RAG storage and retrieval method and device based on graph database

By using RAG method and semantic vector model in the graph database, combined with the heat coefficient, the accuracy and consistency problems of large language models when generating text are solved, efficient and accurate document retrieval and information generation are achieved, and the existing technology is solved inaccuracy and unreliability of information retrieval.

CN118939782AActive Publication Date: 2024-11-12ZHEJIANG GONGSHANG UNIVERSITY +1

Patent Information

Application Number
CN202411426810.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-14
Publication Date
2024-11-12
Estimated Expiration
2044-10-14

AI Technical Summary

Technical Problem

Large language models are prone to "illusion" and "nonsense" problems when generating text, especially when dealing with text information of complex hierarchical relationships, which leads to inaccuracy of information retrieval and Unreliability.

Method used

Using the RAG (Retrieve-And-Generate) storage and retrieval method based on graph database, the multi-level node construction and structured storage can be achieved efficient and accurate retrieval of documents, and combined with semantic vector model and heat coefficient to improve the reliability of information generation. Sex and accuracy.

Benefits of technology

It effectively overcomes the "illusion" problem of large language models when dealing with complex text information, significantly improves the accuracy and relevance of search results, and provides users with more reliable and practical intelligent information services.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118939782A_ABST
    Figure CN118939782A_ABST
Patent Text Reader

Abstract

The invention discloses an RAG storage and retrieval method and device based on a graph database, and relates to the technical field of intelligent information retrieval and storage. The method comprises the following steps: firstly, collecting various document data, extracting full-text abstracts and keywords through a large language model (LLM), converting the full-text abstracts and keywords into vectors by using a vectorization model, and storing the vectors into a graph database; meanwhile, a multi-level structured storage relationship is established by utilizing a popularity coefficient, a chapter directory and segmented contents of the document. In the retrieval process, keywords, file names, chapters and segment contents related to user questions are sequentially obtained through multi-level matching, and final input for LLM processing is generated through integration. The method can effectively improve the structured degree and retrieval efficiency of document storage, and is widely applicable to an intelligent question-answering system and a knowledge management system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of natural language processing, and in particular relates to a RAG storage and retrieval method and device based on a graph database. Background Art

[0002] Large language models (LLMs) have made significant progress in the field of natural language processing in recent years. With their powerful language generation and understanding capabilities, they are widely used in machine translation, dialogue systems, text generation, and information retrieval. However, despite LLM's excellent performance in processing unstructured data, it also has some inherent problems when generating content, such as "hallucinations" and "nonsense". Specifically, when generating text, the model may generate non-existent facts out of thin air or confuse known information, resulting in inaccurate and unreliable results.

[0003] The root of these problems is that LLMs rely on a large amount of unstructured text data for training, and during the generation process, they cannot verify the generated content through logical reasoning or structured data. Especially when it needs to process text information with complex hierarchical relationships, LLMs often find it difficult to ensure the accuracy and consistency of the generated content. This poses a great challenge to many application scenarios that require high-precision information retrieval, such as legal, medical, and scientific research literature.

[0004] In order to solve the above problems, the present invention proposes a RAG (Retrieve-And-Generate) retrieval method based on a graph database. Through the graph database, hierarchical and structured storage of complex text data can be realized, thereby forming effective management and retrieval of multi-level data such as keywords, file names, chapter contents, paragraph contents, etc. On this basis, through the method of combining retrieval and generation, the reliability and accuracy of information generation can be significantly improved, avoiding the illusion and nonsense problems of LLM in the data generation process. Summary of the invention

[0005] The purpose of the present invention is to address the deficiencies of the prior art and provide a RAG (Retrieve-And-Generate) storage and retrieval method and device based on a graph database, aiming to solve the "hallucination" problem existing in the existing large language model when generating text, and the defect of low efficiency of traditional databases in complex document retrieval. The present invention realizes efficient and accurate retrieval of documents through multi-level node construction and structured storage of the graph database, and provides a more stable and accurate input basis for the large language model.

[0006] The object of the present invention is achieved through the following technical solutions: In the first aspect, the present invention provides a RAG storage and retrieval method based on a graph database, including two steps of storage and retrieval:

[0007] The storage step includes extracting the full text summary and keywords of the document data, as well as the chapter directory and performing segmentation processing, and setting the heat coefficient of the document, and storing it in the graph database; wherein the keywords are associated with the file name, the file name is associated with the full text summary, the chapter directory and the heat coefficient, and the chapter directory is associated with the segmented content, for subsequent retrieval process;

[0008] The retrieval step includes rewriting the user's question and matching it with keywords to obtain the associated file name, calculating the file similarity based on the file name, full-text abstract and heat coefficient, screening the files that meet the requirements, and then obtaining the chapter directory and segmented content that match the user's question, and generating the final answer based on the large language model and returning it to the user.

[0009] Furthermore, according to the content attributes of all documents, a keyword library is preset: K i =[k0,k1, k2,… k n ],k n represents the nth keyword; and uses the semantic vector model for each keyword to convert the keyword into a vector: V k =[v0,v1,v2,… v n ],v n Represents the nth keyword vector; the full text summary of the document is also converted into a vector using the semantic vector model: V f ; For each file, the keyword vector v i With Abstract Vector V f Calculate the cosine similarity S i , sort the cosine similarity from high to low, retain the keywords with similarity greater than the threshold, and take the top 3 as the keywords of the document.

[0010] Furthermore, the heat coefficient of a document refers to the heat value of the number of questions in the document with answers to all questions asked by all users within a period of time, Num hit Num is the number of questions in the document whose answers are asked by users within a period of time. total is the number of all questions asked by users in a period of time. The heat coefficient H(f) of the document is obtained as follows. The higher the heat coefficient, the more concerned the user is about the content of the document and the more questions he asks, and vice versa.

[0011] (1)

[0012] (2)

[0013] Among them, tanh is a hyperbolic tangent function, which is used to normalize the heat value so that it ranges from 0 to 1. The heat coefficient makes more popular documents have higher priority in the retrieval results.

[0014] Furthermore, LLM is used to extract the chapter directory structure of the document to obtain the structural hierarchy of the document; according to the chapter directory structure of the document, each chapter content is segmented, and each chapter is cut into multiple segmented content chunks using LLM, and converted into vectors using a semantic vector model.

[0015] Furthermore, keywords, file names, full-text abstracts, chapters, and segmented contents in the graph database are converted into vectors using a semantic vector model and stored, and heat coefficients are stored using floating-point data.

[0016] Furthermore, in the retrieval step, the user question is converted into a vector using a semantic vector model and matched with each keyword in the keyword library. Keywords with a similarity greater than a threshold are retained as a candidate keyword set. The file names associated with the keywords are traversed, the file similarities are calculated, and the file names with a similarity greater than a threshold are retained as a file set. Based on each file in the file set, the similarity between the user question and the chapter is calculated to obtain the chapter with the highest similarity. The similarity between the user question and the segmented content is calculated, and the segmented content with a similarity greater than a threshold is retained as the final retrieved content.

[0017] Furthermore, the file similarity is calculated by the file name, full text summary, and heat coefficient. The vectorized user questions are respectively calculated with the vectorized file name and full text summary to obtain the final file similarity. The calculation formula is as follows:

[0018] (3)

[0019] (4)

[0020] Among them, S name is the similarity between the rewritten user question and the file name, S summary is the similarity between the rewritten user question and the full text summary, c0 and c1 are coefficients, ranging from 0 to 1, and c0+c1=1, and H is the heat coefficient.

[0021] In a second aspect, the present invention also provides a RAG storage and retrieval device based on a graph database, comprising a memory and one or more processors, wherein the memory stores executable code, and when the processor executes the executable code, the RAG storage and retrieval method based on a graph database is implemented.

[0022] In a third aspect, the present invention further provides a computer-readable storage medium having a program stored thereon, and when the program is executed by a processor, the RAG storage and retrieval method based on a graph database is implemented.

[0023] In a fourth aspect, the present invention further provides a computer program product, including a computer program, which, when executed by a processor, implements the RAG storage and retrieval method based on a graph database.

[0024] Beneficial effects of the present invention: The RAG retrieval method based on the graph database of the present invention can effectively overcome the "illusion" problem existing in the existing large language model when processing complex text information. By using the multi-level structured storage and retrieval technology of the graph database, combined with key technologies such as vectorization processing and heat coefficient, the retrieval results are more accurate and more relevant, thereby providing users with more reliable and practical intelligent information services. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0026] Figure 1 It is a data storage flow chart of the present invention.

[0027] Figure 2 It is a data retrieval flow chart of the present invention.

[0028] Figure 3 This is a schematic diagram of the graph database storage structure of the present invention.

[0029] Figure 4 It is a schematic diagram of the function of the heat coefficient calculation formula of the present invention.

[0030] Figure 5 It is a RAG storage and retrieval based on graph database. DETAILED DESCRIPTION

[0031] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described below in conjunction with the accompanying drawings and implementation examples. It should be understood that the specific implementation examples described herein are only used to explain the present invention and are not used to limit the present invention.

[0032] The present invention discloses a RAG (Retrieve-And-Generate) storage and retrieval method based on a graph database. In order to facilitate understanding and implementation, the key concepts involved in the present invention are first explained, and then the implementation method is described in detail.

[0033] Large Language Model (LLM): A large language model (LLM) is a model formed by training a large amount of natural language data, which can understand, generate and process text information. Typical large language models such as GPT (Generative Pre-trained Transformer), including ChatGPT, etc., can generate high-quality text summaries, answer questions and create content. In the present invention, the large language model is used to extract document summaries, generate directory structures and process text segmentation.

[0034] RAG (Retrieve-And-Generate): RAG is a technology that combines information retrieval and text generation, and can generate relevant text content based on retrieved documents. By combining the retrieved information with a large language model, the RAG method can generate more accurate answers when users ask questions. The present invention uses RAG technology to achieve efficient document information retrieval and generation.

[0035] Graph database: A graph database is a type of database specifically designed to process graph data structures, which can efficiently store and query nodes (entities) and their relationships (edges). The characteristics of a graph database are:

[0036] 1. Efficient processing of complex relationships: Suitable for processing data with multi-level relationships, such as the structure of document chapters, paragraphs, keywords, and the relationship between documents.

[0037] 2. Flexible query method: Through graph traversal, you can quickly query related nodes and their relationships.

[0038] In the present invention, the graph database is used to store and organize keywords, file names, abstracts, popularity coefficients, chapters and segmented contents.

[0039] Semantic vector model: A semantic vector model is a model that converts text or other data into vectors (usually points in a high-dimensional space). In text processing, vectorization can map semantically similar text to similar vectors. Cosine similarity is often used to calculate the similarity between two vectors. In the present invention, the semantic vector model is used for processing keywords, document summaries, and chapter contents to help achieve efficient similarity calculation and matching.

[0040] Full-text summary: A full-text summary is a brief summary of the document content, which can condense the main information of the document. The full-text summary generated by the large language model contains the core idea of ​​the document, which is convenient for subsequent keyword extraction and content retrieval.

[0041] Heat coefficient: Heat coefficient is used to measure the degree of user attention to a document over a period of time. The heat value of a document can be calculated by counting the content related to the document in the questions asked by users. Heat coefficient is used to optimize the sorting of search results so that the content that users are more concerned about is presented first.

[0042] Chunk: Chunk is the process of dividing long text or chapter content into smaller, semantically independent chunks. These chunks can more precisely match the user's query content and improve the accuracy of retrieval. In the present invention, Chunk is generated by a large language model and stored and retrieved through a semantic vector model.

[0043] like Figure 1 As shown, this embodiment provides a RAG storage method based on a graph database, comprising the following steps:

[0044] S1: Document Data Collection

[0045] Collect different types of document data and support multiple formats (such as Word, PDF). The integrity and diversity of document data are the basis of the retrieval method of the present invention. In practical applications, data collection can be performed by file system scanning, batch import or automatic crawling.

[0046] S2: Document summary extraction

[0047] Generate a full-text summary of a document using a large language model. The core of summary generation is to extract the main content of the document and form a highly summarized text to ensure comprehensive coverage and accurate description of the content, which is convenient for subsequent keyword extraction and information retrieval. Summary generation can be achieved by calling the LLM model through the API, for example, using the API of Tongyi Qianwen to generate a summary output of a document.

[0048] S3: Keyword Extraction

[0049] Extract keywords from the full text summary of the document. First, build a preset keyword library: K i =[k0,k1, k2,…k n ],k n represents the nth keyword; and uses a semantic vector model (such as BGE-Large) to represent the keyword V k and full text abstract V f Convert to vector: V k =[v0,v1, v2,… v n ],vn represents the nth keyword vector. By calculating the cosine similarity S between the summary vector and the keyword vector i , sort the cosine similarity from high to low, and filter out the most relevant keywords with similarity greater than the threshold. Keyword extraction is achieved by sorting and selecting the top 3 keywords, which are stored as document labels in the graph database.

[0050] S4: Heat coefficient setting

[0051] The popularity of a document is determined by calculating the ratio of the number of query results and the number of questions associated with the document within a specific time period. The higher the heat coefficient, the higher the user's interest in the document. The heat coefficient diagram is shown in the figure below: Figure 4 The document's heat coefficient reflects the user's attention to a specific document, and is calculated as follows:

[0052] S41: Statistics on the association between user questions and documents: In a specific time period, count the number of questions related to a document content in the answers to the questions asked by users (called Num hit ), and count the total number of questions asked by all users during this time period (called Num total ).

[0053] S42: Heat value calculation: According to Num hit and Num total Calculate the document's heat value f:

[0054]

[0055] S43: Heat coefficient calculation: Calculate the heat coefficient H of the document using the following formula:

[0056]

[0057] Among them, tanh is a hyperbolic tangent function, which is used to normalize the heat value so that it ranges from 0 to 1. The calculation of the heat coefficient makes more popular documents have higher priority in the retrieval results.

[0058] S5: Extracting chapter directory structure

[0059] The directory and chapter structure are extracted from the document through a large language model. In actual implementation, LLM is used to parse the directory information of the document (such as chapter titles and hierarchical structure) and generate the corresponding tree structure. The output of this step is a hierarchical directory structure diagram of the document, which is convenient for subsequent chapter content analysis and retrieval.

[0060] S6: Chapter segmentation

[0061] According to the chapter directory structure extracted from S5, each chapter content of the document is segmented. The specific operations are as follows:

[0062] S61: Chapter content segmentation: Use the large language model to semantically segment the content of each chapter and generate multiple segmented content chunks. These chunks are semantically independent text segments, which are convenient for subsequent fine-grained retrieval.

[0063] S62: Chunk vectorization: Use the semantic vector model to convert each chunk into a vector and store it in the graph database. The vectorized chunks can be efficiently matched by similarity when users search for them.

[0064] Specifically, Figure 3 As shown, the construction and use of the graph database is the key to the present invention. The graph database is a data structure with nodes (entities) and edges (relationships) as the core. In the present invention, a multi-layer node storage method is designed to construct a graph database through multi-layer nodes. The top layer is the keyword, followed by the file name, full-text abstract, popularity coefficient, chapter structure, and finally the segmented content. A clear hierarchical relationship is formed between the nodes, making the storage and retrieval of document information more efficient and accurate. The nodes in the graph database and their hierarchical structure are as follows:

[0065] The relationships in a graph database describe the associations between entities. Each relationship represents a hierarchical link between entities. The entity relationships included in this example include:

[0066] HAS_FILES: The relationship between keywords and file names, indicating that a file name is associated with one or more keywords, and a keyword may be associated with multiple file names.

[0067] HAS_SUMMARY: The relationship between the file name and the full-text summary, indicating that a certain file has a corresponding full-text summary.

[0068] HAS_SECTION: The relationship between the file name and the chapter directory, indicating that a file contains one or more chapters.

[0069] HAS_HEAT: The relationship between the file name and the heat coefficient, indicating that a certain file has a corresponding heat coefficient.

[0070] HAS_PARAGRAPH: The relationship between the chapter directory and the segmented content, indicating that a chapter is further divided into multiple paragraphs.

[0071] All text data in the graph database, including keywords, file names, full-text abstracts, chapters, paragraphs, etc., are stored after vectorization processing, and the heat coefficient is stored as floating-point data. The graph database used can be Neo4j, etc. Through this structured storage method, the present invention realizes effective management and efficient retrieval of large-scale text data.

[0072] The present invention not only performs structured processing on data storage, but also optimizes the retrieval process so that the retrieval results are more in line with the actual needs of users. This embodiment provides a RAG retrieval method based on a graph database, such as Figure 2 As shown, the following steps are included:

[0073] S1: Keyword search.

[0074] After receiving the user's question, the question is first rewritten to eliminate ambiguity in the original question, optimize the question into a format that the system can better understand, and improve the accuracy of relevant retrieval results. This step is to improve the accuracy of the retrieval, ensure that the statement of the question can fully capture the user's intention, and better match the keywords and content in the document. In the retrieval system, the questions asked by users usually lead to deviations in retrieval results due to different expressions. Natural language questions may contain grammatical errors, ambiguity, redundant information and other problems, which will affect the system's understanding of user intent, thereby affecting the accuracy and relevance of the retrieval. Therefore, by rewriting user questions, standardizing or optimizing them into an easy-to-process form, it helps to improve the quality of retrieval results. The rewritten questions are more in line with the input requirements of the system, can more accurately match the document content, and improve the precision and recall of the system.

[0075] The rewritten user questions are converted into vectors using the semantic vector model, and the cosine similarity method is used to match them with all the keywords in the keyword library to calculate the similarity. The similarity is sorted from high to low, and a similarity threshold is set. Keywords with similarity higher than the threshold are selected to form a candidate keyword set.

[0076] Question rewriting can use the basic method of Query Rewrite, such as:

[0077] Synonym replacement: Replace the words in the user's question with words of the same or similar meaning to ensure the breadth of the query. For example, replace "get" with "get".

[0078] Contextual completion: Complete incomplete queries based on the context of the user input. For example, the user may have only entered a keyword "weather data", which can be rewritten to "how to obtain the weather data API".

[0079] Disambiguation: Dealing with polysemous words, determining their meaning in a specific context, and avoiding ambiguity. For example, "apple" can refer to a fruit or a technology company, and the appropriate meaning is selected based on the context when rewriting.

[0080] Simplify or clarify queries: Simplify complex or lengthy queries, remove unnecessary information, or clarify vague expressions. For example, change "I want to know how to do the project budget process" to "project budget process."

[0081] The following are examples of the Query Rewrite method:

[0082] 1) User’s original question:

[0083] “How to optimize code performance?”

[0084] Query Rewrite:

[0085] “What are some effective code performance optimization methods and best practices?”

[0086] Explanation: The original question was too broad. After rewriting, it is more specific and can guide the search results to focus on "effective methods" and "best practices".

[0087] 2) User’s original question:

[0088] “What should be written in the project application?”

[0089] Query Rewrite:

[0090] “What are the key parts of a standard project proposal structure?”

[0091] Explanation: By rewriting the questions to make it clear that they are about "standard structure" and "key parts", it helps to systematically return to the specific writing framework of the project application.

[0092] S2: File retrieval.

[0093] For each keyword in the candidate keyword set, traverse the file names associated with the keyword, calculate the file similarity based on the file name, full-text summary, and heat coefficient, and sort the similarities from high to low. Set a similarity threshold and retain the file names with similarity greater than the threshold as the file set. The calculation of file similarity takes into account the similarity between the user question and the file name, full-text summary, and the heat coefficient of the document to ensure that the retrieval results are both relevant and in line with the user's attention. As described in the following formula, first calculate the file similarity based on the file name. and full text abstract Calculate the similarity and get S temp, c0, c1 are coefficients, ranging from 0 to 1, and c0+c1=1, H is the heat coefficient formula. Then the final file similarity S is calculated according to the heat coefficient formula f .

[0094]

[0095]

[0096] S3: Chapter retrieval.

[0097] Based on each file in the final file collection, the similarity between the user's question and the file chapter is calculated. The system will retain the chapter with the highest similarity as the basis for subsequent retrieval. Chapter matching is an important step in the layer-by-layer in-depth retrieval, ensuring that the system can accurately locate the chapter content in the document that is most relevant to the user's question.

[0098] S4: Segment retrieval.

[0099] In the matched chapters, the similarity between the user's question and each segment content is further calculated. A similarity threshold is set, and the paragraph content with a similarity higher than the threshold is retained as the final retrieval result. This step ultimately determines whether the answer provided by the system to the user is specific and accurate enough.

[0100] S5: Integrated output

[0101] The question is integrated with the matched paragraph content to form a prompt word, which is provided as input to the large language model LLM. LLM generates the final answer based on these contents, generates the final text response or other processing results, and returns them to the user.

[0102] Corresponding to the aforementioned embodiment of a RAG storage and retrieval method based on a graph database, the present invention also provides an embodiment of a RAG storage and retrieval device based on a graph database.

[0103] See also Figure 5 An embodiment of the present invention provides a RAG storage and retrieval device based on a graph database, including a memory and one or more processors, wherein the memory stores executable code, and when the processor executes the executable code, it is used to implement a RAG storage and retrieval method based on a graph database in the above embodiment.

[0104] The embodiment of a RAG storage and retrieval device based on a graph database provided by the present invention can be applied to any device with data processing capabilities, and the device with data processing capabilities can be a device or apparatus such as a computer. The device embodiment can be implemented through software, or through hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor of any device with data processing capabilities in which it is located reading the corresponding computer program instructions in the non-volatile memory into the internal memory for execution. From a hardware perspective, if Figure 5 As shown, it is a hardware structure diagram of a RAG storage and retrieval device based on a graph database provided by the present invention, in which any device with data processing capability is located, except Figure 5 In addition to the processor, memory, network interface, and non-volatile memory shown, any device with data processing capabilities in which the apparatus in the embodiments is located may also include other hardware, generally based on the actual functions of the device with data processing capabilities, which will not be described in detail.

[0105] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.

[0106] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of the present invention. Ordinary technicians in this field can understand and implement it without paying creative work.

[0107] An embodiment of the present invention further provides a computer-readable storage medium on which a program is stored. When the program is executed by a processor, a RAG storage and retrieval method based on a graph database in the above embodiment is implemented.

[0108] The computer-readable storage medium may be an internal storage unit of any device with data processing capability described in any of the aforementioned embodiments, such as a hard disk or a memory. The computer-readable storage medium may also be an external storage device of any device with data processing capability, such as a plug-in hard disk, a smart media card (SMC), an SD card, a flash card, etc. equipped on the device. Furthermore, the computer-readable storage medium may also include both an internal storage unit and an external storage device of any device with data processing capability. The computer-readable storage medium is used to store the computer program and other programs and data required by any device with data processing capability, and may also be used to temporarily store data that has been output or is to be output.

[0109] The present invention also provides a computer program product, including a computer program, which, when executed by a processor, implements the RAG storage and retrieval method based on a graph database.

[0110] The above embodiments are used to illustrate the present invention rather than to limit the present invention. Any modification and change made to the present invention within the spirit of the present invention and the protection scope of the claims shall fall within the protection scope of the present invention.

Claims

1. A RAG storage and retrieval method based on a graph database, characterized in that: It includes two steps: storage and retrieval: The storage step includes extracting the full text summary and keywords of the document data, as well as the chapter directory and performing segmentation processing, and setting the heat coefficient of the document, and storing it in the graph database; wherein the keywords are associated with the file name, the file name is associated with the full text summary, the chapter directory and the heat coefficient, and the chapter directory is associated with the segmented content, for subsequent retrieval process; The retrieval step includes rewriting the user's question and matching it with keywords to obtain the associated file name, calculating the file similarity based on the file name, full-text abstract and heat coefficient, screening the files that meet the requirements, and then obtaining the chapter directory and segmented content that match the user's question, and generating the final answer based on the large language model and returning it to the user.

2. A RAG storage and retrieval method based on a graph database according to claim 1, characterized in that: Based on the content attributes of all documents, a keyword library is preset; and a semantic vector model is used for each keyword to convert the keyword and the full-text summary of the document into a vector; for each file, the cosine similarity between the keyword vector and the summary vector is calculated, and the cosine similarities are sorted from high to low, and keywords with similarity greater than the threshold are retained, and the Top 3 are taken as the keywords of the document.

3. A RAG storage and retrieval method based on a graph database according to claim 1, characterized in that: The heat coefficient of a document refers to the heat value of the number of questions in the document with answers to all questions asked by all users within a period of time, Num hit Num is the number of questions in the document whose answers are asked by users within a period of time. total is the number of all questions asked by users in a period of time. The heat coefficient H(f) of the document is obtained as follows. The higher the heat coefficient, the more concerned the user is about the content of the document and the more questions he asks, and vice versa. (1) (2) Among them, tanh is a hyperbolic tangent function, which is used to normalize the heat value so that it ranges from 0 to 1. The heat coefficient makes more popular documents have higher priority in the retrieval results.

4. The RAG storage and retrieval method based on a graph database according to claim 1, characterized in that: Use LLM to extract the chapter directory structure of the document to obtain the structural hierarchy of the document; according to the chapter directory structure of the document, segment the content of each chapter, use LLM to cut each chapter into multiple segmented content chunks, and use the semantic vector model to convert them into vectors.

5. The RAG storage and retrieval method based on a graph database according to claim 1 is characterized in that: Keywords, file names, full-text summaries, chapters, and segmented contents in the graph database are converted into vectors using a semantic vector model and stored, and heat coefficients are stored using floating-point data.

6. A RAG storage and retrieval method based on a graph database according to claim 1, characterized in that: In the retrieval step, the user question is converted into a vector using a semantic vector model and matched with each keyword in the keyword library. Keywords with similarity greater than a threshold are retained as a candidate keyword set. The file names associated with the keywords are traversed, the file similarity is calculated, and the file names with similarity greater than a threshold are retained as a file set. Based on each file in the file set, the similarity between the user question and the chapter is calculated to obtain the chapter with the highest similarity. The similarity between the user question and the segmented content is calculated, and the segmented content with a similarity greater than a threshold is retained as the final retrieved content.

7. The RAG storage and retrieval method based on a graph database according to claim 1, characterized in that: The file similarity is calculated by the file name, full text summary, and heat coefficient. The vectorized user questions are respectively calculated with the vectorized file name and full text summary to obtain the final file similarity. The calculation formula is as follows: (3) (4) Among them, S name is the similarity between the rewritten user question and the file name, S summary is the similarity between the rewritten user question and the full text summary, c0 and c1 are coefficients, ranging from 0 to 1, and c0+c1=1, and H is the heat coefficient.

8. A RAG storage and retrieval device based on a graph database, comprising a memory and one or more processors, wherein the memory stores executable code, characterized in that: When the processor executes the executable code, a RAG storage and retrieval method based on a graph database as described in any one of claims 1 to 7 is implemented.

9. A computer-readable storage medium having a program stored thereon, characterized in that: When the program is executed by a processor, a RAG storage and retrieval method based on a graph database as described in any one of claims 1 to 7 is implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, a RAG storage and retrieval method based on a graph database as described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Question and answer method, computing equipment and storage medium

    CN112417126A

  • Large language model feedback information generation method and device, electronic equipment and medium

    CN118069815A

  • RAG retrieval optimization method and system based on title enhancement and intention recognition

    CN118467681A

  • Construction method of question and answer system

    CN118585682A

  • Method and system for enhancing RAG questions and answers through mixed retrieval method

    CN118627625A

Cited By

  • Structured information extraction method based on artificial intelligence, intelligent agent and device

    CN120747526A

  • Medical document slicing and retrieval method and device, equipment and storage medium

    CN120994800A

  • Question and answer method and device based on product description document, computer equipment and medium

    CN121579647A

  • Systems and methods for using a large language model for large documents

    US12417352B1

  • Systems and methods for agent-controlled federated retrieval-augmented generation

    US12450217B1