Semiconductor device, system and method for calculating distance

By organizing data into clusters and using an approximation of Euclidean distance, the memory bottleneck in high-dimensional vector representation is solved, achieving more efficient computation and resource utilization, and improving the efficiency of large-scale data processing.

CN122019630APending Publication Date: 2026-05-12MACRONIX INTERNATIONAL CO LTD
0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
MACRONIX INTERNATIONAL CO LTD
Filing Date
2025-05-29
Publication Date
2026-05-12

Smart Images

  • Figure CN122019630A_ABST
    Figure CN122019630A_ABST
Patent Text Reader

Abstract

The invention provides a semiconductor device, a system and a method for calculating distance. The semiconductor device includes a memory cell array for storing data in a plurality of memory cells and a circuit coupled to the memory cell array. The circuitry is to perform a plurality of operations in the memory cell array. Operations performed by the circuitry include: receiving a request indicating a query vector; obtaining a plurality of clusters of the plurality of feature vectors, wherein each of the clusters is associated with a corresponding centroid vector; determining a plurality of distances between the query vector and a plurality of centroid vectors of the cluster; selecting one or more clustering clusters from the clustering clusters based on the query vector and the distance between the centroid vectors of the clustering clusters; for each feature vector of the one or more clusters, determining a distance between the query vector and the feature vector; and selecting one or more feature vectors from the one or more clusters based on a plurality of distances between the query vector and the plurality of feature vectors of the one or more clusters.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a technique for calculating distances, and more particularly to a semiconductor device, a system, and a method for calculating distances. Background Technology

[0002] Database search involves retrieving specific information from large collections of structured data through query operations. These queries define criteria for quickly and accurately filtering and extracting relevant records. Depending on the needs, searches can range from simple exact matches to more advanced queries such as range searches, pattern matching, or full-text searches. Effective database search ensures that users can efficiently access the data they need and supports a variety of analytical and operational tasks. Summary of the Invention

[0003] This invention describes methods, apparatus, systems, and techniques for efficiently retrieving and searching information by calculating the Euclidean distance between query vectors and feature vectors in a dataset, thereby promoting accurate similarity-based search and data retrieval.

[0004] One aspect of the present invention includes a semiconductor device. The semiconductor device includes a memory cell array for storing data in a plurality of memory cells and circuitry coupled to the memory cell array. The circuitry is configured to perform a plurality of operations in the memory cell array. These operations performed by the circuitry include: receiving a request indicating a query vector; acquiring a plurality of clusters of a plurality of feature vectors, wherein each cluster is associated with a corresponding centroid vector; determining a plurality of distances between the query vector and the plurality of centroid vectors of the clusters; selecting one or more clusters from the clusters based on the distances between the query vector and the centroid vectors of the clusters; determining a distance between the query vector and the feature vector for each feature vector of the one or more clusters; and selecting one or more feature vectors from the one or more clusters based on the plurality of distances between the query vector and the plurality of feature vectors of the one or more clusters.

[0005] Another aspect of the invention includes a system for calculating distances. The system includes a semiconductor device and a controller coupled to the semiconductor device for controlling the semiconductor device. The semiconductor device includes a memory cell array for storing data in a plurality of memory cells and circuitry coupled to the memory cell array. The circuitry is configured to perform a plurality of operations in the memory cell array. These operations performed by the circuitry include: receiving a request indicating a query vector; obtaining a plurality of clusters of a plurality of feature vectors, wherein each cluster is associated with a corresponding centroid vector; determining a plurality of distances between the query vector and the plurality of centroid vectors of the clusters; selecting one or more clusters from the clusters based on the distances between the query vector and the centroid vectors of the clusters; determining a distance between the query vector and the feature vector for each feature vector of the one or more clusters; and selecting one or more feature vectors from the one or more clusters based on the plurality of distances between the query vector and the plurality of feature vectors of the one or more clusters.

[0006] Another aspect of the invention includes a method for calculating distance, comprising: receiving a request indicating a query vector; obtaining a plurality of clusters of a plurality of feature vectors, wherein each cluster of the clusters is associated with a corresponding centroid vector; determining a plurality of distances between the query vector and the plurality of centroid vectors of the clusters; selecting one or more clusters from the clusters based on the distances between the query vector and the centroid vectors of the clusters; determining a distance between the query vector and the feature vector for each feature vector of the one or more clusters; and selecting one or more feature vectors from the one or more clusters based on the plurality of distances between the query vector and the plurality of feature vectors of the one or more clusters.

[0007] Details of one or more of the disclosed embodiments are set forth in the accompanying drawings and description below. Other features, features, and advantages will become apparent from the description, drawings, and claims. Attached Figure Description

[0008] Figure 1A Illustrations illustrating an example of a system according to one or more embodiments of the present invention.

[0009] Figure 1B This is an illustration of another example of a system including a controller and a memory device, as illustrated in one or more embodiments of the present invention.

[0010] Figure 1C This is an illustration of another example of a system according to one or more embodiments of the present invention.

[0011] Figure 2Illustrations illustrating an example of a memory device according to one or more embodiments of the present invention.

[0012] Figure 3 This is a flowchart illustrating an exemplary method for determining the distance between a query vector and a feature vector, according to one or more embodiments of the present invention.

[0013] Figure 4 A flowchart illustrating an exemplary method for structured data search according to one or more embodiments of the present invention.

[0014] Figure 5 This is an illustration of an exemplary method for aggregating feature vectors according to one or more embodiments of the present invention.

[0015] Figure 6 This is an illustration of an exemplary method for calculating an approximation of the length of the squared vector of an eigenvector, according to one or more embodiments of the present invention.

[0016] Figure 7 An illustration of an exemplary search method according to one or more embodiments of the present invention.

[0017] Figure 8 A flowchart illustrating an exemplary search method according to one or more embodiments of the present invention. Detailed Implementation

[0018] In some applications, such as content search or classification tasks, input data can be represented as numerical vectors carrying various attributes. The host device processes these vectors to identify relevant results or matches. Traditional methods often involve transferring large amounts of data between different processing units and memory levels, leading to bottlenecks that reduce processing efficiency. Even with optimizations to reduce data size, these methods often face limitations such as low data reuse and the limited parallel throughput of traditional processors.

[0019] With the increasing demand for processing large-scale, complex data, the need for efficient computing systems capable of handling high-dimensional vector representations is becoming increasingly prominent. The host device can provide vectorized data to the memory device and instruct the memory device to perform specific operations. By performing these operations internally in memory, the time required to return results to the host device can be reduced, thereby improving overall computational efficiency. However, due to frequent data transfers between the host device and the memory device, memory bottlenecks may occur, limiting the system's ability to fully utilize parallel processing capabilities.

[0020] Embodiments of this invention provide a multi-stage search method that reduces computational load and alleviates memory bottlenecks during the search process. The multi-stage search organizes vectorized data into clusters, each cluster associated with a centroid vector. During processing, a subset of clusters is selected based on their proximity to the query vector, thereby reducing the required computation. Within the selected clusters, the similarity between the query vector and the feature vector can be determined by calculating distances (such as Euclidean distance). However, directly calculating Euclidean distance involves complex operations, such as vector normalization, which can impose a heavy computational burden on memory.

[0021] To mitigate this problem, an approximation of the Euclidean distance can be used, based on a linear function, to simplify the required computation. In some embodiments, certain items of the distance computation can be pre-computed and stored in memory at an offline stage (e.g., by the host processor). At the online stage, only a portion of the computation needs to be performed in memory, thereby reducing the workload of real-time computation. This approach of dividing computation into online and offline stages enables more efficient use of memory resources, further reducing processing latency and energy consumption.

[0022] Figure 1A An example of a rendering system 100. System 100 includes a device 110 and a host device 120. Device 110 includes a device controller 112 and a memory 116. Device controller 112 includes a processor 113 and memory 114. In some embodiments, device 110 includes a plurality of memories 116 coupled to device controller 112. Memory 116 includes a plurality of blocks. Memory 116 may be a 2D memory containing two-dimensional (2D) memory blocks. Memory 116 may also be a 3D memory containing three-dimensional (3D) memory blocks.

[0023] The host device 120 includes a host controller 122. The host controller 122 may include at least one processor and at least one memory connected to the at least one processor. The at least one memory stores programming instructions for execution by the at least one processor to perform one or more corresponding operations.

[0024] Device controller 112 is a general-purpose microprocessor or an application-specific microcontroller. In some embodiments, device controller 112 is the memory controller of device 110.

[0025] Processor 113 is used to execute instructions and process data. Instructions include firmware instructions and / or other programming instructions stored as firmware code and / or other program code. Processor 113 accesses instructions and data from memory 114. In some implementations, memory 114 is static random access memory (SRAM) or dynamic random access memory (DRAM).

[0026] In some embodiments, memory 116 is a non-volatile memory for long-term storage of instructions and / or data, such as a NAND or NOR flash memory device, or other suitable non-volatile memory device. In some cases, device 110 may not include a device controller, and memory 116 may communicate directly with host device 120.

[0027] Figure 1B This illustration depicts another example of a system 150 including a controller 160 and a memory device 170, according to one or more embodiments of the present invention. The controller 160 is electrically connected to the memory device 170, for example via wires, pins, or a bus, or wirelessly, and communicates with the memory device 170, for example, through direct communication. The controller 160 may be… Figure 1A The host controller 122 or device controller 112 in the system.

[0028] Figure 1C This illustration shows another example of a system 180 including addressable memory 190 according to one or more embodiments of the present invention. Addressable memory 190 may be... Figure 1A The memory 116 or Figure 1B The memory device 170 in, or Figure 2 Any memory device described in Figure 10 (e.g., Figure 2 (Memory device 200 in the middle).

[0029] In some embodiments, system 180 includes a network device (e.g., a switch, gateway, etc.). Figure 1C As shown, system 180 includes addressable memory 190, processing circuitry 182, machine-readable medium 184, and communication circuitry 186. Processing circuitry 182 provides control signals or commands to addressable memory 190 via communication circuitry 186. Processing circuitry 182 can be any circuit capable of executing non-transitory machine-readable instructions, such as a central processing unit (CPU), microprocessor, microcontroller, digital signal processor (DSP), etc. Machine-readable medium 184 can be any non-transitory machine-readable medium, including but not limited to volatile storage media (e.g., dynamic RAM (DRAM), SRAM, etc.) and / or non-volatile storage media (e.g., PROM, EPROM, EEPROM, NVRAM, hard disk, etc.). Machine-readable medium 184 can store machine-readable instructions, which, when executed by processing circuitry 182, cause system 180 to perform one or more operations, such as programming, searching, and reading operations.

[0030] The communication circuit 186 may include transceiver circuitry for receiving input data communication and transmitting output data communication. In various embodiments, the communication circuit 186 may include a network interface card (NIC).

[0031] Figure 2 This is an illustration of an example of a memory device 200 according to one or more embodiments of the present invention. The memory device 200 may be... Figure 1A The memory 116 in Figure 1B The memory device 170 in, or Figure 1C The addressable memory 190 in the middle.

[0032] like Figure 2 As shown, the memory device 200 has a memory cell array 210 comprising a plurality of memory cells. The memory cells may be connected in series to a plurality of word lines and a plurality of bit lines. Each memory cell includes at least one memory transistor as a storage element for storing data.

[0033] The memory device 200 may include an X decoder (column decoder) 238 and an optional Y decoder (row decoder) 248. Each memory cell is coupled to the X decoder 238 via a corresponding word line and to the Y decoder 248 via a corresponding bit line.

[0034] The memory device 200 may include a memory interface (input / output (I / O)) 230. The memory interface 230 may be a Serial Peripheral Interface (SPI) or other suitable interface.

[0035] The memory device 200 may include a data buffer 232, an SRAM buffer 234, an address generator 236, a synchronous clock (SCLK) input 240, a clock generator 241, mode logic 242, a state machine 244, and a high-voltage (HV) generator 246. The SCLK input 240 can be used to receive the synchronous clock input, and the clock generator 241 can generate a clock signal for the memory device 200 based on the synchronous clock input. The mode logic 242 can be used to determine whether to perform a read operation or a write operation and provides the determination result to the state machine 244.

[0036] The memory device 200 may also include a sense amplifier 250 and an output buffer 254. The sense amplifier 250 may be selectively connected to the Y decoder 248 via a data line 252. The output buffer 254 is used to buffer the output signal from the sense amplifier 250 to the memory interface 230. The sense amplifier 250 may be part of the read circuitry.

[0037] Controller, for example Figure 1A The host controller 122 or device controller 112, or Figure 1BThe controller 160 in the memory device 200 can generate instructions, such as read instructions and / or write instructions, to be executed accordingly to read data from or write data to the memory device 200.

[0038] like Figure 2 As shown, the memory device 200 may include one or more configuration buffers 220. The configuration buffer 220 may be connected to one or more components within the memory device 200, such as a data buffer 232, a state machine 244, a sense amplifier 250, and / or an output buffer 254. In some embodiments, the configuration buffer 220 may be configured via instruction input from a controller, for example, via the memory interface 230 and the data buffer 232. In some embodiments, the configuration buffer 220 may be predefined in the memory cell array 210 or in the internal circuitry of the memory device 200, for example, via the sense amplifier 250. The configuration buffer 220 may store and provide information such as search length, search depth, and / or search data string to the state machine 244 to generate corresponding control signals.

[0039] A search operation may contain one or more search sessions. Each search session may contain one or more search runs. Different search sessions may use different search data or the same search data. A configuration cache may contain a search length cache, a search depth cache, or a search data cache. The search length cache sets the search length for a search run, such as 34 bits, 68 bits, or 136 bits. The search depth cache sets the search depth or search range for a search session or operation, such as 1 kilobits, 2 kilobits, or 4 kilobits. The search data cache stores the search data used for comparison during the search (e.g., data strings used for the search). The memory device 200 may contain multiple search data caches to store multiple sets of search data that can be used in multiple search sessions. The configuration cache can be configured using option codes (OPs).

[0040] In some cases, the search length and search depth used for the search operation can be specified using the controller's option codes. In other cases, the search length and search depth can also be predefined within the memory device 200. For example, for each search stage, the search length can be preset to 34 bits, and the search depth can be preset to 1KB. The search operation can contain multiple search stages.

[0041] In some cases, the search data and the search start address are transmitted together with the instructions for the search operation to the memory device 200, and option codes can be used to specify the search data cache for storing the search data.

[0042] Figure 3This is a flowchart illustrating an exemplary method 300 for determining the distance between a query vector and a feature vector, according to one or more embodiments of the present invention. Method 300 can be performed by the following means: Figure 1A The memory 116 in Figure 1B Memory device 170 in Figure 1C The addressable memory 190 in Figure 2 The memory device 200 or memory device and controller, for example Figure 1A The host controller 122 in Figure 1B Controller 160 or Figure 1C The processing circuit 182 and / or the communication circuit 186.

[0043] Method 300 illustrates the computational task of determining the Euclidean distance between an input query vector and each of a plurality of feature vectors, in order to find one or more feature vectors that have the minimum Euclidean distance to the input query vector. For illustrative purposes only, Method 300 includes the computation of Euclidean distances. Method 300 can also be applied to other computations, such as determining the similarity between two vectors, such as cosine similarity or inner product distance. By finding the feature vectors that have the minimum Euclidean distance to the input query vector, Method 300 is substantially applicable to query-based search (e.g., searching for content with features closest to the query vector), exhaustive search (e.g., searching for a specified target by exhaustively exploring all possibilities), and behavior-oriented content recommendation (e.g., recommending content that matches a user's interests based on the user's or other users' past behavior).

[0044] In operation 302, a query vector is received. In some embodiments, the query vector is a vector representing the attributes of a user's query. The query vector can encode relevant features of the query into a numerical format. For example, when a user queries for movie applications, the query vector can encode features such as desired movie length, preferred language, and genre. These encoded attributes are presented as numerical values ​​in the query vector to facilitate computational tasks such as similarity search or matching operations.

[0045] In some embodiments, a query vector is compared with a feature vector stored in a database or other repository. In some embodiments, the feature vector represents an attribute or feature of an object, entity, or input in a numerical format. In some examples, a feature vector may contain a set of numerical values, each corresponding to a specific feature or characteristic of an object. For example, in a query search for movies, the feature vector can encode attributes such as length, language, and genre into unique numerical values ​​to form a structured, multidimensional representation that allows the computing system to process efficiently.

[0046] In a database, each feature vector can serve as a compact and standardized representation of an independent data object. This structure enables efficient computational operations, including searching, classification, and matching. In query-based search systems, the database can store multiple feature vectors, each uniquely representing a data object. The use of feature vectors transforms complex datasets into a structural format suitable for computational algorithms. By encoding each data input as a feature vector and by comparing query vectors and storing feature vectors to identify the most relevant matches, the system facilitates efficient similarity search.

[0047] In some embodiments, feature vectors in the database can be grouped into clusters. Each cluster contains a subset of the feature vectors in the database, and each cluster can be associated with a centroid, such as a centroid vector or centroid point. Examples of clustering methods are provided in the following references. Figures 4 to 5 Further details will be provided.

[0048] In operation 304, when a query vector is received, one or more clusters closest to the query vector are determined. In some embodiments, the proximity of clusters is determined by calculating the distance between the query vector and the centroid vector representing each cluster. In some examples, the closest clusters can be selected by identifying the top-n (e.g., top-256) clusters with the smallest distances.

[0049] In some embodiments, after selecting the closest clusters, the similarity between the query vector and each feature vector within those clusters is determined. In some embodiments, similarity is determined by calculating Euclidean distance. In some contexts, squared Euclidean distance is used instead of Euclidean distance to enhance computational efficiency and numerical stability. Calculating Euclidean distance involves calculating the square root of the sum of the squared differences between two vectors. Since calculating the square root is computationally expensive, especially when dealing with large datasets or high-dimensional vectors, using squared Euclidean distance avoids this costly computation, thus enhancing overall performance. Furthermore, squared Euclidean distance is sufficient when the goal is to compare relative distances or rankings between data points. The square root function is monotonic, meaning it preserves the order of values. Thus, comparing squared Euclidean distances can produce the same ranking as comparing actual Euclidean distances, yielding equivalent results with reduced computational cost.

[0050] In some applications, using squared values ​​can also improve numerical stability by avoiding potential accuracy problems. Potential accuracy problems relate to the calculation of the square root of very small or very large values. Therefore, by replacing Euclidean distance with squared Euclidean distance, the system implemented in this invention can achieve higher computational efficiency without sacrificing the accuracy of relative distance comparisons.

[0051] In operation 306, the vector lengths of the feature vectors of one or more of the closest clusters are obtained. In some embodiments, the squared Euclidean distance can be calculated using the following programming method: d 2 =||xw i || 2 =||x|| 2 +||w i || 2 -2x·w i , where d 2 Represents the squared Euclidean distance, x represents the input query vector, and w i This represents the feature vector. Therefore, ||x|| can be calculated as the length of the query vector x, and ||w i || 2 It can be calculated as an eigenvector w i The length of x·w i It can be calculated as query vector x and feature vector w i The dot product. Therefore, calculating the squared Euclidean distance involves calculating the first term ||x||. 2 The second item ||w i || 2 and the third item 2x·w i .

[0052] The first term ||x|| 2 and the second item ||w i || 2 The computation of ||x|| is computationally expensive for memory, thus increasing the computational load on memory. To alleviate the computational burden on memory, the first term ||x|| 2 It can be computed during the online computation phase via the host processor, and the second term ||w i || 2 This can be computed during the offline computation phase, before receiving the query vector. The third term is 2x·w. i The computation can be performed directly in memory after receiving the query vector. This approach reduces the overall computational burden on memory, thereby increasing processing efficiency.

[0053] In some embodiments, the second item ||w i || 2 It can be roughly determined based on a linear function. In some examples, the second term ||w i || 2 The level can be determined based on the following linear function: n ·Δd+β cj Among them, level n Representative eigenvector w iIn the hierarchy of a cluster, Δd represents the distance between adjacent levels in the cluster, and β cj This represents the magnitude of the smallest level in the cluster. The second term ||w i || 2 The approximate calculation will be in the following reference Figure 6 Further details will be provided.

[0054] In some examples, the second term ||w i || 2 The value representing the squared norm of the eigenvector can be pre-computed and stored in local memory, such as RAM or external storage. Pre-compiling these values ​​helps reduce computational costs during real-time (online) searches, as the norm values ​​do not need to be repeatedly calculated. In online search operations, when processing query vectors, ||w i || 2 Pre-calculated values ​​can be retrieved from memory and transferred to storage. This method enhances efficiency by minimizing on-the-fly computations, ensuring faster data retrieval and improved system performance during search operations.

[0055] In operation 308, in obtaining ||x|| 2 The value of ||w i || 2 Approximate values ​​and dot product x·w i Then, an approximation of the squared Euclidean distance can be derived using ||x|| 2 The value of ||w i || 2 Approximate values ​​and dot product x·w i In some examples, the squared Euclidean distance between the query vector x and the eigenvectors can be expressed as ||x||. 2 The value of ||w i || 2 Approximate values ​​and dot product x·w i The following relationship between them is derived: ||xw i || 2 ≈ ||x|| 2 +||w i || 2 -2x·w i This approximation allows for efficient similarity-based searches, reducing the computational complexity that typically involves precise distance calculations. The resulting squared Euclidean distance provides a measure of difference, which can be used to determine how well a given feature vector matches a query vector.

[0056] In some embodiments, the dot product distance can be used to determine the similarity between feature vectors and query vectors. The calculation of the dot product distance may involve normalizing the query vector, feature vector, and centroid vector to a consistent scale, such as unit length. For example, in applications like nearest neighbor search or clustering, normalizing these vectors ensures that the similarity measurement is based on the direction of the vectors rather than their absolute values. This can enhance the accuracy of similarity comparisons, especially when dealing with high-dimensional data. In some embodiments, normalization can be applied as a preprocessing step before calculating the dot product, so that variations in vector magnitude do not interfere with the similarity assessment.

[0057] Figure 4 This is a flowchart illustrating an exemplary method 400 for structured data search according to one or more embodiments of the present invention.

[0058] In operation 402, obtain the feature vector. In some embodiments, the feature vector represents an attribute or characteristic of an object, entity, or input in a numerical format. In some examples, the feature vector may contain a set of numerical values, each corresponding to a specific feature or property of the object. For example, in a query-based search for a movie, the feature vector may encode attributes such as the movie's length, language, and genre as unique numerical values, forming a structured and multi-dimensional representation for efficient processing by the computational system.

[0059] In a database, each feature vector can be a compact and standardized representation of an independent data input. This structure enables efficient computational operations, including searching, classification, and matching. In query-based search systems, the database can store multiple feature vectors, each uniquely representing a data object. The use of feature vectors transforms complex datasets into a structural format suitable for computational algorithms. By encoding each data input as a feature vector and then comparing the query vector with the stored feature vectors to identify the most relevant matches, the system facilitates efficient similarity search.

[0060] In operation 404, the feature vectors are grouped into clusters. In some embodiments, each cluster contains a subset of feature vectors from a database. In some embodiments, clustering feature vectors in the feature vector space involves various methods, with each cluster associated with a centroid that represents and characterizes the cluster.

[0061] In some embodiments, the clustering method includes iterative partitioning, wherein a predefined number of clusters is initialized and feature vectors are assigned to the nearest clusters based on a selected distance metric, such as Euclidean distance. Centroids are updated by calculating the average of the feature vectors in each cluster, and this procedure is repeated until the centroids stabilize or meet a specific stopping criterion.

[0062] In some embodiments, the clustering method includes hierarchical clustering, wherein clusters are formed by either agglomeration or splitting methods. Agglomeration methods begin with individual eigenvectors and merge them into larger clusters. Splitting methods begin with a single large cluster and recursively split it into smaller clusters. The centroids of the resulting clusters are determined by the mean or median of the eigenvectors in each cluster.

[0063] In some embodiments, the clustering method includes density-based clustering, where clusters are defined as high eigenvector density regions separated by low-density regions. This method allows clusters to form in irregular shapes and of various sizes. The centroids of these clusters can be calculated by averaging the eigenvectors in the high-density regions.

[0064] In some embodiments, the clustering method includes probabilistic modeling, where the clusters are represented by a Gaussian distribution. Parameters of the distribution, such as the mean and variance, are estimated, and eigenvectors are assigned to clusters based on the probability of belonging to each distribution. The centroid of each cluster corresponds to the mean vector of the individual Gaussian distribution.

[0065] In some embodiments, the clustering method includes constructing a nearest neighbor graph, wherein feature vectors are connected to their nearest neighbors, and clusters are formed by identifying densely connected subgraphs. The centroid of a cluster is determined by averaging the feature vectors in each identified subgraph.

[0066] Clustering methods provide an efficient organization of feature vectors by associating each cluster with its centroid. In query processing, the closest centroids are first identified, and further computation is restricted to feature vectors within the selected clusters. This approach reduces computational complexity and improves performance for search and retrieval tasks in large-scale feature vector spaces.

[0067] In operation 406, within each cluster, multiple radii levels are trained for each cluster. In some embodiments, these radii levels represent different approximate thresholds used to partition clusters into different levels based on the distance from the cluster to the centroid. By organizing feature vectors into different levels according to their distance to the centroid, a more efficient search can be facilitated by progressively reducing the search space. This approach improves overall search performance and computational efficiency by focusing computation on feature vectors at relevant distance levels, thereby reducing unnecessary computation.

[0068] Clustering and training of feature vectors across multiple clusters can be performed using the exemplary methods described below, referencing... Figure 5 . Figure 5This is an exemplary method for clustering feature vectors according to one or more embodiments of the present invention. In some embodiments, the MAC operation can be performed by a device, such as... Figure 1A Memory 116, Figure 1B Memory device 170, Figure 1C Addressable memory 190, Figure 2 Memory device 200. In some embodiments, addition / subtraction / linear multiplication operations such as L2 distance (Euclidean distance) (e.g., |ab|) 2 =|a| 2 +|b| 2 -2×<a,b> Comparisons and / or sorting can be performed by devices, such as Figure 1A The host controller 122, or Figure 1B Controller 160, or Figure 1C The processing circuit 182 and / or the communication circuit 186.

[0069] Please refer to Figure 5 Multiple feature vectors, labeled as feature vectors w1, w2, ..., w i The features are distributed in the feature vector space 500, so that the feature vector space 500 can be constructed as a space containing multiple levels, labeled L0, L1, L2, ..., L... n Each level corresponds to a sphere centered at the origin, labeled C0, where the sphere is characterized by a specific radius. The radius of each sphere defines the boundary of a level, thus dividing the feature vector space 500 into different regions. In this way, the feature vector space 500 contains multiple concentric spherical regions, each representing a different level. Each level represents a set of feature vectors whose amplitude falls within a specific range, where the amplitude can be defined by the distance of the feature vector from the origin C0.

[0070] The procedure for determining the radius of the sphere and thus defining the hierarchy can be accomplished through a training method that analyzes the distribution of eigenvectors and identifies meaningful partitions. In some paradigms, the training method may begin by calculating the magnitude of the eigenvectors and, based on their distances to the origin, arranging the eigenvectors in ascending order. This ordered set of magnitudes provides the basis for constructing the sphere that defines the hierarchy.

[0071] Once an initial set of amplitudes is obtained, the training method employs clustering techniques or tiering strategies to group feature vectors based on their amplitude. Each group corresponds to a different tier, and the radius of the sphere for that tier is determined by analyzing the amplitude of the feature vectors within the group. The radius can be chosen based on various criteria, such as the maximum or average amplitude within the group, depending on specific requirements.

[0072] In some paradigms, the radius of the sphere can be iteratively adjusted to reduce the variability of eigenvectors within each level and maintain separation between adjacent levels. This adjustment keeps eigenvectors compactly clustered within levels and ensures that the boundaries between levels are well-defined. This iterative adjustment can continue until convergence is achieved, for example, when subsequent iterations produce the minimum change in the sphere's radius.

[0073] After the training process is complete, the radius of the sphere is finally determined, and each feature vector can be assigned to a specific level based on its magnitude. In some paradigms, a feature vector is considered to belong to a specific level if its magnitude falls within the range defined by the corresponding sphere. Partitioning the feature vector space into multiple levels allows for the efficient organization and retrieval of feature vectors based on their relative magnitudes.

[0074] This approach can be leveraged in systems requiring efficient similarity searches, where hierarchical levels correspond to approximate thresholds used to identify neighbors closest to the query feature vector. By structuring the feature vector space in this way, the system can manage large sets of feature vectors and ensure high accuracy for retrieval or classification tasks.

[0075] In some embodiments, feature vectors are remapped and reorganized into multiple clusters (e.g., Figure 5 Clusters 1, 2, and 3 are defined in the model, each representing a distinct subset of the feature vector space, just as each cluster occupies a specific subspace of the overall vector space. Once the clusters are determined, each cluster can independently define its own hierarchy, corresponding sphere, and origin (e.g., origins C1, C2, and C3). In some paradigms, the clustering process can involve multiple stages, including initial clustering of feature vectors, identification of the sphere for each cluster, and allocation of hierarchy within each cluster.

[0076] In one example, a clustering procedure may begin with an analysis of the distribution of feature vectors in the feature vector space to identify clusters of feature vectors based on similarity criteria, such as spatial approximation or shared features. Clustering algorithms, such as K-means, hierarchical clustering, or density-based methods, can be used to partition the feature vectors into multiple clusters. Each resulting cluster represents a group of feature vectors, where the relationships between feature vectors are more compact than the relationships between feature vectors in other clusters.

[0077] Once clusters are formed, the next step is to define the hierarchy within each cluster. In some paradigms, this can be achieved by examining the magnitudes of the eigenvectors belonging to a particular cluster and constructing a series of concentric spheres centered around a specified point (e.g., the centroid of the cluster). The radius of each sphere is determined by analyzing the distances of the eigenvectors in the cluster to the centroid. Similar to the treatment of a single global eigenvector space, clustering can involve determining the radius based on criteria, such as the maximum or average distance between eigenvectors in a given group.

[0078] To ensure that the hierarchies within clusters are well-defined and meaningful, adjustment procedures can be applied. Adjustments may involve reducing intra-hierarchical variability and maintaining inter-hierarchical separation within clusters. Additionally, adjustments may include adjusting the separation between spheres in adjacent clusters to reduce overlap or interference between clusters. This ensures that feature vectors are clearly assigned to specific clusters and hierarchies, enhancing the accuracy and efficiency of subsequent retrieval or classification tasks. Within a cluster, the inter-hierarchical distances (or intervals) between spheres can be the same or different. For different clusters, the inter-hierarchical distances (or intervals) between adjacent spheres within these clusters can be the same or different.

[0079] After determining the radius of the sphere in each cluster, the hierarchy within the cluster is finally determined, and eigenvectors are assigned accordingly. Each eigenvector is associated with its hierarchy within the cluster based on the distance from the centroid of the cluster to the eigenvector. The resulting structure can contain multiple clusters, each with its own hierarchy and spherical layering.

[0080] This clustering-based approach offers several technical advantages. It allows for precise, fine-grained organization of the feature vector space by enabling different regions to have their own independent hierarchies. This is useful in applications where feature vectors represent heterogeneous data with diverse features, such as embeddings from different categories or classifications. By partitioning feature vectors into clusters and defining the hierarchy within each cluster, the system can achieve more accurate feature vector classification and retrieval.

[0081] In some paradigms, the clustering process can be dynamic, allowing the system to adapt to changes in the feature vector space over time. New feature vectors can be merged, either by assigning them to existing clusters or by forming new clusters, if necessary. The system can periodically update cluster-specific hierarchies and spheres to maintain optimal organization and retrieval performance.

[0082] This approach is useful for applications involving large-scale feature vector datasets, such as image recognition, natural language processing, and recommendation systems, where efficient similarity search and classification are required. By leveraging clustering at specific levels and on spheres, the system can enhance operational accuracy and computational efficiency.

[0083] Please refer to the reply. Figure 4 In operation 408, an approximate value for the length of the squared vector of the feature vector is determined relative to multiple levels within each cluster. This approximation reduces the complexity and computational load of directly calculating the exact squared vector length during the query process. By pre-compiling and approximating these values ​​relative to the levels within each cluster, the system can efficiently retrieve relevant feature data without performing expensive real-time computations. This approach improves the speed and scalability of search operations, for example, when handling large datasets and high-dimensional feature vectors. The approximate value for the length of the squared vector of the feature vector is referenced below. Figure 6 illustrate.

[0084] Figure 6 This is an exemplary method for calculating an approximation of the length of the squared vector of an eigenvector, as illustrated in one or more embodiments of the present invention.

[0085] exist Figure 6 The text shows two vector spaces, 602 and 604, to illustrate the calculation of an approximation of the length of a squared vector. Vector spaces 602 and 604 can be used as a subset of... Figure 5 An example of the vector spaces of cluster 1 and cluster 2 in [the dataset]. For example... Figure 6 As shown, vector space 602 contains the first cluster of feature vectors, including feature vectors w1, W2, and w3, distributed in concentric spherical regions centered at the origin C1. Each spherical region corresponds to a relative hierarchy, forming hierarchies L0, L1, L2, ..., L... n Similarly, vector space 604 contains a second cluster of feature vectors, containing feature vectors w4, w5, w6, ..., w n They are distributed in a concentric spherical region centered at the origin C2, and have relative hierarchical levels L0, L1, L2, ..., L n .

[0086] In some embodiments, the sphere, its radius, and the hierarchy for each vector space are determined independently. For example, the radius of the sphere defining the hierarchy of one vector space can be different from the radius of the sphere defining the hierarchy of other vector spaces. This allows each vector space to have its own unique structure based on the distribution of eigenvectors in the vector space.

[0087] In some embodiments, the length of an eigenvector depends on the origin of the vector space in which the eigenvector resides. For example, in vector space 602, the lengths of eigenvectors w1, w2, and w3 depend on the origin C1, while in vector space 604, the lengths of eigenvectors w4, w5, w6, ..., w nThe length of the eigenvector depends on the origin C2. In some embodiments, the length of the eigenvector depends on the distance between the eigenvector and the centroid vector of the vector space or the centroid vector of the cluster in which the eigenvector belongs.

[0088] In some operations, calculating distance requires the length of the squared vector of the feature vectors, such as Euclidean distance calculation during query processing. However, directly calculating the length of the squared vector in real time places a significant computational burden on memory, especially when dealing with large datasets. To reduce this burden and improve computational efficiency, approximations of the length of the squared vector can be used.

[0089] In some embodiments, for feature vector w i The length of the squared vector is denoted as ||w i || 2 Furthermore, it can be approximated by a linear function. In some examples, the length of the squared vector ||w i || 2 The following linear function can be used to approximate it: level n ·Δd+β cj Among them, level n w represents the eigenvector in the vector space i In the hierarchy of a cluster, Δd represents the distance between adjacent levels in the cluster, and β cj This represents the magnitude of the smallest level in the vector space. This linear approximation can reduce computational complexity by pre-compiling specific terms offline, leaving lightweight operations to online query processing.

[0090] In some examples, the hierarchy of an eigenvector can be determined based on its proximity to adjacent spheres. If an eigenvector lies between two spheres, it can be assigned to the hierarchy of the closer sphere. For example, in vector space 602, eigenvector w1 is closer to the sphere corresponding to hierarchy L0, and eigenvectors w2 and w3 are closer to the sphere corresponding to hierarchy L1. Similarly, in vector space 604, eigenvector w4 is assigned to L0, eigenvectors w5 and w6 are assigned to L1, ..., and eigenvector w... n Specify to L n-1 .

[0091] In some examples, the Δd spacing represents the distance between two adjacent spheres, corresponding to adjacent levels in vector space. Term β cj It represents the magnitude of the smallest level in the vector space, corresponding to the radius of the sphere at that level.

[0092] In some embodiments, for each vector space, Δd and β cj The values ​​of these variables are determined independently, allowing them to vary in various vector spaces. For example, in... Figure 6In the vector spaces 602 and 604, β has different values. c1 and β c2 , representing the smallest levels of vector spaces 602 and 604, respectively. Although the spacing Δd of vector spaces 602 and 604 is shown as the same, in some cases, different vector spaces can have different spacings, depending on their specific configuration.

[0093] By employing this approach, the computational burden on memory can be reduced, and query processing performance can be enhanced. The approximation method allows the system to efficiently approximate the length of a squared vector without requiring expensive real-time computation, making it well-suited for large-scale applications involving high-dimensional feature vectors.

[0094] In some embodiments, the length of the squared vector of the eigenvector is ||w i || 2 The values ​​can be pre-computed and stored in a mapping table. Each vector space or cluster is associated with a corresponding mapping table. This pre-computation allows the system to quickly retrieve the length of the squared vector in the query procedure, thereby reducing computational costs and improving real-time performance.

[0095] For example, mapping table 606 corresponds to vector space 602, and mapping table 608 corresponds to vector space 604. In the online phase, when processing a query vector, the system retrieves the squared vector length from the appropriate mapping table based on the cluster or vector space to which the feature vector belongs. Storing the squared vector length in this way eliminates the need to recalculate these values ​​in each search operation, making distance calculation faster and more efficient.

[0096] In some contexts, each item in the mapping table may correspond to one or more specific feature vectors and contain a pre-computed squared vector length associated with a specific level. For example, in mapping table 606, feature vector w1 corresponds to the vector length associated with level L0, and feature vectors w2 and w3 correspond to the vector length associated with level L1.

[0097] The mapping table architecture allows for fast indexing and retrieval, reducing latency in large-scale search operations. This approach is useful when dealing with high-dimensional data, as it reduces computation time and memory bandwidth requirements during search operations.

[0098] Figure 7 This illustration depicts an exemplary search method 700 according to one or more embodiments of the present invention. Method 700 involves identifying feature vectors in a database that are most similar to a query vector based on a request. The request specifies a query vector and initiates a search to find the closest match among the feature vectors in the database. In some examples, method 700 can use one or more... Figures 1A to 3 The device shown is used for execution. Figure 7The description can be understood in conjunction with the previous illustrations, including Figures 1A to 6 To provide a clear description of the components and processes.

[0099] In receiving Figure 7 When a query vector is denoted as x, method 700 begins with a coarse search. In some embodiments, feature vectors in the database are clustered into multiple clusters, each cluster being associated with a representative centroid, such as a centroid vector or centroid point. Clustering is performed to reduce the search space, allowing the system to focus only on a subset of the most relevant feature vectors. Figure 7 The example shown presents six clusters, each containing multiple feature vectors. The centroids of these clusters are labeled w. c0 w c1 w c2 w c3 w c4 w c5 .

[0100] In the coarse search phase, the distance between the query vector and the centroid vectors of the clusters is calculated. Based on these distances, a subset of clusters with shorter distances to the query vector is selected for further processing, e.g., distances less than a threshold. In some embodiments, the top-n clusters with the shortest distances are selected (e.g., the 256 clusters with the shortest distances). Figure 7 As shown, in stage 1, a vector with a centroid w is selected. c1 w c2 w c3 w c4 Clusters are formed because their distance to the query vector is less than a threshold. These clusters have centroid vectors w. c0 w c5 Clusters with a distance greater than a threshold are excluded from subsequent operations to reduce computational complexity.

[0101] After selecting relevant clusters, the similarity between each feature vector of the selected cluster and the query vector is determined. In some embodiments, this similarity is calculated using an approximate Euclidean distance. Figures 3 to 6 The described approximation method involves determining the squared Euclidean distance by pre-compiling and storing specific terms in the offline stage, and performing lightweight computation in the online stage. This approach reduces computational burden while maintaining high accuracy. Feature vectors with values ​​greater than a preset threshold are excluded in further processing. Figure 7 In stage 2, with the center of mass w c1 w c2 w c3 w c4 In the selected clusters, feature vectors that exceed the distance threshold are removed and excluded in subsequent operations.

[0102] The remaining feature vectors, having distances within a preset threshold, are further filtered. In some embodiments, an intro-selection procedure is used to select the top-k feature vectors that best match the query vector. In some examples, intro-selection is used to find the top-k (e.g., top-5) smallest elements in an unsorted table, combining the characteristics of quicksort and heaping sort to ensure optimal performance. In one example of intro-selection, a table of distances between the query vector and feature vectors can be obtained to select the five smallest distances. The intro-selection procedure uses quicksort to logically partition the table to select a subset containing the smallest distances. Once partitioning is complete, the top-5 smallest distances can be retrieved without fully sorting the entire table. In another example, a table of similarity scores between the query vector and feature vectors can be obtained to select the ten highest scores. The subset of feature vectors with the highest similarity can be determined by partitioning the table and selecting the top-10 elements. This procedure is more efficient than sorting the entire table. Figure 7 As shown in stage 3, feature vectors that are removed and excluded from the top-5 are removed from further operations.

[0103] In the final stage, a fine-grained search is performed on the top-k feature vectors to identify the best match for the query vector. This fine-grained search may involve a more precise calculation of the similarity between the query vector and the remaining feature vectors. In some embodiments, the fine-grained search may involve calculating precise Euclidean distance or other high-precision similarity metrics to determine the closest match. Figure 7 As shown in stage 4, a fine-grained search process is performed on the top-5 feature vectors selected in stage 3 to identify the feature vector that best matches the query vector. The final result is then returned as the best candidate.

[0104] By combining coarse and fine search stages and employing clustering, distance approximation, and preliminary selection, Method 700 ensures efficient and accurate retrieval of the most relevant feature vectors for a given query. This multi-stage approach reduces computational complexity, minimizes memory usage, and enhances performance, making it suitable for large-scale datasets and real-time applications.

[0105] Figure 8 This is a flowchart illustrating an exemplary search method 800 according to one or more embodiments of the present invention. In some examples, method 800 can use one or more... Figures 1A to 3 The device shown is used for execution. Figure 8 The description can be understood in conjunction with the previous illustrations, including Figures 1A to 7 To provide a clear description of the components and processes.

[0106] In operation 802, a request indicating a query vector is received. In some embodiments, the request specifies a query vector (e.g., Figure 7 The query vector x) is used to start the search in the database for feature vectors (e.g., ...). Figure 5 The eigenvectors w1, w2, ..., w in the data are... i The query vector is used to find the closest match within the given set. In some embodiments, the query vector is a vector representing the characteristics of the query provided by the user.

[0107] In operation 804, multiple clusters of feature vectors are obtained. In some embodiments, feature vectors in the database can be grouped into clusters (e.g., ...). Figure 5 Clusters 1, 2, and 3 in the database. Each cluster contains a subset of feature vectors from the database, and each cluster can be associated with a centroid, such as a centroid vector or centroid point (e.g., ...). Figure 5 (The centroids C1, C2, and C3 in the middle).

[0108] In operation 806, multiple distances are obtained between the query vector and the centroid vectors of multiple clusters. In some embodiments, the distances between the query vector and the centroid vectors are determined using a distance metric, such as Euclidean distance or an approximation thereof.

[0109] In some examples, Euclidean distance is calculated as the square root of the sum of squared differences between the corresponding components of the query vector and the centroid vector. To reduce computational complexity, in some cases, an approximate squared Euclidean distance can be used, eliminating the need to calculate the square root. By applying this distance metric to each centroid vector, the system can identify the relative approximation of the query vector to each cluster, facilitating the efficient selection of relevant clusters for further processing.

[0110] In operation 808, one or more clusters are selected from multiple clusters based on multiple distances.

[0111] In some embodiments, selecting one or more clusters from a plurality of clusters based on multiple distances between the query vector and the centroid vectors of the plurality of clusters includes: selecting one or more clusters associated with one or more centroid vectors, wherein the one or more centroid vectors have one or more shortest distances to the query vector. For example, the system may apply top-n selection, where n represents a predefined number of clusters to be selected. Clusters with the top-n shortest distances to the query vector are selected for further processing. This selection approach allows the system to focus on a limited number of relevant clusters, thereby improving search efficiency and reducing computational complexity.

[0112] In operation 810, for each feature vector of one or more selected clusters, the distance between the query vector and the feature vector is determined. In some embodiments, the distance between the query vector and the feature vector includes Euclidean distance. In some embodiments, to enhance computational efficiency, squared Euclidean distance is used to avoid the need for expensive square root operations while still providing an accurate similarity measurement. In some embodiments, approximate squared Euclidean distance can be used, where specific items are pre-computed and stored in an offline stage. This approach allows the system to efficiently compute distances during query processing by reducing the real-time computational burden. By using squared or approximate squared Euclidean distance, the system can handle large datasets and high-dimensional feature vectors more efficiently, ensuring faster and more efficient search operations.

[0113] In some embodiments, determining the distance between the query vector and the eigenvector involves performing distance calculations directly within the memory cell array, thereby reducing data movement and improving computational efficiency. In some examples, the dot product of the query vector and the eigenvector can be calculated directly within the memory cell array. The distance between the eigenvector and the centroid vector, and the distance between the query vector and the centroid vector, can be obtained from the memory controller or other circuitry. This approach leverages in-memory computing techniques, where the memory cell array itself can be used to perform operations such as vector multiplication and accumulation, reducing the need to transfer data to an external processor.

[0114] For example, after loading the query vector and relevant feature vectors from the selected clusters into the memory cell array, the squared Euclidean distance between the query vector and each feature vector can be calculated by performing element operations in the memory cells and summing the squared differences. In some scenarios, some calculations, such as pre-calculated terms for approximate squared Euclidean distances, can be placed in memory beforehand to further reduce workload.

[0115] In some embodiments, determining the distance between the query vector and the feature vector includes: determining the distance between the feature vector and the centroid vector of the cluster to which the feature vector belongs (e.g., ||x||); determining the distance between the query vector and the centroid vector of the cluster to which the feature vector belongs (e.g., ||w||). i ||); Determine the dot product of the query vector and the feature vector (e.g., x·w). i ); and determine the distance between the query vector and the feature vector (e.g., ||xw) i The distance between the feature vector and the centroid vector, the distance between the query vector and the centroid vector, and the dot product are used. For example, the distance between the query vector and the feature vector can be determined programmatically as follows: d 2 =||xw i || 2=||x|| 2 +||w i || 2 -2x·w i , where d 2 Represents the squared Euclidean distance, x represents the query vector, and w i This represents the eigenvector.

[0116] In some embodiments, determining the distance between a feature vector and the centroid vector of the cluster to which the feature vector belongs includes: using a mapping table associated with the clusters to determine the distance between the feature vector and the centroid vector. In this embodiment, the mapping table (e.g., Figure 6 The mapping tables 606 and 608 in the table indicate the mapping relationship between the feature vectors of clusters and the centroid vectors of clusters.

[0117] In some embodiments, determining the distance between a feature vector and the centroid vector of the cluster to which the feature vector belongs includes: determining the scale level of the feature vectors in the centroid vector of the cluster to which the feature vector belongs (e.g., Figure 5 The hierarchy L0, L1, ..., or L n ); Determine a first value indicating the spacing between adjacent scale levels of clusters (e.g. Figure 6 Δd in the equation; and a second value (e.g., to determine the magnitude of the smallest scale level indicating the cluster) to determine the magnitude of the cluster. Figure 6 β in c1 or β c2 ); and determining the distance between the eigenvectors and the centroid vectors of the clusters, based on the scale level, first value, and second value of the eigenvectors. In some examples, the squared vector length ||w is used. i || 2 This indicates the distance between the eigenvector and the centroid vector of the cluster to which the eigenvector belongs. The length of the squared vector ||w i || 2 The level can be determined based on the following linear function: n ·Δd+β cj Among them, level n w represents the eigenvector in the vector space i In the hierarchy of a cluster, Δd represents the distance between adjacent levels in the cluster, and β cj This represents the magnitude of the smallest level in the cluster.

[0118] In some embodiments, determining the scale level of a feature vector within a cluster to which it belongs includes: determining the scale level of the feature vector within the cluster based on the proximity of the feature vector to adjacent scale levels within the cluster. Each scale level corresponds to a sphere centered at the centroid of the cluster, the sphere having a specific radius defining the boundary of the scale level. The proximity of the feature vector to adjacent scale levels can be estimated by measuring the distance of the feature vector to the corresponding sphere.

[0119] For example, if a feature vector lies between two adjacent spheres, the system can compare the distances of the feature vector to the two spheres and assign it to the scale level of the closer surface. In some scenarios, if the feature vector is equidistant from two adjacent scale levels, a predefined rule can be applied to solve a specific problem, such as selecting the inner or outer scale level based on system parameters.

[0120] In operation 812, one or more feature vectors are selected from one or more clusters based on the distance between the query vector and the feature vectors in one or more clusters.

[0121] In some embodiments, selecting one or more feature vectors from one or more clusters based on the distance between the query vector and feature vectors in one or more clusters includes: selecting a set of feature vectors from one or more clusters based on a distance threshold, wherein the distance between each feature vector in the set of feature vectors and the query vector is less than the distance threshold; and selecting one or more feature vectors from the set of feature vectors that have the shortest distance to the query vector.

[0122] For example, in a scenario where the system begins by selecting a set of feature vectors from multiple clusters, each feature vector's distance to the query vector is below a predefined threshold. By focusing only on the most relevant candidates, this filtering step reduces the number of feature vectors to process, improving computational efficiency. After filtering, the system can apply an initial selection procedure to identify the top-k feature vectors with the shortest distance to the query vector. By combining distance threshold filtering with top-k selection, the system can reduce unnecessary computation and improve the accuracy of search results.

[0123] This invention discloses only some examples and embodiments. Based on the disclosure, changes, modifications, and enhancements can be made to implement other possible embodiments.

Claims

1. A semiconductor device comprising: An array of memory cells for storing data in multiple memory cells; and A circuit, coupled to the memory cell array and used to perform multiple operations within the memory cell array, including: Receive a request indicating a query vector; Obtain multiple clusters of multiple feature vectors, where each cluster is associated with a corresponding centroid vector; Determine multiple distances between the query vector and multiple centroid vectors of these clusters; Based on the query vector and the distances between the centroid vectors of these clusters, select one or more clusters from these clusters; For each feature vector of the one or more clusters, determine a distance between the query vector and the feature vector; and Based on the query vector and the multiple distances between the multiple feature vectors of the one or more clusters, select one or more feature vectors from the one or more clusters.

2. The semiconductor device of claim 1, wherein determining the distance between the query vector and the feature vector comprises: Determine the distance between the feature vector and the centroid vector of the cluster to which the feature vector belongs; Determine a distance between the query vector and the centroid vector of the cluster to which the feature vector belongs; Determine the dot product of the query vector and the feature vector; and The distance between the query vector and the feature vector is determined based on the distance between the feature vector and the centroid vector, the distance between the query vector and the centroid vector, and the dot product.

3. The semiconductor device of claim 2, wherein determining the distance between the feature vector and the centroid vector of the cluster to which the feature vector belongs comprises: The distance between the feature vector and the centroid vector is determined using a mapping table associated with the cluster, wherein the mapping table indicates the following mapping relationship: The cluster's multiple feature vectors; and Multiple distances between these feature vectors and the centroid vector of the cluster.

4. The semiconductor device of claim 2, wherein determining the distance between the feature vector and the centroid vector of the cluster to which the feature vector belongs comprises: Determine the scale level of the feature vector within the cluster to which it belongs; A first value is determined, which indicates a spacing between multiple adjacent scale levels of the cluster; Determine a second value that indicates the magnitude of a minimum scale level of the cluster; and Based on the scale level, the first value, and the second value of the feature vector, the distance between the feature vector and the centroid vector is determined.

5. The semiconductor device of claim 4, wherein determining the scale level of the feature vector within the cluster to which the feature vector belongs comprises: The scale level of the feature vector is determined based on its proximity to these adjacent scale levels in the cluster.

6. A system for calculating distance, comprising: A semiconductor device; and A controller, coupled to the semiconductor device and used to control the semiconductor device, The semiconductor device includes: An array of memory cells used to store data in multiple memory cells; as well as A circuit, coupled to the memory cell array and used to perform multiple operations within the memory cell array, including: Receive a request from the controller that indicates a query vector; Obtain multiple clusters of multiple feature vectors, where each cluster is associated with a corresponding centroid vector; Determine multiple distances between the query vector and multiple centroid vectors of these clusters; Based on the query vector and the distances between the centroid vectors of these clusters, select one or more clusters from these clusters; For each feature vector of the one or more clusters, determine a distance between the query vector and the feature vector; and Based on the query vector and the multiple distances between the multiple feature vectors of the one or more clusters, select one or more feature vectors from the one or more clusters.

7. The system of claim 6, wherein determining the distance between the query vector and the feature vector comprises: Determine the distance between the feature vector and the centroid vector of the cluster to which the feature vector belongs; Determine a distance between the query vector and the centroid vector of the cluster to which the feature vector belongs; Determine the dot product of the query vector and the feature vector; and The distance between the query vector and the feature vector is determined based on the distance between the feature vector and the centroid vector, the distance between the query vector and the centroid vector, and the dot product.

8. A method for calculating distance, comprising: Receive a request indicating a query vector; Obtain multiple clusters of multiple feature vectors, where each cluster is associated with a corresponding centroid vector; Determine multiple distances between the query vector and multiple centroid vectors of these clusters; Based on the query vector and the distances between the centroid vectors of these clusters, select one or more clusters from these clusters; For each feature vector of the one or more clusters, determine a distance between the query vector and the feature vector; and Based on the query vector and the multiple distances between the multiple feature vectors of the one or more clusters, select one or more feature vectors from the one or more clusters.

9. The method of claim 8, wherein determining the distance between the query vector and the feature vector comprises: Determine the distance between the feature vector and the centroid vector of the cluster to which the feature vector belongs; Determine a distance between the query vector and the centroid vector of the cluster to which the feature vector belongs; Determine the dot product of the query vector and the feature vector; and The distance between the query vector and the feature vector is determined based on the distance between the feature vector and the centroid vector, the distance between the query vector and the centroid vector, and the dot product.

10. The method of claim 9, wherein determining the distance between the feature vector and the centroid vector of the cluster to which the feature vector belongs comprises: The distance between the feature vector and the centroid vector is determined using a mapping table associated with the cluster, wherein the mapping table indicates the following mapping relationship: The cluster's multiple feature vectors; and Multiple distances between these feature vectors and the centroid vector of the cluster.