Vector determination method and apparatus, storage medium, and electronic device

By encapsulating the Milvus open-source vector search engine in the database, joint retrieval of vectors and structured data is achieved, solving the problem of insufficient indexing algorithms in existing vector databases, improving retrieval efficiency and performance, reducing costs, and simplifying the system architecture.

CN118012889BActive Publication Date: 2026-11-24SHANGHAI SHANMA INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311868625.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-26
Publication Date
2026-11-24
Estimated Expiration
2044-03-26

AI Technical Summary

Technical Problem

Existing vector databases lack indexing algorithms that support better retrieval results, and they also lack compatibility and scalability, resulting in high costs and low retrieval efficiency in large-scale production environments.

Method used

By receiving structured data from vector retrieval requests, the system concatenates the data and controls an open-source vector search engine to determine the target vector table partition across multiple vector table partitions in the database. Using Milvus as the open-source vector search engine, its interface is encapsulated as a static library file to achieve joint retrieval of vectors and structured data, supporting more indexing algorithms with better retrieval results.

Benefits of technology

It improves the efficiency and performance of vector retrieval, reduces the learning cost, simplifies the system architecture, and maintains the original characteristics of the database. It supports multi-table queries and transaction functions, and significantly improves the computational efficiency during queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118012889B_ABST
    Figure CN118012889B_ABST
Patent Text Reader

Abstract

This invention discloses a method and apparatus for determining vectors, a storage medium, and an electronic device. The method includes: receiving a vector retrieval request, wherein the vector retrieval request carries a first vector and first structured data, the first structured data indicating attribute information corresponding to the first vector; concatenating the first structured data to obtain concatenated first structured data; controlling an open-source vector search engine encapsulated in a database to determine a target vector table partition based on the concatenated first structured data in multiple vector table partitions of the database; and determining a second vector in the target vector table partition based on the first vector, wherein the similarity between the second vector and the first vector is greater than or equal to a preset threshold. This technical solution solves the problem that existing databases cannot support more indexing algorithms with better retrieval effects.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computers, and more specifically, to a method and apparatus for determining vectors, a storage medium, and an electronic device. Background Technology

[0002] With the continuous development of artificial intelligence technology, the application of large-scale AI models has experienced explosive growth. For large-scale AI models, all concepts can be represented by vectors, and vector spaces possess excellent mathematical properties, supporting the calculation of the "distance" between vectors. This means that the correlation between any two abstract concepts can be measured by the distance between their corresponding vectors. This functionality can be applied to retrieval. For example, documents within a knowledge base can be transformed into abstract vectors using a model. During retrieval, only the document "closest" to this query vector needs to be found as the answer and returned to the user. Supporting such a retrieval process requires the use of vector databases.

[0003] Currently, there are many vector database products on the market, such as: the commercial Pinecone AI, a simple and easy-to-use managed vector database service that provides a fully managed, serverless environment for real-time vector similarity search and recommendation systems, reducing the burden of operation and maintenance. While Pinecone's free space is sufficient for most scenarios, its starting cost is relatively high compared to other products in production environments with large databases. The open-source Milvus is an open-source vector similarity search engine that supports multiple similarity metrics and has high scalability. Although Milvus has gained some recognition in the domestic market, its ecosystem is relatively weak and lacks compatibility with other database products. pgvector, a vector image service provided as a plugin based on a relational database, offers services on the open-source relational database PostgreSQL. It is not only easy to operate and performs well, but also inherits the PostgreSQL ecosystem. pgvector, as a plugin for the PostgreSQL Database Management System (PostgreSQL), provides excellent support for vectors. However, pgvector supports a limited number of indexing algorithms and does not perform any quantization or storage optimizations.

[0004] There is currently no effective solution to the problem that existing databases cannot support more indexing algorithms with better retrieval performance.

[0005] Therefore, it is necessary to improve the relevant technology to overcome the aforementioned defects. Summary of the Invention

[0006] This invention provides a method and apparatus for determining vectors, a storage medium, and an electronic device to address the problem that existing databases cannot support more indexing algorithms with better retrieval results.

[0007] According to one aspect of the present invention, a method for determining a vector is provided, comprising: receiving a vector retrieval request, wherein the vector retrieval request carries: a first vector and first structured data, the first structured data being used to indicate attribute information corresponding to the first vector; concatenating the first structured data to obtain concatenated first structured data; controlling an open-source vector search engine encapsulated in a database to determine a target vector table partition based on multiple vector table partitions in the database according to the concatenated first structured data; and determining a second vector in the target vector table partition based on the first vector, wherein the similarity between the second vector and the first vector is greater than or equal to a preset threshold.

[0008] In an exemplary embodiment, controlling an open-source vector search engine to determine a target vector table partition based on multiple vector table partitions in a database using the concatenated first structured data includes: controlling the open-source vector search engine to compare the concatenated first structured data with the identification information of the multiple vector table partitions to obtain a comparison result; determining first identification information consistent with the concatenated first structured data based on the comparison result; and determining the vector table partition corresponding to the first identification information as the target vector table partition.

[0009] In one exemplary embodiment, controlling an open-source vector search engine encapsulated in a database to determine a target vector table partition based on the concatenated first structured data in multiple vector table partitions of the database includes: encapsulating the interface of the open-source vector search engine into a static library file; encapsulating the generated static library file and the header file of the interface into a port of the database's encapsulation layer; and calling the port of the database's encapsulation layer to control the open-source vector search engine encapsulated in the database to determine the target vector table partition based on the concatenated first structured data in multiple vector table partitions of the database.

[0010] In one exemplary embodiment, the method further includes: receiving a vector insertion request, wherein the vector retrieval request carries: a third vector and second structured data, the second structured data being used to indicate attribute information corresponding to the third vector; parsing the vector insertion request to obtain the third vector and the second structured data; and determining a storage area for the third vector based on the second structured data.

[0011] In an exemplary embodiment, determining the storage area of ​​the third vector based on the second structured data includes: concatenating the second structured data to obtain concatenated second structured data; determining whether there is second identification information consistent with the concatenated second structured data in the identification information of the plurality of vector table partitions; and controlling the open-source vector search engine to determine the storage area of ​​the third vector based on the determination result, wherein the determination result indicates one of the following: there is second identification information consistent with the concatenated second structured data in the identification information of the plurality of vector table partitions; or there is no second identification information consistent with the concatenated second structured data in the identification information of the plurality of vector table partitions.

[0012] In an exemplary embodiment, determining the storage area of ​​the third vector based on the determination result includes: if the determination result indicates that there is second identification information in the identification information of the plurality of vector table partitions that is consistent with the concatenated second structured data, determining the vector table partition corresponding to the second identification information as the storage area of ​​the third vector; if the determination result indicates that there is no second identification information in the identification information of the plurality of vector table partitions that is consistent with the concatenated second structured data, establishing a target vector table partition based on the concatenated second structured data, and determining the target vector table partition as the storage area of ​​the third vector.

[0013] In an exemplary embodiment, after determining the second vector in the target vector table partition based on the first vector, the method further includes: determining a data type recognizable by the database and converting the second vector into a third vector corresponding to the data type; and sending a vector retrieval result to a terminal device based on the third vector, wherein the terminal device is the device that sent the vector retrieval request.

[0014] According to another aspect of the present invention, a vector determination apparatus is also provided, comprising: a receiving module for receiving a vector retrieval request, wherein the vector retrieval request carries: a first vector and first structured data, the first structured data being used to indicate attribute information corresponding to the first vector; a splicing module for splicing the first structured data to obtain spliced ​​first structured data; a control module for controlling an open-source vector search engine encapsulated in a database to determine a target vector table partition based on multiple vector table partitions in the database according to the spliced ​​first structured data; and a determination module for determining a second vector in the target vector table partition based on the first vector, wherein the similarity between the second vector and the first vector is greater than or equal to a preset threshold.

[0015] According to another aspect of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored therein, wherein the computer program is configured to execute the above-described vector determination method at runtime.

[0016] According to another aspect of the present invention, an electronic device is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the vector determination method by means of the computer program.

[0017] This invention receives a vector retrieval request carrying a first vector and first structured data indicating the attribute information corresponding to the first vector. An open-source vector search engine encapsulated in a database determines a target vector table partition based on the concatenated first structured data across multiple vector table partitions in the database. The concatenated first structured data is obtained by concatenating multiple first structured data. Then, a second vector with a similarity greater than or equal to a preset threshold is determined in the target vector table partition based on the first vector. This technical solution solves the problem that existing databases cannot support more indexing algorithms with better retrieval performance. Attached Figure Description

[0018] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with the description thereof, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:

[0019] Figure 1 This is a hardware structure block diagram of a computer device for a vector determination method according to an embodiment of the present invention;

[0020] Figure 2 This is a flowchart of a vector determination method according to an embodiment of the present invention;

[0021] Figure 3 This is a flowchart illustrating the insertion vector data according to an exemplary embodiment of this application;

[0022] Figure 4 This is a flowchart illustrating the retrieval process according to an exemplary embodiment of this application;

[0023] Figure 5 This is a schematic diagram illustrating the time consumption of vector joint retrieval under different structured data according to an exemplary embodiment of this application;

[0024] Figure 6 This is a structural block diagram of a vector determination device according to an embodiment of the present invention. Detailed Implementation

[0025] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0026] It should be noted that the terms and terms such as "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0027] The methods and embodiments provided in this application can be executed in a computer device or a similar computing device. Taking running on a computer device as an example, Figure 1 This is a hardware structure block diagram of a computer device for a vector determination method according to an embodiment of the present invention. Figure 1 As shown, a computer device may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor unit (MPU) or a programmable logic device (PLD)) and a memory 104 for storing data are also shown. In one exemplary embodiment, the computer device may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that… Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the computer device described above. For example, the computer device may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 Equivalent functions or ratios shown Figure 1 The functions shown have more different configurations.

[0028] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the vector determination method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, which is equivalent to implementing the above-described method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the computer device via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0029] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by a communications provider for the computer device. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module used for wireless communication with the Internet.

[0030] This embodiment provides a method for determining a vector. Figure 2 This is a flowchart of a vector determination method according to an embodiment of the present invention, applied to the above-described computer device. The process includes the following steps:

[0031] Step S202: Receive a vector retrieval request, wherein the vector retrieval request carries: a first vector and first structured data, the first structured data being used to indicate the attribute information corresponding to the first vector.

[0032] It's important to note that a set of numbers representing a thing is called a vector. Vector retrieval refers to finding one or more vectors that are most similar to a target vector within a given set of vectors.

[0033] Step S204: Concatenate the first structured data to obtain concatenated first structured data.

[0034] Step S206: Control the open-source vector search engine encapsulated in the database to determine the second vector table partition based on the concatenated first structured data in the database's multiple vector table partitions.

[0035] Step S208: Determine a second vector in the target vector table partition based on the first vector, wherein the similarity between the second vector and the first vector is greater than or equal to a preset threshold.

[0036] Through the above steps, a vector retrieval request carrying a first vector and first structured data indicating the attribute information corresponding to the first vector is received. An open-source vector search engine encapsulated in the database determines the target vector table partition based on the concatenated first structured data across multiple vector table partitions in the database. The concatenated first structured data is obtained by concatenating existing structured data. Then, based on the first vector, a second vector with a similarity greater than or equal to a preset threshold is determined in the target vector table partition. This solves the problem that existing databases cannot support more indexing algorithms with better retrieval performance.

[0037] To better understand how the open-source vector search engine encapsulated in the database determines the second vector table partition based on the concatenated first structured data in the database's multiple vector table partitions in step S206, step S206 can be implemented using the following technical solution: Control the open-source vector search engine to compare the concatenated first structured data with the identifier information of the multiple vector table partitions to obtain a comparison result; determine the first identifier information consistent with the concatenated first structured data based on the comparison result; and determine the vector table partition corresponding to the first identifier information as the target vector table partition.

[0038] The vector search engine for the aforementioned technical solution could be Milvus. Milvus is an open-source vector database used to store and manage large-scale vector data. It provides efficient vector similarity search and analysis capabilities, enabling the rapid finding of similar vectors in large datasets.

[0039] Furthermore, in the absence of first identifier information consistent with the concatenated first structured data, a new vector table partition can be created using the identifier information corresponding to the concatenated first structured data as the target vector table partition.

[0040] Optionally, controlling the open-source vector search engine encapsulated in the database to determine the target vector table partition based on the concatenated first structured data in the database's multiple vector table partitions includes: encapsulating the interface of the open-source vector search engine into a static library file; encapsulating the generated static library file and the header file of the interface into the port of the database's encapsulation layer; and calling the port of the database's encapsulation layer to control the open-source vector search engine encapsulated in the database to determine the target vector table partition based on the concatenated first structured data in the database's multiple vector table partitions.

[0041] It should be noted that in this embodiment of the application, the application programming interface (API) provided by Milvus is encapsulated as a static library to provide operations on vector tables and indexes for the development of subsequent open source projects (Multicorn).

[0042] Optionally, this application embodiment also provides a method for storing vectors: receiving a vector insertion request, wherein the vector retrieval request carries: a third vector and second structured data, the second structured data being used to indicate attribute information corresponding to the third vector; parsing the vector insertion request to obtain the third vector and the second structured data; and determining the storage area of ​​the third vector based on the second structured data.

[0043] Optionally, determining the storage area of ​​the third vector based on the second structured data includes: concatenating the second structured data to obtain concatenated second structured data; determining whether there is second identification information consistent with the concatenated second structured data in the identification information of the plurality of vector table partitions; and controlling the open-source vector search engine to determine the storage area of ​​the third vector based on the determination result, wherein the determination result indicates one of the following: there is second identification information consistent with the concatenated second structured data in the identification information of the plurality of vector table partitions; or there is no second identification information consistent with the concatenated second structured data in the identification information of the plurality of vector table partitions.

[0044] Specifically: if the determination result indicates that there is a second identifier information in the identifier information of the plurality of vector table partitions that is consistent with the concatenated second structured data, the vector table partition corresponding to the second identifier information is determined as the storage area of ​​the third vector; if the determination result indicates that there is no second identifier information in the identifier information of the plurality of vector table partitions that is consistent with the concatenated second structured data, a target vector table partition is established based on the concatenated second structured data, and the target vector table partition is determined as the storage area of ​​the third vector.

[0045] To illustrate the technical solution for receiving and parsing vector insertion requests, if a record is inserted into the `partest` table, with each column containing the values: 1, '{1,1}', 0, 'hei', 'nan', 'zhong', then the code for receiving the vector insertion request could be:

[0046] insertintopartestvalues(1,'{1,1}',0,'hei','nan','zhong');

[0047] This is an SQL statement used to insert a record into a table named "partest".

[0048] In this context, "insert into partest" means that data will be inserted into the partest table; "values" represents the specific values ​​to be inserted; "(1,'{1,1}',0,'hei','nan','zhong')" represents the specific values ​​to be inserted, assigned according to the column order of the table; the first value 1 will be inserted into the first column of the table; "{1,1}" is an array that will be inserted into the second column of the table; 0 will be inserted into the third column of the table; "hei" will be inserted into the fourth column of the table; "nan" will be inserted into the fifth column of the table; and "zhong" will be inserted into the sixth column of the table.

[0049] insert into partest(myid,sex,race,age,myvec)values(1,'nan','hei','zhong','{1,1}');

[0050] This is an SQL statement used to insert a new record into the `partest` table. Specifically, it sets `myid` to 1, `sex` to "nan", `race` to "hei", `age` to "zhong", and `myvec` to "{1,1}".

[0051] The above two lines of code provide a technical solution for receiving and parsing vector insertion requests.

[0052] Optionally, after determining the second vector in the target vector table partition based on the first vector, the method further includes: determining the data type recognizable by the database and converting the second vector into a third vector corresponding to the data type; sending the vector retrieval result to the terminal device based on the third vector, wherein the terminal device is the device that sent the vector retrieval request.

[0053] In other words, the second vector determined in this embodiment may be a data type that the database cannot recognize. Therefore, after determining the second vector, the second vector is converted into a third vector according to the data type that the database can recognize, and the third vector is sent to the device that sent the vector retrieval request through the database as a vector retrieval result.

[0054] To better understand the process of determining the above vector, the implementation flow of the above vector determination method will be described below in conjunction with optional embodiments, but this is not intended to limit the technical solution of the embodiments of this application.

[0055] In the current mainstream vector databases, most vector databases are independent database systems. Although some vector databases provide API calling interfaces, they still require additional learning costs when using them. Vector database plugins integrated on relational databases cannot support more indexing algorithms with better retrieval performance due to the limitations of their existing form.

[0056] Therefore, the exemplary embodiments of this application propose a database implementation method that supports joint retrieval of vector and structured data. This method not only enables operations on vector databases based on traditional relational database platforms, but also enables joint retrieval of vector and structured data, further improving retrieval performance.

[0057] Before describing exemplary embodiments of this application, it is necessary to further explain vectors and vector retrieval.

[0058] Vector: A vector is a set of numbers used to represent a single thing. For example, if a vector consists of n numbers, it is an n-dimensional vector. Furthermore, taking facial recognition as an example, a computer extracts an image of a face from a photograph and can then convert that image into a 128-dimensional or higher-dimensional vector.

[0059] Vector retrieval: Given a set of vectors, finding one or more vectors that are closest to a target vector is called vector retrieval. Whether vectors are close depends on the distance between them, which can be cosine distance, Euclidean distance, Hamming distance, etc. For example: Suppose A and B represent two normalized n-dimensional vectors, the formula for calculating their cosine distance is:

[0060] An exemplary embodiment of this application uses the vector search engine Milvus, and the specific steps are as follows:

[0061] 1) The Application Programming Interface (API) provided by Milvus is encapsulated into a static library to provide operations on vector tables and indexes for the development of subsequent open-source projects (Multicorn). Partial API code is shown below:

[0062] void call_Connect(const char*ip,const char*port,int*code,char**message);

[0063] This code declares a function called "call_Connect". The call_Connect function accepts two parameters of type "const char*" "ip" and "port", a pointer parameter of type "int" "code", and a pointer parameter of type "char**" "message".

[0064] The `call_Connect` function is used to establish a connection. It may attempt to connect to a specified server based on the passed "ip" and "port", and return the connection status code and message. The connection status code is stored in the variable pointed to by the "code" pointer, while the connection message is returned by allocating memory and assigning the pointer to "message".

[0065] void call_Create_Collection(milvus_CollectionParam cp,int*code,char**message);

[0066] This code defines a function called "call_Create_Collection" that accepts three parameters: cp of type milvus_CollectionParam, code of type int, and message of type char pointer.

[0067] The `call_Create_Collection` function creates a collection and returns the result of the operation.

[0068] void call_Create_Index(const char*name,char*indextype,int*code,char**message);

[0069] This is a function declaration that declares a function named "call_Create_Index". This function accepts four parameters: name, indextype, code, and message.

[0070] Where: "name" is a pointer to a constant character used to specify the name of the index; "indextype" is a pointer to a character used to specify the type of the index; "code" is a pointer to an integer used to return the result code of the function execution; and "message" is a pointer to a pointer used to return the message of the function execution.

[0071] It should be noted that the specific implementation of the call_Create_Index function needs to be determined according to the specific implementation; here, only the function's parameters and return type are declared.

[0072] void call_Insert_Entity(constchar*name,const char*tag,milvus_ids ids,milvus_Entities entities,const char*ip,const char*port,int*code,char**message);

[0073] This function is a method for inserting entities. The specific parameters are: "name": the name of the entity; "tag": the tag of the entity; "ids": a list of IDs of the entities to be inserted; "entities": a list of entities to be inserted; "ip": the IP address of the Milvus server; "port": the port number of the Milvus server; "code": the return status code; "message": the return message content. The function's purpose is to insert entity data into the Milvus server and return the insertion operation status code and message.

[0074] void call_Search(const char*name,milvus_PartitionTagList plist,milvus_Entities entities,int topk,milvus_TopKQueryResult*query_results,int*code,char**message);

[0075] This is a function declaration defining a function named "call_Search" with the following parameters and return value: "name": a pointer to a constant character representing the name to search for; "plist": a data type named milvus_PartitionTagList representing a list of partition tags; "entities": a data type named milvus_Entities representing entities; "topk": an integer representing the number of most similar entities returned; "query_results": a pointer to milvus_TopKQueryResult representing the query results; "code": a pointer to an integer representing the returned error code; "message": a pointer to a pointer representing the returned error message; "void": indicating that the function has no return value.

[0076] 2) Implement FDW development within Multicorn, which requires implementing the following ports:

[0077] 1. GetForeignRelSize (a function in the PostgreSQL database management system): Gets a cost estimate for the basic scan method of an SQL statement.

[0078] 2. GetForeignPaths and GetForeignPlan: Calculate the plan path for various scenarios, including basic scans and various join methods. After selecting the best path from multiple plan paths, recover the SQL statement that needs to be executed in the executor from this path.

[0079] 3. BeginForeignScan, IterateForeignScan, ReScanForeignScan, and EndForeignScan: These are used to execute query operations. Here, the SQL needs to be parsed to obtain the input target vector, and the encapsulated Milvus API is called to perform the retrieval, returning the top K query results.

[0080] 4. BeginForeignModify, ExecForeignInsert, EndForeignModify, ExecForeignDelete, ExecForeignUpdate: These are used to perform data insertion, deletion, and update operations. They also require parsing SQL statements, converting the data into the corresponding structure, and calling the interface to store it in the vector engine.

[0081] 3) After the required features within Multicorn are developed and packaged, add the extension to PostgreSQL. This can be achieved using the following code:

[0082] Create extension multicorn;

[0083] When storing vectors with structured information, the following table creation methods can be used:

[0084] create foreign table partest(myid bigint,myvec float[2],myscorefloat4,race varchar,sex varchar,age varchar)server pgVector_srv options();

[0085] Among them, race, sex, and age are structured data columns.

[0086] The code above demonstrates how to specify options for an external table using the "OPTIONS()" clause when creating it. In the given statement, the "OPTIONS()" clause is empty, meaning no options are specified for the external table.

[0087] Options can be used to specify parameters related to the external table, such as file path, connection string, data format, data delimiter, etc. Different options may be supported depending on the specific external table type and the external table server used. In the exemplary embodiment of this application, the "OPTIONS()" clause is empty, possibly because no specific options have been specified for the external table "partest".

[0088] Furthermore, Figure 3 This is a flowchart illustrating the insertion of vector data according to an exemplary embodiment of this application. When inserting vector data, structured information is extracted within the implemented port, and a corresponding partition is created within the vector engine. The partition ID is associated with the extracted structured information. Specifically, as shown... Figure 3 As shown:

[0089] Step S301: Insert the SQL statement into PostgreSQL;

[0090] Step S302: Input PostgreSQL into Multicorn via FDW;

[0091] Step S303: Extract vector information and structured data, concatenate the structured data into a partition ID, and input the concatenated partition ID into the vector engine;

[0092] Step S304: Determine whether there is already a partition with the corresponding ID in the vector table using the vector engine; if there is already a partition with the corresponding ID in the vector table, proceed to step S305; if there is no partition with the corresponding ID in the vector table, proceed to step S306.

[0093] Step S305: Store the vector in the partition;

[0094] Step S306: Create a new partition with the ID and store the vector.

[0095] The SQL syntax for inserting structured vector data is as follows:

[0096] insert into partest values(1,'{1,1}',0,'hei','nan','zhong');

[0097] insert into partest(myid,sex,race,age,myvec)values(1,'nan','hei','zhong','{1,1}');

[0098] In addition, it supports default values ​​and empty fields, but these two are not equivalent when querying.

[0099] The SQL statement `INSERT INTO partest VALUES(1,'{1,1}',0,'hei','nan','zhong')` inserts a record into a table named `partest`. Here, `"INSERT INTO partest"` means that data will be inserted into the `partest` table; `"VALUES"` represents the specific values ​​to be inserted; `"(1,'{1,1}',0,'hei','nan','zhong')` represents the specific values ​​to be inserted, assigned in column order; the first value, 1, will be inserted into the first column; `"{1,1}"` is an array that will be inserted into the second column; `"0"` will be inserted into the third column; `"hei"` will be inserted into the fourth column; `"nan"` will be inserted into the fifth column; and `"zhong"` will be inserted into the sixth column.

[0100] The SQL statement `insert into partest(myid,sex,race,age,myvec)values(1,'nan','hei','zhong','{1,1}')` inserts a new record into the `partest` table. Specifically, it sets `myid` to 1, `sex` to "nan", `race` to "hei", `age` to "zhong", and `myvec` to "{1,1}".

[0101] Furthermore, Figure 4 This is a flowchart of a search process according to an exemplary embodiment of this application, specifically, as follows: Figure 4 As shown:

[0102] Step S401: Insert the SQL statement into PostgreSQL;

[0103] Step S402: Input PostgreSQL into Multicorn via FDW;

[0104] Step S403: Extract vector information and structured data, concatenate the structured data into a partition ID, and input the concatenated partition ID into the vector engine;

[0105] Step S404: Perform vector retrieval in the corresponding partition using the vector engine;

[0106] Step S405: Return the retrieved TopK vector table T section A / a / 3, vector table T section A / b / 3, vector table T section A / c / 3... vector table T section * / * / * to the vector engine;

[0107] In step S406, the vector engine returns the search results to Multicorn;

[0108] Step S407: Convert the search results in Multicorn into a data type that PG can recognize and send it to PostgreSQL;

[0109] Step S408: Output the search results in PostgreSQL.

[0110] The exemplary embodiments of this application demonstrate that vector operations can be performed directly using SQL statements, thereby storing business logic within a single system and simplifying the system architecture to some extent.

[0111] Furthermore, the SQL statements used in the operation vector library are basically the same as those used in relational databases, requiring no additional learning cost. It also supports multi-table queries, transactions, and other functions, maintaining the original characteristics of the database.

[0112] Furthermore, due to the support vector structured joint query, the amount of data that needs to be calculated during the query is reduced, resulting in a significant performance improvement compared to unstructured retrieval.

[0113] Through the embodiments of this application, experimental results comparing the performance of vector structured joint retrieval and non-joint retrieval can be obtained. Figure 5 This is a schematic diagram illustrating the time consumption of vector joint retrieval under different structured data according to exemplary embodiments of this application, such as... Figure 5 As shown, specifically:

[0114] The comparative experiment used a vector table with two structured columns, storing the resulting partition IDs as: 'A / 1', 'A / 2', 'A / 3', 'A / 4', 'B / 1', 'B / 2', 'B / 3', 'C / 1', 'C / 2', and 'C / 3'. Each partition contained ten million 128-dimensional vector data entries, totaling one hundred million entries. The time taken for joint retrieval under different structured data was recorded, and the average of ten retrieval times was recorded.

[0115] from Figure 5 As can be seen, the query efficiency using vector structured joint retrieval is significantly improved compared to non-joint retrieval (i.e., full retrieval).

[0116] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of the present invention.

[0117] This embodiment also provides a vector determination device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, hardware implementations, or a combination of software and hardware, are also possible and contemplated.

[0118] Figure 6 This is a structural block diagram of a vector determination device according to an embodiment of the present invention, the device comprising:

[0119] The receiving module 52 is used to receive a vector retrieval request, wherein the vector retrieval request carries: a first vector and first structured data, and the first structured data is used to indicate the attribute information corresponding to the first vector;

[0120] The splicing module 54 is used to splice the first structured data to obtain spliced ​​first structured data;

[0121] Control module 56 is used to control the open-source vector search engine encapsulated in the database to determine the target vector table partition based on the concatenated first structured data in the database's multiple vector table partitions;

[0122] The determining module 58 is used to determine a second vector in the target vector table partition based on the first vector, wherein the similarity between the second vector and the first vector is greater than or equal to a preset threshold.

[0123] The aforementioned device receives vector retrieval requests carrying a first vector and first structured data indicating the attribute information corresponding to the first vector. It then controls an open-source vector search engine encapsulated in the database to determine a target vector table partition based on the concatenated first structured data across multiple vector table partitions in the database. The concatenated first structured data is obtained by concatenating multiple first structured data. Finally, based on the first vector, a second vector with a similarity greater than or equal to a preset threshold is determined in the target vector table partition. This technical solution solves the problem that existing databases cannot support more indexing algorithms with better retrieval performance.

[0124] In an exemplary embodiment, the determining module 58 is configured to control the open-source vector search engine to compare the concatenated first structured data with the identification information of the plurality of vector table partitions to obtain a comparison result; determine the first identification information that is consistent with the concatenated first structured data based on the comparison result; and determine the vector table partition corresponding to the first identification information as the target vector table partition.

[0125] In an exemplary embodiment, the determining module 58 is configured to encapsulate the interface of the open-source vector search engine into a static library file; encapsulate the generated static library file and the header file of the interface into the port of the encapsulation layer of the database; and call the port of the encapsulation layer of the database to control the open-source vector search engine encapsulated in the database to determine the target vector table partition based on the concatenated first structured data in the multiple vector table partitions of the database.

[0126] In one exemplary embodiment, the apparatus further includes: an insertion module, configured to receive a vector insertion request, wherein the vector retrieval request carries: a third vector and second structured data, the second structured data being used to indicate attribute information corresponding to the third vector; parse the vector insertion request to obtain the third vector and the second structured data; and determine a storage area for the third vector based on the second structured data.

[0127] In one exemplary embodiment, an insertion module is configured to concatenate the second structured data to obtain concatenated second structured data; determine whether there is second identification information consistent with the concatenated second structured data in the identification information of the plurality of vector table partitions; and control the open-source vector search engine to determine the storage area of ​​the third vector based on the determination result, wherein the determination result is used to indicate one of the following: there is second identification information consistent with the concatenated second structured data in the identification information of the plurality of vector table partitions; or there is no second identification information consistent with the concatenated second structured data in the identification information of the plurality of vector table partitions.

[0128] In an exemplary embodiment, the insertion module is configured to: determine the vector table partition corresponding to the second identification information as the storage area of ​​the third vector when the determination result indicates that there is a second identification information in the identification information of the plurality of vector table partitions that is consistent with the concatenated second structured data; and establish a target vector table partition based on the concatenated second structured data when the determination result indicates that there is no second identification information in the identification information of the plurality of vector table partitions that is consistent with the concatenated second structured data, and determine the target vector table partition as the storage area of ​​the third vector.

[0129] In one exemplary embodiment, the above apparatus further includes: a sending module, configured to determine a data type recognizable by the database, and convert the second vector into a third vector corresponding to the data type; and send a vector retrieval result to a terminal device based on the third vector, wherein the terminal device is the device that sent the vector retrieval request.

[0130] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:

[0131] S1, Receive a vector retrieval request, wherein the vector retrieval request carries: a first vector and first structured data, the first structured data being used to indicate the attribute information corresponding to the first vector;

[0132] S2, concatenate the first structured data to obtain the concatenated first structured data;

[0133] S3, the open-source vector search engine encapsulated in the database determines the second vector table partition based on the concatenated first structured data in the database's multiple vector table partitions;

[0134] S4, determine a second vector in the target vector table partition based on the first vector, wherein the similarity between the second vector and the first vector is greater than or equal to a preset threshold.

[0135] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.

[0136] Specific examples in this embodiment can be found in the examples described in the above embodiments and exemplary implementations, and will not be repeated here.

[0137] Embodiments of the present invention also provide an electronic device including a memory and a processor, the memory storing a computer program and the processor being configured to run the computer program to perform the steps in any of the above method embodiments.

[0138] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:

[0139] S1, Receive a vector retrieval request, wherein the vector retrieval request carries: a first vector and first structured data, the first structured data being used to indicate the attribute information corresponding to the first vector;

[0140] S2, concatenate the first structured data to obtain the concatenated first structured data;

[0141] S3, the open-source vector search engine encapsulated in the database determines the second vector table partition based on the concatenated first structured data in the database's multiple vector table partitions;

[0142] S4, determine a second vector in the target vector table partition based on the first vector, wherein the similarity between the second vector and the first vector is greater than or equal to a preset threshold.

[0143] In one exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.

[0144] Specific examples in this embodiment can be found in the examples described in the above embodiments and exemplary implementations, and will not be repeated here.

[0145] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.

[0146] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for determining a vector, characterized in that, include: A vector retrieval request is received, wherein the vector retrieval request carries: a first vector and first structured data, the first structured data being used to indicate attribute information corresponding to the first vector; The first structured data is concatenated to obtain the concatenated first structured data; The open-source vector search engine, which is encapsulated in the database, determines the second vector table partition based on the concatenated first structured data in the database's multiple vector table partitions. A second vector is determined in the target vector table partition based on the first vector, wherein the similarity between the second vector and the first vector is greater than or equal to a preset threshold. The process of controlling the open-source vector search engine encapsulated in the database to determine the target vector table partition based on the concatenated first structured data in the database includes: encapsulating the interface of the open-source vector search engine into a static library file; encapsulating the generated static library file and the header file of the interface into the port of the database's encapsulation layer; and calling the port of the database's encapsulation layer to control the open-source vector search engine encapsulated in the database to determine the target vector table partition based on the concatenated first structured data in the database's multiple vector table partitions.

2. The method for determining a vector according to claim 1, characterized in that, The open-source vector search engine is controlled to determine the target vector table partition based on the concatenated first structured data in multiple vector table partitions in the database, including: The open-source vector search engine is controlled to compare the concatenated first structured data with the identification information of the multiple vector table partitions to obtain the comparison results; Based on the comparison results, a first identification information consistent with the spliced ​​first structured data is determined; The vector table partition corresponding to the first identification information is determined to be the target vector table partition.

3. The method for determining a vector according to claim 1, characterized in that, The method further includes: A vector insertion request is received, wherein the vector retrieval request carries: a third vector and second structured data, the second structured data being used to indicate the attribute information corresponding to the third vector; Parse the vector insertion request to obtain the third vector and the second structured data; The storage area for the third vector is determined based on the second structured data.

4. The method for determining a vector according to claim 3, characterized in that, Determining the storage area of ​​the third vector based on the second structured data includes: The second structured data is concatenated to obtain the concatenated second structured data; Determine whether there is a second identifier in the identifier information of the multiple vector table partitions that is consistent with the concatenated second structured data; The open-source vector search engine is controlled to determine the storage area of ​​the third vector based on the determination result, wherein the determination result is used to indicate one of the following: there is second identification information in the identification information of the plurality of vector table partitions that is consistent with the concatenated second structured data; or there is no second identification information in the identification information of the plurality of vector table partitions that is consistent with the concatenated second structured data.

5. The method for determining a vector according to claim 4, characterized in that, The storage area for the third vector is determined based on the determination result, including: If the determination result indicates that there is a second identifier information in the identifier information of the plurality of vector table partitions that is consistent with the concatenated second structured data, then the vector table partition corresponding to the second identifier information is determined as the storage area of ​​the third vector; If the determination result indicates that there is no second identifier information in the identifier information of the plurality of vector table partitions that is consistent with the concatenated second structured data, a target vector table partition is established based on the concatenated second structured data, and the target vector table partition is determined as the storage area of ​​the third vector.

6. The method for determining a vector according to claim 1, characterized in that, After determining the second vector in the target vector table partition based on the first vector, the method further includes: Determine the data types that the database can recognize, and convert the second vector into a third vector corresponding to the data type; The vector retrieval result is sent to the terminal device according to the third vector, wherein the terminal device is the device that sent the vector retrieval request.

7. A vector determining device, characterized in that, include: A receiving module is used to receive a vector retrieval request, wherein the vector retrieval request carries: a first vector and first structured data, the first structured data being used to indicate attribute information corresponding to the first vector; The splicing module is used to splice the first structured data to obtain spliced ​​first structured data; The control module is used to control the open-source vector search engine encapsulated in the database to determine the target vector table partition based on the concatenated first structured data in the database's multiple vector table partitions; The determining module is used to determine a second vector in the target vector table partition based on the first vector, wherein the similarity between the second vector and the first vector is greater than or equal to a preset threshold. The control module is further configured to encapsulate the interface of the open-source vector search engine into a static library file; encapsulate the generated static library file and the header file of the interface into the port of the encapsulation layer of the database; and call the port of the encapsulation layer of the database to control the open-source vector search engine encapsulated in the database to determine the target vector table partition based on the concatenated first structured data in the multiple vector table partitions of the database.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein the program, when executed, performs the method described in any one of claims 1 to 6.

9. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to execute the method described in any one of claims 1 to 6 through the computer program.

Citation Information

Patent Citations

  • Request result determination method and device, storage medium and electronic device

    CN114490095A

  • Information retrieval method and device

    CN116186298A