Searching method and device, electronic equipment, storage medium and computer program product
By storing vector data locally and combining it with keyword indexing technology, the issues of real-time performance, privacy protection, and cost control in cloud-based vector databases are resolved, enabling efficient and accurate local vector retrieval and result generation.
Patent Information
- Application Number
- CN202511393823.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-26
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2045-09-26
AI Technical Summary
The existing RAG technology framework relies on cloud-based vector databases for vector retrieval, which has technical limitations in terms of real-time performance, privacy protection, and cost control.
By employing a local vector database, vector indexes and text blocks of external documents are stored in non-volatile memory. Combined with keyword indexing and word segmentation technology, local vector retrieval and keyword matching are performed, reducing reliance on the cloud.
It improves the accuracy of search results, avoids network latency and high costs, ensures privacy protection, and reduces reliance on vectorization models.
Smart Images

Figure CN120873173B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the field of deep learning, and in particular, to a retrieval method and device, electronic device, storage medium, and computer program product. BACKGROUND
[0002] With the rapid development of artificial intelligence technology, especially natural language processing (NLP), large language models (LLM) based on deep learning have made remarkable achievements in text generation, dialogue systems, machine translation, and other fields. However, the knowledge base of these large-scale pre-training language models often has the problems of lagging and insufficient professionalism, and cannot cover the latest information in specific fields or deep knowledge in specific industries. To solve this problem, retrieval-augmented generation (RAG) technology has emerged, which introduces an external knowledge base on the basis of LLM, realizes the output of the generation model through vector retrieval, and thus improves the accuracy and relevance of the generation results.
[0003] Since traditional databases are inefficient in handling vector data and similarity searches, existing RAG technology frameworks generally rely on vector databases deployed in the cloud to handle large-scale data retrieval requirements. However, the cloud-based vector database solution has technical limitations in real-time performance, privacy protection, and cost control. SUMMARY
[0004] The present disclosure provides a retrieval method and device, electronic device, storage medium, and computer program product to at least solve the technical limitation problem of relying on cloud vector databases for vector retrieval in real-time performance, privacy protection, and cost control.
[0005] According to a first aspect of the embodiments of the present disclosure, a retrieval method is provided, including: obtaining a query vector of a query question; determining, by using a vector index in a local non-volatile memory, a first predetermined number of vectors with high similarity to the query vector as a vector retrieval result, wherein the non-volatile memory is used to store the vector index of an external document and a text block corresponding to each vector under the vector index, and the text block is obtained by blocking the text content of the external document; obtaining the text block corresponding to the vector retrieval result from the non-volatile memory; performing word segmentation on the text block corresponding to the vector retrieval result and the query question; creating a keyword index based on the word segmentation result of the text block corresponding to the vector retrieval result; performing keyword retrieval based on the word segmentation result of the query question and the keyword index to obtain a second predetermined number of text blocks with high matching degree to the query question, wherein the second predetermined number of text blocks are used to assist a local large language model to generate an answer to the query question.
[0006] Optionally, before determining, by using the vector index in the local non-volatile memory, the first predetermined number of vectors with high similarity to the query vector as the vector retrieval result, the method further includes: creating a plane vector index of the external document; writing the plane vector index into a predetermined buffer area of the local memory, wherein the predetermined buffer area is an area in the memory used to store the plane vector index of the external document; and in response to the data amount in the predetermined buffer area reaching a preset threshold, writing the plane vector index in the predetermined buffer area into the non-volatile memory; wherein the step of determining, by using the vector index in the local non-volatile memory, the first predetermined number of vectors with high similarity to the query vector as the vector retrieval result includes: determining, by using the vector index in the predetermined buffer area and the non-volatile memory, the first predetermined number of vectors with high similarity to the query vector as the vector retrieval result.
[0007] Optionally, in response to the data amount in the predetermined buffer area reaching the preset threshold, writing the plane vector index in the predetermined buffer area into the non-volatile memory includes: in response to the data amount in the predetermined buffer area reaching the preset threshold and the number of vectors under the plane vector index in the predetermined buffer area being greater than a third predetermined number, creating a non-plane vector index based on the plane vector index in the predetermined buffer area; writing the non-plane vector index into the non-volatile memory and emptying the predetermined buffer area.
[0008] Optionally, the creating the flat vector index of the external document comprises: in response to the external document being a pure text document, dividing the text content of the external document into a plurality of text blocks in a sliding window manner; in response to the external document being a structured document, dividing the text content of the external document into a plurality of text blocks based on hierarchical information of the external document, wherein each text block contains hierarchical information of all levels to which the text block belongs in the external document; respectively vectorizing each text block to obtain a vector of each text block; and creating the flat vector index based on the vector of each text block.
[0009] Optionally, the receiving the deletion file list, wherein the deletion file list comprises an identifier of at least one to-be-deleted document; querying an index creation state of the at least one to-be-deleted document; for the to-be-deleted document whose index creation state is index creation success, querying a predetermined vector index of the to-be-deleted document from the memory based on the identifier of the to-be-deleted document; in response to the predetermined vector index existing in the memory, deleting the predetermined vector index from the memory; in response to the predetermined vector index not existing in the memory, querying the predetermined vector index from the non-volatile storage, and setting a deletion flag corresponding to the predetermined vector index to 1, wherein the predetermined vector index is a vector index of the to-be-deleted document; for the to-be-deleted document whose index creation state is in an index creation process, stopping the index creation process of the to-be-deleted document; and for the to-be-deleted document whose index creation state is index creation failure, skipping the to-be-deleted document.
[0010] Optionally, the determining the first predetermined number of vectors with higher similarity to the query vector using the vector indexes in the predetermined buffer and the non-volatile storage and taking the first predetermined number of vectors as the vector retrieval result comprises: determining the similarity of each vector under the vector index in the predetermined buffer in the memory to the query vector using the vector index in the predetermined buffer in the memory; determining the similarity of each vector under the vector index in the non-volatile storage to the query vector using the vector index in the non-volatile storage; merging the vectors under the vector indexes in the predetermined buffer and the non-volatile storage and sorting the vectors in descending order of similarity to determine the first predetermined number of vectors with higher similarity as the vector retrieval result.
[0011] Optionally, the determining the similarity of each vector under the vector index in the non-volatile storage to the query vector using the vector index in the non-volatile storage comprises: constructing a bit map based on a deletion flag bit of the vector index in the non-volatile storage; and determining the similarity of each vector under the vector index in the non-volatile storage whose deletion flag bit is 0 to the query vector using the bit map and the vector index in the non-volatile storage.
[0012] According to a second aspect of the embodiments of the present disclosure, a retrieval device is provided, comprising: a first acquisition unit configured to acquire a query vector of a query question; a first retrieval unit configured to determine, by using a vector index in a local non-volatile memory, a first predetermined number of vectors with higher similarity to the query vector as a vector retrieval result, wherein the non-volatile memory is used to store the vector index of an external document and a text block corresponding to each vector under the vector index, and the text block is obtained by blocking the text content of the external document; a second acquisition unit configured to acquire the text block corresponding to the vector retrieval result from the non-volatile memory; a word segmentation unit configured to perform word segmentation on the text block corresponding to the vector retrieval result and the query question; a creation unit configured to create a keyword index based on the word segmentation result of the text block corresponding to the vector retrieval result; and a second retrieval unit configured to perform keyword retrieval based on the word segmentation result of the query question and the keyword index to obtain a second predetermined number of text blocks with higher matching degree to the query question, wherein the second predetermined number of text blocks are used to assist a local large language model to generate an answer to the query question.
[0013] Optionally, the first retrieval unit is further configured to, before determining, by using the vector index in the local non-volatile memory, the first predetermined number of vectors with higher similarity to the query vector as the vector retrieval result, create a plane vector index of the external document; write the plane vector index into a predetermined buffer area of the local memory, wherein the predetermined buffer area is an area in the memory used to store the plane vector index of the external document; in response to the data amount in the predetermined buffer area reaching a preset threshold, write the plane vector index in the predetermined buffer area into the non-volatile memory; and determine, by using the predetermined buffer area and the vector index in the non-volatile memory, the first predetermined number of vectors with higher similarity to the query vector as the vector retrieval result.
[0014] Optionally, the first retrieval unit is further configured to, in response to the data amount in the predetermined buffer area reaching the preset threshold and the number of vectors under the plane vector index in the predetermined buffer area being greater than a third predetermined number, create a non-plane vector index based on the plane vector index in the predetermined buffer area; write the non-plane vector index into the non-volatile memory and empty the predetermined buffer area.
[0015] Optionally, the first retrieval unit is further configured to, in response to the external document being a pure text document, block the text content of the external document in a sliding window manner to obtain a plurality of text blocks; and in response to the external document being a structured document, block the text content of the external document based on the hierarchical information of the external document to obtain a plurality of text blocks, wherein each text block contains the hierarchical information of all levels to which the text block belongs in the external document; vectorize each text block respectively to obtain a vector of each text block; and create the plane vector index based on the vector of each text block.
[0016] Optionally, the apparatus further comprises a deleting unit configured to receive a deleting file list, wherein the deleting file list comprises an identification of at least one to-be-deleted document; query an index creation state of the at least one to-be-deleted document; for the to-be-deleted document with the index creation state of index creation success, query a predetermined vector index from the memory based on the identification of the to-be-deleted document; in response to the existence of the predetermined vector index in the memory, delete the predetermined vector index from the memory; in response to the non-existence of the predetermined vector index in the memory, query the predetermined vector index from the non-volatile memory, and set a deletion flag corresponding to the predetermined vector index to 1, wherein the predetermined vector index is a vector index of the to-be-deleted document; for the to-be-deleted document with the index creation state in an index creation process, stop the index creation process of the to-be-deleted document; for the to-be-deleted document with the index creation state of index creation failure, skip the to-be-deleted document.
[0017] Optionally, the first retrieving unit is further configured to determine the similarity between each vector under a vector index in a predetermined buffer of the memory and the query vector by using the vector index in the predetermined buffer; determine the similarity between each vector under a vector index in the non-volatile memory and the query vector by using the vector index in the non-volatile memory; merge the vectors under the vector indexes in the predetermined buffer and the non-volatile memory and sort the vectors in descending order of the similarity, and determine a first predetermined number of vectors with higher similarity as the vector retrieval result.
[0018] Optionally, the first retrieving unit is further configured to construct a bit map based on a deletion flag bit of the vector index in the non-volatile memory; and determine the similarity between each vector under a vector index with the deletion flag bit of 0 in the non-volatile memory and the query vector by using the bit map and the vector index in the non-volatile memory.
[0019] According to a third aspect of embodiments of the present disclosure, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to execute the instructions to implement the retrieval method according to the present disclosure.
[0020] According to a sixth aspect of embodiments of the present disclosure, a computer-readable storage medium is provided, when the instructions in the computer-readable storage medium are executed by at least one processor, the at least one processor is caused to perform the retrieval method according to the present disclosure.
[0021] According to a seventh aspect of embodiments of the present disclosure, a computer program product is provided, comprising computer instructions, which, when executed by a processor, implement the retrieval method according to the present disclosure.
[0022] The technical solutions provided by the embodiments of the present disclosure at least bring the following beneficial effects:
[0023] According to the retrieval method and device, the electronic device, the storage medium and the computer program product, the vector data is stored locally and the processing of the vector data is also local, so that the dependence on the cloud vector database is eliminated, the dependence on the network is avoided, the network delay and bandwidth bottleneck problems commonly existing in the cloud service are avoided, the storage cost and the high cost of charging by access amount of the cloud service are avoided, and the security risk of transmitting sensitive data to the cloud is avoided; in addition, the keyword reordering algorithm is provided, that is, more retrieval results are obtained in advance when the vector is retrieved, then the source text information is obtained from the predetermined cache area and the nonvolatile memory according to the retrieval results, and the query question and the source text information are segmented respectively, the source text segmentation result is used to create a keyword index, the second predetermined number of text blocks with the highest matching degree with the query question are obtained by searching the keyword index by using the segmentation result of the query question, as the final retrieval result, the dependence on the vectorization model is reduced, and the accuracy of the retrieval result is improved.
[0024] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present disclosure. BRIEF DESCRIPTION OF DRAWINGS
[0025] The accompanying drawings incorporated in the specification and forming a part of it illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the disclosure without imposing undue limitation on the disclosure.
[0026] Figure 1 is a flowchart of a retrieval method according to an exemplary embodiment;
[0027] Figure 2 is a schematic diagram of a document parsing and text blocking flowchart according to an exemplary embodiment;
[0028] Figure 3 is a schematic diagram of a vector index creation flow according to an exemplary embodiment;
[0029] Figure 4 is a schematic diagram of the relationship of three tables according to an exemplary embodiment;
[0030] Figure 5 is a schematic diagram of a vector index deletion flow according to an exemplary embodiment;
[0031] Figure 6 is a schematic diagram of a vector retrieval flow according to an exemplary embodiment;
[0032] Figure 7 is a system architecture diagram of a local vector database according to an exemplary embodiment;
[0033] Figure 8 is a block diagram of a retrieval device according to an exemplary embodiment;
[0034] Figure 9 is a block diagram of an electronic device 900 according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0035] In order for those skilled in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be described clearly and completely below with reference to the drawings.
[0036] It should be noted that the terms "first", "second", and the like in the specification and claims of the present disclosure and the above-described drawings are used to distinguish similar objects, and do not necessarily have to describe a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following embodiments do not represent all embodiments consistent with the present disclosure. Rather, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0037] It should be noted that "at least one of a plurality of items" appearing in the present disclosure means that the three types of alternatives of "any one of the plurality of items", "a combination of any multiple of the plurality of items", and "all of the plurality of items" are included. For example, "including at least one of A and B" includes the following three alternatives: (1) including A; (2) including B; (3) including A and B. For another example, "performing at least one of step one and step two" means the following three alternatives: (1) performing step one; (2) performing step two; (3) performing step one and step two.
[0038] RAGs perform outstandingly in applications such as question-answering systems, intelligent customer service, knowledge base management, and complex task-oriented dialogue systems. By introducing a retrieval step, RAGs not only improve the accuracy of generation, but also make the generated content have more detailed and knowledge-related details. The RAG application scenarios mainly include two process steps:
[0039] Retrieval step: Obtain external or internal knowledge related to user input through an information retrieval module, generate a query, and find similar data segments.
[0040] Generation step: Input the retrieval results into a generative model to generate responses or content that better meet actual needs and context.
[0041] The information retrieval module in the above search step usually needs to perform efficient vector similarity search to quickly find relevant information from the knowledge base for the user query, so it needs to process and store a large amount of vector data to realize similarity search on high-dimensional data. Because traditional databases are inefficient in processing vector data and similarity search, the existing RAG technology framework generally relies on vector databases deployed in the cloud to handle large-scale data retrieval requirements. Cloud-based vector databases are usually based on distributed computing architecture to store and retrieve large amounts of vector data. The following is a general implementation scheme of the current mainstream cloud vector database technology:
[0042] Distributed storage: Vector data is stored in a distributed storage system, which manages the distribution of data through sharding to handle large-scale data sets. These sharded data can be distributed across multiple nodes to achieve load balancing and efficient access.
[0043] Vector index: Cloud-based vector databases usually use specific vector index structures, such as HNSW (Hierarchical Navigable Small World), an approximate nearest neighbor search algorithm commonly used to implement fast high-dimensional vector retrieval; IVF-PQ (Inverted File Product Quantization), which significantly reduces vector storage space through blocking and quantization to support fast matching of large-scale vector data; LSH (Locality-Sensitive Hashing), a hashing technique used to accelerate vector similarity search, especially suitable for high-dimensional data.
[0044] High-concurrency retrieval: Cloud-based vector databases design multi-level caching and high-concurrency processing mechanisms combined with load balancing strategies to support a large number of concurrent retrieval requests and ensure system response time within a reasonable range.
[0045] API interface: Cloud-based vector databases interface with application systems through Application Programming Interface (API) interfaces (such as REST, gRPC, etc.) to provide standardized query, insertion, and update operations for use in various environments.
[0046] However, the above cloud vector database scheme has the following technical limitations:
[0047] Real-time: Cloud-based vector databases are limited by network connection quality and latency, which can affect user experience, especially in applications with high real-time requirements.
[0048] Privacy protection: In applications involving user sensitive information, such as medical question and answer, financial customer service, etc., cloud data storage and retrieval has privacy and security risks, and the process of uploading user data to the cloud may cause data leakage or privacy infringement problems.
[0049] Cost control: Cloud services usually charge by access times or storage capacity, and in high-frequency access scenarios, the cost will rise sharply, which is not suitable for enterprises or organizations with limited budget or cost sensitivity.
[0050] To solve the above problems, the present disclosure proposes a local vector database, that is, storing vector data locally, users can realize vector data storage and fast retrieval on local devices, so that it is no longer dependent on the vector database in the cloud, thereby eliminating the dependence on the network, avoiding the network delay and bandwidth bottleneck problems commonly seen in cloud services, significantly improving the real-time performance, also avoiding the storage fees of cloud services and the high cost of charging by access volume, and avoiding the security risks of transmitting sensitive data to the cloud. Moreover, the present disclosure also proposes a keyword reordering algorithm, that is, when retrieving vectors, more retrieval results are obtained first, then the source text information is obtained from the predetermined cache area and the non-volatile memory according to the retrieval results, and the query question and the source text information are segmented respectively, the source text segmentation result is used to create a keyword index, the query question segmentation result is used to retrieve in the keyword index, and the text blocks with the matching degree ranked in the front second predetermined number are obtained as the final retrieval results, which reduces the dependence on the vectorization model and improves the accuracy of the retrieval results. In addition, the present disclosure also stores the vector data in segments, that is, when new vector indexes are written, they are first stored in the predetermined cache area of the local memory, and when the data volume in the predetermined cache area reaches the preset threshold, the vector indexes in the predetermined cache area are written to the non-volatile memory, which avoids the frequent file IO operations caused by directly writing to the non-volatile memory, and also avoids the problem of excessive consumption of local memory caused by storing all vector indexes in the memory. In addition, the present disclosure also uses a structured method for parsing, that is, according to the structure information in the document, the document is blocked by level, and each block includes the hierarchical information of all levels to which it belongs in the document, such as multi-level titles in docx and table information in xslx table, etc. These structure information can provide more information for the text block when blocking, making the retrieval result more accurate. In summary, compared with related technologies, the present disclosure provides a more economical, efficient and stable solution.
[0051] In the following, the retrieval method and device, electronic equipment, storage medium and computer program product according to the exemplary embodiments of the present disclosure will be described in detail with reference to the accompanying drawings.
[0052] Figure 1 is a flowchart of a retrieval method according to an exemplary embodiment, as shown inFigure 1 As shown, the retrieval method comprises the following steps:
[0053] In step 101, a query vector of a query question is obtained.
[0054] As an example, a vector retrieval interface can be pre-set, in response to the vector retrieval interface being invoked, a query request input by a user is received, wherein the query request can include a query question; the query question is vectorized, i.e., a query vector is obtained;
[0055] As an example, the number of returned results in the above query request can also be included, i.e., it is indicated that how many results related to the query question are included in the final returned retrieval results, such as selecting the top how many results after sorting according to the relevance to the query question, which is not limited by the present disclosure.
[0056] As an example, an end-side vectorization model HTTP interface can be invoked, the text of the query question is input, and the corresponding query vector is obtained, which is not limited by the present disclosure.
[0057] Return Figure 1 In step 102, the first predetermined number of vectors with high similarity to the query vector are determined using the vector index in the local non-volatile memory, and are used as the vector retrieval result, wherein the non-volatile memory is used to store the vector index of the external document and the text block corresponding to each vector under the vector index, and the text block is obtained by blocking the text content of the external document.
[0058] As an example, the Euclidean distance can be used to calculate the similarity distance of two vectors, and the smaller the distance, the more similar the semantic of the corresponding text vectors, which is not limited by the present disclosure.
[0059] According to the exemplary embodiments of the present disclosure, before step S102, a plane vector index of the external document can be created; the plane vector index is written to a predetermined buffer area of the local memory, wherein the predetermined buffer area is a region in the memory for storing the plane vector index of the external document; in response to the data amount in the predetermined buffer area reaching a preset threshold, the plane vector index in the predetermined buffer area is written to the non-volatile memory; on this basis, the first predetermined number of vectors with high similarity to the query vector are determined using the vector index in the local non-volatile memory, and are used as the vector retrieval result, which can include: using the vector index in the predetermined buffer area and the non-volatile memory, the first predetermined number of vectors with high similarity to the query vector are determined, and are used as the vector retrieval result.
[0060] By the embodiment, the vector index is stored in segments, that is, when a new vector index is written, it is first stored in a predetermined buffer of the local memory, and when the amount of data in the predetermined buffer reaches a preset threshold, the vector index in the predetermined buffer is written to the non-volatile memory, that is, the frequent file IO operation caused by directly writing to the non-volatile memory is avoided, and the problem that all vector indexes are stored in the memory, causing excessive consumption of the local memory, is also avoided.
[0061] Specifically, in order to facilitate subsequent vector retrieval, external documents can be introduced in advance, that is, the vector indexes of the external documents are constructed in advance, and after the vector indexes of the external documents are constructed, the vector index data generated needs to be saved. However, if all the vector index data of the external documents are placed in the memory, the memory will be excessively consumed; if all the vector index data of the external documents are directly written to the hard disk, frequent file IO operations will be caused. In order to avoid huge performance overhead, the present disclosure proposes a vector caching mechanism.
[0062] As an example, when new vector index data needs to be written, the new vector index data is first stored in a predetermined buffer. The predetermined buffer is a temporary cache area and is usually stored in the memory. When the amount of data in the predetermined buffer reaches a preset threshold, the vector index data in the predetermined buffer can be written to the local non-volatile memory.
[0063] It should be noted that the above-mentioned preset threshold can be set as needed. The above-mentioned non-volatile memory can be a hard disk or other forms of memory, and the present disclosure does not limit it.
[0064] As an example, when the above-mentioned vector caching mechanism is used for storage, subsequent vector retrieval needs to be performed in the predetermined buffer and the local non-volatile memory at the same time. For example, in vector retrieval, the vector indexes in the predetermined buffer and the non-volatile memory can be used to determine the first predetermined number of vectors with the highest similarity to the query vector, and the vectors are used as the vector retrieval result.
[0065] As an example, obtaining the text block corresponding to the vector retrieval result from the non-volatile memory can include: obtaining the text block corresponding to the vector retrieval result from the predetermined buffer and the non-volatile memory, that is, if the predetermined buffer saves not only vector index data, but also subsequent text blocks, the predetermined buffer also needs to be considered when the text blocks are obtained.
[0066] According to an example embodiment of the present disclosure, the writing of the plane vector index in the predetermined buffer to the non-volatile memory in response to the data amount in the predetermined buffer reaching the preset threshold can include: in response to the data amount in the predetermined buffer reaching the preset threshold and the number of vectors under the plane vector index in the predetermined buffer being greater than the third predetermined number, creating a non-plane vector index based on the plane vector index in the predetermined buffer; writing the non-plane vector index to the non-volatile memory and emptying the predetermined buffer.
[0067] Through the present embodiment, when the number of vectors under the vector index in the predetermined buffer is large, a non-plane vector index can be created based on the plane vector index in the predetermined buffer and written to the non-volatile memory in the form of the non-plane vector index, so as to avoid frequent IO operations caused by writing the plane vector index to the non-volatile memory in the form of the plane vector index in the large-scale vector data scenario, and the non-plane vector index can improve the query speed.
[0068] As an example, the present disclosure can optimize the update process of the vector index by dividing the vector index data into an incremental segment and a sealed segment. When new vector index data needs to be written, the new vector index data is first stored in the predetermined buffer. At this time, the vector index data in the predetermined buffer can be regarded as incremental segment data. When the data amount in the predetermined buffer reaches the preset threshold, a non-plane vector index can be created based on the plane vector index in the predetermined buffer, which is equivalent to sealing the plane vector index in the predetermined buffer. At this time, the data can be regarded as sealed segment data. Then, the created non-plane vector index is written to the local non-volatile memory.
[0069] As an example, the plane vector index can be a FlatIndex, and the non-plane vector index can be an inverted index, a product quantization index, etc. The specific type of non-plane vector index needs to be determined according to the number of vectors under the plane vector index, and the present disclosure does not limit this.
[0070] According to an example embodiment of the present disclosure, the determination of the first predetermined number of vectors with high similarity to the query vector based on the vector index in the predetermined buffer and the non-volatile memory and the use of the first predetermined number of vectors as the vector retrieval result can include: determining the similarity of each vector under the vector index in the predetermined buffer to the query vector based on the vector index in the predetermined buffer of the memory; determining the similarity of each vector under the vector index in the non-volatile memory to the query vector based on the vector index in the non-volatile memory; merging the vectors under the vector index in the predetermined buffer and the non-volatile memory and sorting the vectors in descending order of similarity; and determining the first predetermined number of vectors with high similarity as the vector retrieval result.
[0071] As an example, assuming that the first predetermined number is 10, the similarity of all vectors under the vector index in the predetermined buffer of the memory and the query vector can be calculated, the similarity of all vectors under the vector index in the non-volatile memory and the query vector can be calculated, and then the similarity corresponding to the predetermined buffer and the similarity corresponding to the non-volatile storage are comprehensively sorted, and the top 10 vectors are selected. The present disclosure does not make any limitation.
[0072] It should be noted that the above first predetermined number can be set as needed, and the present disclosure does not make any limitation.
[0073] According to the exemplary embodiments of the present disclosure, the above creating a flat vector index of the external document can include: in response to the external document being a pure text document, the text content of the external document is blocked in a sliding window manner to obtain a plurality of text blocks; in response to the external document being a structured document, the text content of the external document is blocked based on the hierarchical information of the external document to obtain a plurality of text blocks, wherein each text block contains the hierarchical information of all levels to which it belongs in the external document; each text block is vectorized respectively to obtain the vector of each text block; and the flat vector index is created based on the vector of each text block. Through this embodiment, a structured method is used for parsing, i.e. the text is blocked according to the hierarchical information in the document, and each block includes the hierarchical information of all levels to which it belongs in the document. These structural information can provide more information for the text blocks when blocking, so that the retrieval result is more accurate.
[0074] Specifically, in the index construction process of the existing RAG technology, the document parsing and blocking are usually directly divided into blocks according to a preset block size, or recursively divided according to punctuation marks. The disadvantage of this ordinary division method is that global information cannot be obtained, for example, if the semantic of the retrieval is related to the title of a paragraph, and the title information is contained in the first block, but the remaining blocks do not contain it, which leads to a decrease in retrieval accuracy. In order to solve this problem, the present disclosure considers that in various document formats, structured documents are the majority, such as docx, xslx, markdown, etc. Therefore, the present disclosure uses a structured method for parsing, i.e. the text is blocked according to the hierarchical information in the document, and each block includes the hierarchical information of all levels to which it belongs in the document, such as the multi-level title in docx and the table information in xslx table, etc. These structural information can provide more information for the text blocks when blocking, so that the retrieval result is more accurate.
[0075] As an example, assuming that the document in docx format is taken as an example, the document content contains a two-level title, which can be as follows:
[0076] title1 (one-level title)
[0077] title2 (Second-level heading)
[0078] Abcdefghijklmnopqrst... (Main text)
[0079] The block segmentation results obtained using ordinary segmentation methods are generally as follows:
[0080] Section 1: title1\ntitle2\nabcdefg...
[0081] Block 2: hijklmnopqrst...
[0082] The block-based results obtained after parsing using a structured method in this disclosure are as follows:
[0083] Section 1: title1\ntitle2\nabcdefg...
[0084] Block 2: title1\ntitle2\nhijklmnopqrst...
[0085] As can be seen from the above example, when searching with "title1", the segmentation results obtained by the ordinary segmentation method cannot retrieve segment 2, while the segmentation results obtained by this disclosure can retrieve segment 2.
[0086] As an example, when writing to an external document, the index creation interface can be called. In response to this call, the external document to be written is received, and its text content is extracted using a parser corresponding to the external document. Then, the text content is converted to Markdown format. Next, the converted text content is cleaned to obtain cleaned text content. After obtaining the cleaned text content, the text segmentation operation described in the previous example is performed.
[0087] To better understand the text segmentation process in this implementation, the following will combine... Figure 2 A systematic explanation of the text segmentation process is provided.
[0088] Figure 2 This demonstrates a flowchart of document parsing and text segmentation, such as... Figure 2 As shown, firstly, the document type is identified by the file extension, then the corresponding parser is called to extract the text content, and then the extracted text content is converted into a unified intermediate representation in Markdown format. Next, text cleanup is performed, such as removing invalid characters, and then intelligent chunking can be performed.
[0089] If the external document is a plain text document, an overlapping sliding window approach can be used for segmentation. First, a default window size and stride are set. The sliding window ensures semantic continuity. If the external document is a structured document, the system segments the text according to semantic boundaries and identifies heading levels. Contextual information is added to each text block, meaning each text block contains hierarchical information about all levels it belongs to within the external document. Therefore, the final generated text blocks maintain the semantic integrity of the original document while meeting the input requirements of the vectorized model, improving the accuracy of semantic retrieval.
[0090] To better understand the index creation process, the following will combine... Figure 3 The index creation process is explained systematically.
[0091] Figure 3 This demonstrates a vector index creation process, such as Figure 3 As shown, after the index creation interface is called, the document is first parsed and segmented, and the corresponding interface is called for vectorization. Then, vector data and metadata are stored separately. The generated metadata can be directly stored in a local database (such as SQL) using Structured Query Language (SQL). It should be noted that metadata can include the document's text data and metadata such as document name and document path. After the vector data is generated, a vector caching mechanism can be used for data storage. Specifically, a new vector index, i.e., a flat vector index, is created based on the vector data and stored in a predetermined buffer in memory. It is determined whether the data volume in the predetermined buffer is greater than a threshold. If the result is no, it continues to be cached in the predetermined buffer. If the result is yes, an index write-to-disk signal is triggered. After the index write-to-disk signal is triggered, metadata write-to-disk operations and vector index write-to-disk operations can be performed, that is, the vector index in the predetermined buffer is saved to a vector index file in non-volatile memory. Then, the result of index construction is returned to the index creation interface, which receives the processing result.
[0092] As an example, when metadata (i.e., non-vector data) is stored in a local database, the database table structure can be as follows:
[0093] Table 1 Collection of Database Tables
[0094]
[0095] Table 2 embedding_metadata
[0096]
[0097] Table 3 embedding_status table
[0098]
[0099] Table 4 index_segment table
[0100]
[0101] As an example, Figure 4 The relationship of three tables is shown as follows, Figure 4 As shown in Table 2 and Table 3 are constructed on the basis of Table 1, Table 2 shows the creation state of the vector index of the document, and Table 3 shows the information of the vector index.
[0102] According to an example embodiment of the present disclosure, a delete file list is received, wherein the delete file list includes an identification of at least one to-be-deleted document; an index creation state of the at least one to-be-deleted document is queried; for a to-be-deleted document whose index creation state is index creation success, a predetermined vector index is queried from the memory based on the identification of the to-be-deleted document; in response to the existence of the predetermined vector index in the memory, the predetermined vector index is deleted from the memory; in response to the non-existence of the predetermined vector index in the memory, the predetermined vector index is queried from the non-volatile memory, and a delete flag corresponding to the predetermined vector index is set to 1, wherein the predetermined vector index is a vector index of the to-be-deleted document; for a to-be-deleted document whose index creation state is in an index creation process, the index creation process of the to-be-deleted document is stopped; and for a to-be-deleted document whose index creation state is index creation failure, the to-be-deleted document is skipped.
[0103] Through the present embodiment, a delete flag bit (deleteBit) is maintained for each vector index, when deleting the vector index, physical deletion can be not performed, but the corresponding delete flag bit is set to 1, and in the subsequent vector retrieval process, these deleted vectors will be automatically skipped, so that the delete operation only needs to update one bit in the database, avoiding frequent disk IO operations and index reconstruction, improving the performance of the delete operation; and the index file does not need to be modified, maintaining the integrity of the index file, avoiding index fragmentation; and batch deletion and recovery operations are also supported, such as that the bit can be reset to recover the misdeletion, thereby ensuring the retrieval accuracy while significantly improving the efficiency of the delete operation and the overall stability of the system.
[0104] As an example, Figure 5 A vector index deletion process is shown as follows, Figure 5As shown, after the index deletion interface is called, a file list containing information of documents to be deleted is received in response to the index deletion interface being called, that is, the file list to be deleted is specified in the figure. The vector index deletion first needs to determine the current processing state of the document (i.e., the index creation state described above), and the vector index of the external document in the processing in progress (i.e., the index creation process described above) and the processing error (i.e., the index creation error described above) state does not need to be deleted, because both of them have not successfully created a vector index. For the external document in the index creation process, only the index creation process in progress needs to be stopped, such as adding the vector ID to the abort list, and for the external document with failed index creation, the external document can be skipped. For the external document with successful index creation, the vector ID is first queried through the document name passed in, and the vector index data on the predetermined buffer and the non-volatile memory is deleted through the vector ID, specifically, if the vector index data corresponding to the vector ID is located in the predetermined buffer, the vector index data can be directly deleted from the predetermined buffer, if not in the predetermined buffer, the vector index data is deleted from the non-volatile memory, and the deletion operation in the non-volatile memory can be to set the deletion flag bit to 1. Finally, the deletion result can be returned to the index deletion interface.
[0105] According to an example embodiment of the present disclosure, determining the similarity between each vector under the vector index in the non-volatile memory and the query vector based on the vector index in the non-volatile memory can include: constructing a bit set based on the deletion flag bit of the vector index in the non-volatile memory; and determining the similarity between each vector under the vector index with the deletion flag bit of 0 in the non-volatile memory and the query vector based on the bit set and the vector index in the non-volatile memory. Through this embodiment, when vector retrieval is performed, a bit set can be constructed based on the deletion flag bit, so that in the vector search process, the deleted vectors can be automatically skipped based on the bit set.
[0106] As an example, when vector retrieval is performed, the system can construct a bit set based on the deletion bit of all vector indexes (BitSet bit set), and because the positions of all deleted vector indexes are marked as 1, these deleted vectors can be automatically skipped in the search process based on the BitSet bit set.
[0107] It should be noted that the constructed BitSet bit set can be stored in the memory, and the present disclosure does not limit this.
[0108] Return Figure 1 In step 103, the text block corresponding to the vector retrieval result is obtained from the non-volatile memory.
[0109] In step 104, the text block corresponding to the vector retrieval result and the query question are segmented.
[0110] In step 105, a keyword index is created based on the word segmentation result of the text block corresponding to the vector retrieval result.
[0111] In step 106, keyword retrieval is performed based on the word segmentation result of the query question and the keyword index, and a second predetermined number of text blocks with the highest matching degree to the query question are obtained, wherein the second predetermined number of text blocks are used to assist the local large language model to generate an answer to the query question.
[0112] Specifically, the above-mentioned vector retrieval result is obtained by calculating the vector similarity, that is, based on the ranking of the semantic distance of the vector in the vector space generated from the text information and the query vector, the vectors ranked in the front are selected, but this way of obtaining the vector retrieval result is more dependent on the ability of the vectorization model, and if the model ability is poor, it will lead to reduced retrieval accuracy. Therefore, in order to solve this problem, the embodiment proposes a keyword reordering algorithm.
[0113] As an example, when vector retrieval is performed, a larger number of vectors are first obtained for backup, that is, 2topK (i.e. 2topK) vectors are obtained as the vector retrieval result. Then, according to the vector ID of the vector in the vector retrieval result, the corresponding source text information (i.e. the text block corresponding to the above-mentioned vector retrieval result) is obtained from the predetermined buffer and the non-volatile memory. Then, the query question and the source text information are segmented using a word segmentation algorithm, wherein the word segmentation result of the source text information is used to create a keyword index, and the word segmentation result of the query question is used to retrieve in the keyword index. The retrieval result can select topK text blocks, that is, the keyword retrieval result, which is the retrieval result of the entire vector retrieval process. Finally, the required number of results can be returned based on user demand, that is, the required amount of text blocks in topK results are selected as the retrieval result for the query question to assist the large language model to generate an answer to the query question.
[0114] It should be noted that the generated keyword index can be stored in the memory, and the present disclosure does not limit this.
[0115] In order to better understand the retrieval method of the present disclosure, the following will be combined with Figure 6 and Figure 7 to make a systematic description.
[0116] Figure 6 A vector retrieval process is shown, as shown in Figure 6 , the vector retrieval process is a multi-level and efficient semantic search system, which adopts a hybrid retrieval strategy combining vector similarity search and keyword reordering. The entire process is divided into five core stages of query preprocessing, vector search, result merging and sorting, metadata query, and keyword reordering.
[0117] First, a query request is received through a vector retrieval interface, which can contain a user query text (i.e., the query question described above) and a desired number of returned results (such as topK). Second, the user query text is vectorized. Third, vector search is performed based on the vector of the query question, specifically, searching in the vector index in the predetermined buffer (such as the cache in Figure 6 ) in memory and the non-volatile storage (such as the disk in Figure 6 ), the similarity can be calculated using the Euclidean distance, and the topK vectors with the highest similarity are selected; during the vector search process, the BitSet mechanism is used to filter the deleted vectors to ensure the validity of the retrieval results. Fourth, the cache retrieval results and the disk retrieval results are merged to obtain the vector retrieval results. Finally, the result ranking is optimized through a keyword reordering algorithm to provide more accurate semantic matching, specifically, the source text information of the vector retrieval results is obtained from the predetermined buffer (such as the cache in Figure 6 ) in memory and the non-volatile storage (such as the database in Figure 6 ), and the keyword reordering is performed based on the source text information.
[0118] Figure 7 A system architecture diagram of a local vector database is shown in Figure 7 , the local vector database exposes vector index creation interface, vector retrieval interface and index deletion interface as system services, i.e., the local vector database can provide vector index construction, deletion and retrieval functions to the outside through the interface service module. The data processing module implements document parsing, text blocking, text vectorization processing during vector index creation, and text vectorization processing and vector similarity calculation functions during vector retrieval. The data management module implements vector data and metadata management, such as vector index creation, deletion, metadata storage, deletion, etc. The vector file can contain cache vector index data (i.e., the vector index data of the predetermined buffer in the above embodiment) and the disked local vector file, which contains the vector index data that has been disked, and the metadata management directly operates the local database.
[0119] In summary, the related art has technical limitations in real-time performance, privacy protection, and cost control using a cloud vector database solution. For example, Milvus is a cloud-native, distributed vector database designed for massive vector approximate nearest neighbor search. As a cloud-native distributed vector database, Milvus has the advantages of supporting horizontal expansion, high availability, and billion-level vector millisecond-level retrieval, and is suitable for large-scale online services. However, Milvus has the disadvantages of relying on components such as etcd, Pulsar, and object storage for deployment, and has high resource consumption and complex operation and maintenance in local development or edge scenarios. The local vector database solution of the present embodiment can be started with one key, has zero dependencies, and has low resource consumption, and is suitable for single-machine deployment, which can overcome the above-mentioned disadvantages of the cloud vector database solution.
[0120] Specifically, the architecture design of the efficient and lightweight local vector database proposed in the present embodiment aims to solve the technical limitations of existing cloud vector database solutions in real-time performance, privacy protection, and cost control. Specifically, by using a local storage system to implement the vector storage and retrieval solution, the network dependence of the cloud solution is avoided, and the influence of network delay on real-time performance is eliminated, significantly improving real-time performance. Moreover, the vector data storage and retrieval process of the present embodiment is completely performed locally, avoiding the security risks of transmitting sensitive data to the cloud, so that the personal data and sensitive information of the user can be kept completely private, reducing the risk of data leakage or privacy infringement, and meeting strict data privacy protection requirements. Therefore, the present embodiment strengthens privacy protection and ensures data security, and is particularly suitable for medical, financial, and other high-privacy fields. In addition, the localized solution of the present embodiment also avoids the storage fees of cloud services and the high cost of charging by access volume, so that the user does not need to pay high fees for frequent database access, while reducing the dependence on external services, effectively reducing operation and maintenance costs and improving resource utilization, and is particularly suitable for budget-limited or cost-sensitive enterprises and individuals, enabling efficient vector data management and retrieval under limited resources.
[0121] Figure 8 is a block diagram of a retrieval device according to an exemplary embodiment. Referring to Figure 8 The device includes a first acquisition unit 80, a first retrieval unit 82, a second acquisition unit 84, a word segmentation unit 86, a creation unit 88, and a second retrieval unit 810.
[0122] The first obtaining unit 80 is configured to obtain a query vector of a query question; the first retrieving unit 82 is configured to determine a first predetermined number of vectors with high similarity to the query vector by using the vector index in the local non-volatile memory, and take the first predetermined number of vectors as a vector retrieval result, wherein the non-volatile memory is used to store the vector index of the external document and a text block corresponding to each vector under the vector index, and the text block is obtained by blocking the text content of the external document; the second obtaining unit 84 is configured to obtain the text block corresponding to the vector retrieval result from the non-volatile memory; the word segmentation unit 86 is configured to perform word segmentation on the text block corresponding to the vector retrieval result and the query question; the creating unit 88 is configured to create a keyword index based on the word segmentation result of the text block corresponding to the vector retrieval result; and the second retrieving unit 810 is configured to perform keyword retrieval based on the word segmentation result of the query question and the keyword index, to obtain a second predetermined number of text blocks with high matching degree to the query question, wherein the second predetermined number of text blocks are used to assist the local large language model to generate an answer to the query question.
[0123] According to an example embodiment of the present disclosure, the first retrieving unit 82 is further configured to, before determining the first predetermined number of vectors with high similarity to the query vector by using the vector index in the local non-volatile memory and taking the first predetermined number of vectors as the vector retrieval result, create a plane vector index of the external document; write the plane vector index to a predetermined buffer area of the local memory, wherein the predetermined buffer area is an area in the memory used to store the plane vector index of the external document; in response to the data amount in the predetermined buffer area reaching a preset threshold, write the plane vector index in the predetermined buffer area to the non-volatile memory; and determine the first predetermined number of vectors with high similarity to the query vector by using the predetermined buffer area and the vector index in the non-volatile memory, and take the first predetermined number of vectors as the vector retrieval result.
[0124] According to an example embodiment of the present disclosure, the first retrieving unit 82 is further configured to, in response to the data amount in the predetermined buffer area reaching the preset threshold and the number of vectors under the plane vector index in the predetermined buffer area being greater than a third predetermined number, create a non-plane vector index based on the plane vector index in the predetermined buffer area; write the non-plane vector index to the non-volatile memory and empty the predetermined buffer area.
[0125] According to an example embodiment of the present disclosure, the first retrieval unit 82 is further configured to, in response to the external document being a pure text document, divide the text content of the external document into a plurality of text blocks in a sliding window manner; in response to the external document being a structured document, divide the text content of the external document into a plurality of text blocks based on hierarchical information of the external document, wherein each text block contains hierarchical information of all levels to which the text block belongs in the external document; vectorize each text block respectively to obtain a vector of each text block; and create a flat vector index based on the vector of each text block.
[0126] According to an example embodiment of the present disclosure, the apparatus further includes a deletion unit configured to receive a deletion file list, wherein the deletion file list includes an identifier of at least one to-be-deleted document; query an index creation state of the at least one to-be-deleted document; for a to-be-deleted document with an index creation state of index creation success, query a predetermined vector index of the to-be-deleted document from the memory based on the identifier of the to-be-deleted document; in response to the predetermined vector index existing in the memory, delete the predetermined vector index from the memory; in response to the predetermined vector index not existing in the memory, query the predetermined vector index from the non-volatile memory, and set a deletion flag corresponding to the predetermined vector index to 1, wherein the predetermined vector index is a vector index of the to-be-deleted document; for a to-be-deleted document with an index creation state of being in an index creation process, stop the index creation process of the to-be-deleted document; and for a to-be-deleted document with an index creation state of index creation failure, skip the to-be-deleted document.
[0127] According to an example embodiment of the present disclosure, the first retrieval unit 82 is further configured to determine the similarity between each vector under a vector index in a predetermined buffer area of the memory and the query vector by using the vector index in the predetermined buffer area of the memory; determine the similarity between each vector under a vector index in the non-volatile memory and the query vector by using the vector index in the non-volatile memory; merge the vectors under the vector indexes in the predetermined buffer area and the non-volatile memory and sort the vectors in descending order of the similarity; and take a first predetermined number of vectors with higher similarity as the vector retrieval result.
[0128] According to an example embodiment of the present disclosure, the first retrieval unit 82 is further configured to construct a bit map based on a deletion flag bit of a vector index in the non-volatile memory; and determine the similarity between each vector under a vector index with the deletion flag bit being 0 in the non-volatile memory and the query vector by using the bit map and the vector index in the non-volatile memory.
[0129] According to an example embodiment of the present disclosure, an electronic device can be provided. Figure 9is a block diagram of an electronic device 900 according to an embodiment of the present disclosure, which includes at least one memory 901 and at least one processor 902, and the at least one memory has a set of computer-executable instructions stored therein, and when the set of computer-executable instructions is executed by the at least one processor, the set of computer-executable instructions performs the retrieval method according to an embodiment of the present disclosure.
[0130] As an example, the electronic device 900 can be a PC computer, a tablet device, a personal digital assistant, a smart phone, or other device capable of executing the above-mentioned set of instructions. Here, the electronic device 900 is not necessarily a single electronic device, but can be a collection of any device or circuit capable of executing the above-mentioned instructions (or set of instructions) individually or jointly. The electronic device 900 can also be part of an integrated control system or a system manager, or can be configured as a portable electronic device that interfaces with a local or remote (e.g., via wireless transmission) device.
[0131] In the electronic device 900, the processor 902 can include a central processing unit (CPU), a graphics processing unit (GPU), a programmable logic device, a dedicated processor system, a microcontroller, or a microprocessor. As an example and not a limitation, the processor 902 can also include an analog processor, a digital processor, a microprocessor, a multi-core processor, a processor array, a network processor, etc.
[0132] The processor 902 can execute instructions or codes stored in the memory, and the memory 901 can also store data. The instructions and data can also be sent and received via a network through a network interface device, which can use any known transmission protocol.
[0133] The memory 901 can be integrated with the processor 902, for example, arranging RAM or flash memory within an integrated circuit microprocessor, etc. In addition, the memory 901 can include a separate device, such as an external disk drive, a storage array, or other storage device that can be used by any database system. The memory 901 and the processor 902 can be operatively coupled or can communicate with each other, for example, through an I / O port, a network connection, etc., so that the processor 902 can read files stored in the memory 901.
[0134] In addition, the electronic device 900 can also include a video display (such as a liquid crystal display) and a user interaction interface (such as a keyboard, a mouse, a touch input device, etc.). All components of the electronic device can be connected to each other via a bus and / or a network.
[0135] According to embodiments of the present disclosure, a computer-readable storage medium can also be provided, wherein when instructions in the computer-readable storage medium are run by at least one processor, the at least one processor is caused to perform the retrieval method of embodiments of the present disclosure. Examples of the computer-readable storage medium herein include read-only memory (ROM), programmable read-only memory (PROM), electrically programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), random access memory (RAM), dynamic random access memory (DRAM), static random access memory (SRAM), flash memory, nonvolatile memory, CD-ROM, CD-R, CD+R, CD-RW, CD+RW, DVD-ROM, DVD-R, DVD+R, DVD-RW, DVD+RW, DVD-RAM, BD-ROM, BD-R, BD-R LTH, BD-RE, Blu-ray or optical disk memory, a hard disk drive (HDD), a solid state disk (SSD), a card-type memory (such as a multimedia card, a secure digital (SD) card, or an extreme digital (XD) card), a magnetic tape, a floppy disk, a magneto-optical data storage device, an optical data storage device, a hard disk, a solid state disk, and any other device configured to store a computer program in a non-transitory manner and provide the computer program to a processor or computer so that the processor or computer can execute the computer program, as well as any associated data, data files, and data structures. The computer program in the computer-readable storage medium described above can be run in an environment deployed in a computer device such as a client, a host, a proxy device, a server, etc., and in addition, in one example, the computer program, as well as any associated data, data files, and data structures, is distributed over a networked computer system so that the computer program, as well as any associated data, data files, and data structures, is stored, accessed, and executed in a distributed manner by one or more processors or computers.
[0136] According to embodiments of the present disclosure, a computer program product is provided, including computer instructions, which, when executed by a processor, implement the retrieval method of embodiments of the present disclosure.
[0137] Other embodiments of the present disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the aspects disclosed herein. The present disclosure is intended to cover any variations, uses, or adaptations of the present disclosure following, in general, the principles of the present disclosure and including such features that are evident to those skilled in the art to which the present disclosure pertains. The specification and examples are to be regarded as exemplary only, with the true scope and spirit of the present disclosure being indicated by the appended claims.
[0138] It should be understood that the present disclosure is not limited to the precise construction that has been described above and shown in the accompanying drawings, and that various modifications and changes can be made by those skilled in the art without departing from the scope of the present disclosure. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A retrieval method, characterized in that, include: Obtain the query vector for the query question; Using the vector index in the local non-volatile memory, a first predetermined number of vectors with the highest similarity to the query vector are determined as vector retrieval results. The non-volatile memory is used to store the vector index of the external document and the text block corresponding to each vector under the vector index. The text block is obtained by dividing the text content of the external document into blocks. Retrieve the text block corresponding to the vector retrieval result from the non-volatile memory; The text blocks corresponding to the vector retrieval results and the query question are segmented into words; A keyword index is created based on the word segmentation results of the text blocks corresponding to the vector retrieval results; Based on the word segmentation results of the query question and the keyword index, keyword retrieval is performed to obtain a second predetermined number of text blocks with the highest matching degree to the query question. The second predetermined number of text blocks are used to assist the local large language model in generating an answer to the query question. Before determining a first predetermined number of vectors with high similarity to the query vector as vector retrieval results using the vector index in local non-volatile memory, the process further includes: Create a planar vector index for the external document; The planar vector index is written to a predetermined buffer in local memory, wherein the predetermined buffer is a region in the memory used to store the planar vector index of the external document; In response to the data volume in the predetermined buffer reaching a preset threshold, the plane vector index in the predetermined buffer is written into the non-volatile memory; The step of using the vector index in the local non-volatile memory to determine the first predetermined number of vectors with the highest similarity to the query vector as vector retrieval results includes: using the predetermined buffer and the vector index in the non-volatile memory to determine the first predetermined number of vectors with the highest similarity to the query vector as vector retrieval results. The retrieval method further includes: receiving a list of deleted files, wherein the list of deleted files includes the identifier of at least one document to be deleted; querying the index creation status of the at least one document to be deleted; for a document to be deleted whose index creation status is successful, querying a predetermined vector index from memory based on the identifier of the document to be deleted; in response to the existence of the predetermined vector index in memory, deleting the predetermined vector index from memory; in response to the absence of the predetermined vector index in memory, querying the predetermined vector index from non-volatile memory, setting the deletion flag corresponding to the predetermined vector index to 1, wherein the predetermined vector index is the vector index of the document to be deleted; for a document to be deleted whose index creation status is in the index creation process, stopping the index creation process of the document to be deleted; and skipping a document to be deleted whose index creation status is failed.
2. The retrieval method as described in claim 1, characterized in that, The step of writing the plane vector index in the predetermined buffer to the non-volatile memory in response to the data volume in the predetermined buffer reaching a preset threshold includes: In response to the data volume in the predetermined buffer reaching a preset threshold and the number of vectors under the planar vector index in the predetermined buffer being greater than a third predetermined number, a non-planar vector index is created based on the planar vector index in the predetermined buffer; Write the non-planar vector index into the non-volatile memory and clear the predetermined buffer.
3. The retrieval method as described in claim 1, characterized in that, Creating the planar vector index of the external document includes: In response to the fact that the external document is a plain text document, the text content of the external document is divided into blocks using a sliding window method to obtain multiple text blocks; In response to the fact that the external document is a structured document, the text content of the external document is divided into blocks based on the hierarchical information of the external document to obtain multiple text blocks, wherein each text block contains hierarchical information of all levels to which it belongs in the external document; Vectorize each text block separately to obtain the vector of each text block; The planar vector index is created based on the vector of each text block.
4. The retrieval method as described in claim 1, characterized in that, The step of using the predetermined buffer and the vector index in the non-volatile memory to determine a first predetermined number of vectors with high similarity to the query vector as vector retrieval results includes: Using the vector indices in the predetermined buffer of the memory, determine the similarity between each vector under the vector index in the predetermined buffer and the query vector; Using the vector index in the non-volatile memory, determine the similarity between each vector under the vector index in the non-volatile memory and the query vector; The vectors under the vector indices in the predetermined buffer and the non-volatile memory are merged and sorted in descending order of similarity. The first predetermined number of vectors with the highest similarity are determined as the vector retrieval results.
5. The retrieval method as described in claim 4, characterized in that, The step of determining the similarity between each vector under the vector index in the non-volatile memory and the query vector, using the vector index in the non-volatile memory, includes: A bitmap is constructed based on the deletion flag bits of the vector index in the non-volatile memory; Using the bitmap and the vector indexes in the non-volatile memory, the similarity between each vector under the vector index with the marker bit set to 0 in the non-volatile memory and the query vector is determined.
6. A retrieval device, characterized in that, include: The first acquisition unit is configured to acquire the query vector of the query question; The first retrieval unit is configured to use a vector index in a local non-volatile memory to determine a first predetermined number of vectors with the highest similarity to the query vector as vector retrieval results. The non-volatile memory is used to store the vector index of an external document and the text block corresponding to each vector under the vector index. The text block is obtained by dividing the text content of the external document into blocks. The second acquisition unit is configured to acquire the text block corresponding to the vector retrieval result from the non-volatile memory; The word segmentation unit is configured to segment the text block corresponding to the vector retrieval result and the query question into words. The creation unit is configured to create a keyword index based on the word segmentation results of the text blocks corresponding to the vector retrieval results; The second retrieval unit is configured to perform keyword retrieval based on the word segmentation results of the query question and the keyword index, and obtain a second predetermined number of text blocks with the highest matching degree to the query question. The second predetermined number of text blocks are used to assist the local large language model in generating an answer to the query question. The first retrieval unit is further configured to: create a planar vector index of the external document before determining a first predetermined number of vectors with high similarity to the query vector as vector retrieval results using a vector index in local non-volatile memory; write the planar vector index into a predetermined buffer in local memory, wherein the predetermined buffer is a region in the memory used to store the planar vector index of the external document; and write the planar vector index in the predetermined buffer into the non-volatile memory in response to the data volume in the predetermined buffer reaching a preset threshold; wherein determining a first predetermined number of vectors with high similarity to the query vector as vector retrieval results using a vector index in local non-volatile memory includes: determining a first predetermined number of vectors with high similarity to the query vector as vector retrieval results using the predetermined buffer and the vector index in the non-volatile memory. The retrieval device further includes a deletion unit configured to receive a list of deleted files, wherein the list of deleted files includes an identifier of at least one document to be deleted; query the index creation status of the at least one document to be deleted; for a document to be deleted whose index creation status is successful, query a predetermined vector index from the memory based on the identifier of the document to be deleted; in response to the existence of the predetermined vector index in the memory, delete the predetermined vector index from the memory; in response to the absence of the predetermined vector index in the memory, query the predetermined vector index from the non-volatile memory and set the deletion flag corresponding to the predetermined vector index to 1, wherein the predetermined vector index is the vector index of the document to be deleted; for a document to be deleted whose index creation status is in the index creation process, stop the index creation process of the document to be deleted; for a document to be deleted whose index creation status is failed, skip the document to be deleted.
7. An electronic device, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the retrieval method as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, When the instructions in the computer-readable storage medium are executed by at least one processor, the at least one processor causes the processor to perform the retrieval method as described in any one of claims 1 to 5.
9. A computer program product comprising computer instructions, characterized in that, When the computer instructions are executed by the processor, they implement the retrieval method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Cloud storage based power full text retrieval method and system
CN102156711A
Multi-document intelligent question and answer method and system based on large language model
CN118394897A