Knowledge question-answering method and device based on vector recall optimization strategy under RAG framework
By dividing text paragraphs into small blocks and performing vector retrieval under the RAG framework, it solves the problem of unsatisfactory retrieval recall and accuracy in the existing technology, achieves more efficient knowledge retrieval, and improves the processing of large language models. Accuracy in answering questions.
Patent Information
- Application Number
- CN202410306344.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-18
- Publication Date
- 2024-08-30
AI Technical Summary
The overall retrieval recall rate and accuracy rate of the existing RAG combined with LLM vector similarity retrieval method in actual scenarios are not ideal, especially when dealing with unseen problems.
By dividing text paragraphs into small blocks, and retrieving multiple small block text paragraphs with similar semantics in the vector library, aggregating and accumulating semantic similarity according to the parent large block paragraph ID, and sorting in reverse order to recall the most similar large block text paragraphs , as a reference knowledge base combined with user input to generate new prompt text, and input the large language model to obtain the answer.
The recall rate and retrieval accuracy are significantly improved. The recall rate on the private test set is increased from 70% to 90%, and the overall retrieval effect is significantly improved.
Smart Images

Figure CN118568209A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of large language models, and in particular to a knowledge question answering method and device based on a vector recall optimization strategy under a RAG framework. Background Art
[0002] Large Language Model (LLM) is a natural language processing model trained by deep learning technology, which has powerful language understanding and generation capabilities. However, because its knowledge is limited to the training data it has received, its performance is not satisfactory when dealing with problems that are not in the training set. In order to overcome this challenge, a generation method called "retrieval augmented generation" has emerged. Retrieval augmented generation is abbreviated as RAG (full name: Retrieval Augmented Generation). This technology retrieves information from private knowledge base documents and inserts it into prompt instructions, enabling large language models to answer questions more accurately, providing additional contextual knowledge filling for the model, thereby alleviating the dilemma of large models answering inaccurate questions.
[0003] Further, the concept of large language model (LLM) refers to a natural language processing model trained on a large corpus through deep learning technology. Such models can perform a variety of natural language processing tasks by learning language structure and semantic information. In traditional large language models, their performance is limited by reasoning based only on training data, so they may perform poorly when faced with unseen problems.
[0004] In the existing technology, RAG combined with LLM usually converts private document content into vectors through a vector embedding model, and retrieves the TopK most similar candidate document contents from the vector database through vector similarity retrieval. Although this method is highly versatile and low-cost, the overall retrieval recall and accuracy are not ideal in actual scenarios. Summary of the invention
[0005] The present application provides a knowledge question answering method and device based on a vector recall optimization strategy under a RAG framework to solve the above-mentioned technical problem that the retrieval recall rate and accuracy rate of the prior art are not ideal.
[0006] According to one aspect of the present application, an embodiment provides a knowledge question answering method based on a vector recall optimization strategy under a RAG framework, including:
[0007] Implement user question and answer based on the constructed knowledge base;
[0008] Wherein, the user question and answer based on the constructed knowledge base includes:
[0009] Question Q1 generates a vector value QE1 through an embedding vector model; wherein the question Q1 is input by a user;
[0010] The vector value QE1 retrieves multiple small text paragraph arrays PK1 with similar semantics in the vector library, wherein the large paragraph ID P2 of each small paragraph parent is also found at the same time;
[0011] The small text paragraph array PK1 is aggregated according to the parent large paragraph ID P2, and the semantic similarity is accumulated to generate the array PK2;
[0012] According to the semantic similarity of PK2, PK2.S1 is arranged in reverse order, and K1 content is retained to generate array PK3; the most similar large block of text segments is recalled by arranging the semantic similarity PK2.S1 in reverse order;
[0013] The large text paragraph array PK3 is used as a reference knowledge base and together with the user input Q1, forms a new prompt text Prompt1;
[0014] Input Prompt1 into the large language model and get the answer.
[0015] In one embodiment, the accumulated semantic similarity generating array PK2 includes:
[0016] Accumulate the semantic similarities of the small paragraphs under the same parent large paragraph to generate array PK2;
[0017] The array PK2 contains the accumulated semantic similarity PK2.S1 of the parent large block text ID P2 and the associated small block similarities.
[0018] In one embodiment, a larger PK2.S1 value represents a higher semantic similarity, which is used to generate subsequent large model prompt text.
[0019] In one embodiment, the large text paragraph array PK3 as a reference knowledge base includes:
[0020] The chunk ID P2 in the chunk text paragraph array PK3 queries the corresponding chunk paragraph text in the non-relational database as a reference knowledge base context.
[0021] In one embodiment, the method for constructing the knowledge base includes:
[0022] Extract text content C1 based on different types of documents;
[0023] The extracted text is used to generate a number of text segments P1 according to the first set rule through regular expressions, and a unique segment ID P2 is generated through the snowflake algorithm;
[0024] P1 and P2 are persisted in a non-relational database or stored in a database;
[0025] P1 generates several small text segments P1.C1 through regular expressions according to the second set rule;
[0026] P1.C1 generates vector E1 through a vector model, and stores E1, P1.C1 and the unique identifier P2 of the parent large block of text that generates the small block of text into the vector database.
[0027] In one embodiment, the generating of the plurality of text segments P1 according to the set rules is generating the plurality of text segments P1 according to at least one rule of paragraph, space, line break, symbol and text length L1; and / or,
[0028] The generating of a plurality of small text segments P1.C1 according to the second set rule is generating a plurality of small text segments P1.C1 according to at least one rule of paragraph, space, line break, symbol and text length L2.
[0029] In one embodiment, the non-relational database is set to elasticsearch; and / or,
[0030] The database is set to MongoDB or Redis.
[0031] According to one aspect of the present application, an embodiment provides a knowledge question answering device based on a vector recall optimization strategy under a RAG framework, including:
[0032] A knowledge base building module, used to build a knowledge base; and / or,
[0033] User question and answer module, used to realize user question and answer based on the constructed knowledge base;
[0034] Wherein, the knowledge base construction module includes:
[0035] An extraction module, used for extracting text content C1 based on different types of documents;
[0036] A first generation module is used to generate a plurality of text segments P1 according to a first set rule by using a regular expression to extract the text, and to generate a unique segment ID P2 by using a snowflake algorithm;
[0037] The persistence module is used to persist P1 and P2 to a non-relational database or store them through a database;
[0038] A second generation module is used for P1 to generate a plurality of small text segments P1.C1 according to a second set rule by using a regular expression; and
[0039] A storage module is used for P1.C1 to generate vector E1 through a vector model, and store E1, P1.C1 and a unique identifier P2 of a parent large text block of the generated small text block into a vector database;
[0040] Wherein, the user question and answer module includes:
[0041] A third generation module is used for generating a vector value QE1 through an embedding vector model for question Q1; wherein the question Q1 is input by a user;
[0042] A search module is used for the vector value QE1 to search for multiple small text paragraph arrays PK1 with similar semantics in the vector library, wherein the large paragraph ID P2 of each small paragraph parent is also found at the same time;
[0043] Aggregation module, used to aggregate the small text paragraph array PK1 according to the parent large paragraph ID P2, and accumulate semantic similarity to generate array PK2;
[0044] The recall module is used to sort PK2.S1 in reverse order according to the semantic similarity of PK2, retain K1 content to generate array PK3; recall the most similar large block of text segments by sorting the semantic similarity PK2.S1 in reverse order;
[0045] A composition module, which is used for the large text paragraph array PK3 as a reference knowledge base and is used together with the user input Q1 to form a new prompt text Prompt1; and
[0046] The processing module is used to input Prompt1 into the large language model and get the answer.
[0047] According to one aspect of the present application, an embodiment provides an electronic device, including:
[0048] Memory, and
[0049] processor;
[0050] Among them, the memory is used to store one or more computer instructions; the one or more computer instructions are executed by the processor to implement any of the above-mentioned knowledge question answering methods based on the vector recall optimization strategy under the RAG framework.
[0051] According to one aspect of the present application, an embodiment provides a readable storage medium having computer instructions stored thereon; wherein the computer instructions are executed by a processor to implement any one of the above-mentioned knowledge question answering methods based on the vector recall optimization strategy under the RAG framework.
[0052] The above embodiment of the present application divides the text paragraphs into small blocks, and improves the recall rate of vector retrieval through more small blocks of content; at the same time, in order to ensure the contextual integrity in the prompt, large blocks of text are still retained. In actual application scenarios, the technical solution of the present application will make the RAG combined with LLM technology more reliable and accurate, thereby improving the accuracy and comprehensiveness of knowledge retrieval; it solves the problem of unsatisfactory results when large language models are not in the training set, and provides strong technical support. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 is a schematic diagram of a flow chart of a method for constructing a knowledge base in an embodiment;
[0054] Figure 2 It is a schematic diagram of a process of implementing user question and answer based on a constructed knowledge base in an embodiment;
[0055] Figure 3 The present invention is a structural diagram of a knowledge question-answering device based on a vector recall optimization strategy under a RAG framework in an embodiment. DETAILED DESCRIPTION
[0056] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0057] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only embodiments of a part of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work should fall within the scope of protection of the present application.
[0058] It should be noted that the terms "first", "second" etc. in the present application are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged in appropriate circumstances, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, the process, method, system, product or equipment comprising a series of steps or units need not be limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0059] It should be understood that when an element (such as a layer, film, region, or substrate) is described as being "on" another element, the element may be directly on the other element, or there may be an intermediate element. Moreover, in this application, when an element is described as being "connected" to another element, the element may be "directly connected" to the other element, or "connected" to the other element through a third element.
[0060] Embodiment 1
[0061] Please refer to Figure 1 , Figure 2 An embodiment provides a knowledge question answering method based on a vector recall optimization strategy under a RAG framework, comprising the following steps:
[0062] 1. Construction of knowledge base;
[0063] 2. Implement user question and answer based on the constructed knowledge base.
[0064] Explain in detail.
[0065] S1. Extract text content C1 based on different types of documents;
[0066] S2. The extracted text is processed by a regular expression to generate a number of text segments P1 according to the first set rule, and a unique paragraph ID P2 is generated by the snowflake algorithm;
[0067] S3.P1 and P2 are persisted to a non-relational database or stored in a database;
[0068] S4.P1 generates several small text segments P1.C1 through regular expressions according to the second set rule;
[0069] S5.P1.C1 generates vector E1 through the vector model, and stores E1, P1.C1 and the unique identifier P2 of the parent large block of text that generates the small block of text into the vector database.
[0070] The above steps complete the construction of the knowledge base; the following is user Q&A.
[0071] S6. Question Q1 generates a vector value QE1 through an embedding vector model; wherein the question Q1 is input by a user;
[0072] S7. The vector value QE1 retrieves multiple small text paragraph arrays PK1 with similar semantics in the vector library, wherein the large paragraph ID P2 of each small paragraph parent is also found at the same time;
[0073] S8. The small text paragraph array PK1 is aggregated according to the parent large paragraph ID P2, and the semantic similarity is accumulated to generate the array PK2;
[0074] S9. According to the semantic similarity of PK2, PK2.S1 is arranged in reverse order, and K1 pieces of content are retained to generate array PK3; the most similar large block of text is recalled by arranging the semantic similarity PK2.S1 in reverse order; wherein, the larger the PK2.S1 value, the higher the semantic similarity, which is used to generate the subsequent large model prompt text; K1 represents the number of retained content items, which is configurable;
[0075] S10. The large text paragraph array PK3 is used as a reference knowledge base and together with the user input Q1, forms a new prompt text Prompt1;
[0076] S11. Input Prompt1 into the large language model and get the answer.
[0077] In an embodiment of step S2, the generating of the plurality of text segments P1 according to the set rules is generating the plurality of text segments P1 according to at least one rule among paragraph, space, line break, symbol and text length L1. Similarly, in an embodiment of step S4, the generating of the plurality of small text segments P1.C1 according to the second set rules is generating the plurality of small text segments P1.C1 according to at least one rule among paragraph, space, line break, symbol and text length L2.
[0078] In an embodiment of step S3, the non-relational database is set to elasticsearch; and / or the database is set to MongoDB or Redis.
[0079] In an embodiment of step S8, the accumulating semantic similarities to generate an array PK2 includes:
[0080] Accumulate the semantic similarities of the small paragraphs under the same parent large paragraph to generate array PK2;
[0081] The array PK2 contains the accumulated semantic similarity PK2.S1 of the parent large block text ID P2 and the associated small block similarities.
[0082] In an embodiment of step S10, the large text paragraph array PK3 as a reference knowledge base includes:
[0083] The chunk ID P2 in the chunk text paragraph array PK3 queries the corresponding chunk paragraph text in the non-relational database as a reference knowledge base context.
[0084] The knowledge question answering method based on the vector recall optimization strategy under the RAG framework of this application innovates on the existing RAG vector similarity retrieval method, divides the text paragraphs into small blocks, and improves the recall rate of vector retrieval through more small blocks of content. At the same time, in order to ensure the contextual integrity in the prompt, large blocks of text are still retained. After comprehensive optimization, on the private test set (5000 pairs of QA texts), the recall rate increased from the original 70% to 90%, and the overall retrieval effect was significantly improved.
[0085] Embodiment 2
[0086] Please refer to Figure 1 , Figure 2 An embodiment provides a knowledge question answering method based on a vector recall optimization strategy under a RAG framework, comprising the following steps:
[0087] 1. Knowledge Base Construction Process
[0088] S1: Extract text content C1 through different types of documents.
[0089] S2: Generate several text segments P1 based on the extracted text through regular expressions, paragraphs, spaces, line breaks, symbols (., ?, !), text length L1 and other rules, and generate unique paragraph ID P2 through the snowflake algorithm. Among them, the text length L1 represents the upper limit of the characters for generating each paragraph. For example, if L1 is set to 300, the character length of each large text segment is 300.
[0090] S3: Persist P1 and P2 in the non-relational database elasticsearch. It can also be stored in databases such as MongoDB and Redis.
[0091] S4: P1 is passed through a regular expression to generate several small text segments P1.C1 according to the rules of paragraph, space, line break, symbol (.,?,!), text length L1, etc. Among them, the text length L2 represents the upper limit of the characters for generating each paragraph. For example, if L2 is set to 50, the character length of each small text segment is 50.
[0092] S5: Generate vector E1 from P1.C1 through a vector model, and store E1, P1.C1, and the unique identifier P2 of the parent large block of text that generates the small block of text into a vector database.
[0093] 2. User Q&A process:
[0094] S6: Generate a vector value QE1 through the embedding vector model for the question Q1 input by the user.
[0095] S7: Use the vector value QE1 to search for an array PK1 consisting of multiple small paragraphs with similar semantics in the vector library; wherein, the large paragraph ID P2 of each small paragraph parent is also found.
[0096] S8: Aggregate the small text paragraph array PK1 according to the parent large paragraph ID P2, and accumulate the semantic similarities of the small paragraphs under the same parent large paragraph to generate an array PK2; wherein the array PK2 contains the accumulated semantic similarity PK2.S1 of the parent large text ID P2 and the associated small similarities.
[0097] S9: According to the semantic similarity of PK2, PK2.S1 is arranged in reverse order, K1 pieces of content are retained to generate array PK3, and the most similar large blocks of text are recalled by sorting the semantic similarity PK2.S1 in reverse order. The larger the PK2.S1 value, the higher the semantic similarity, which is used to generate the subsequent large model prompt text; K1 represents the number of retained content items, which can be configured.
[0098] S10: query the corresponding large block paragraph text in elasticsearch for the large block ID P2 in the large text paragraph array PK3 as a reference knowledge base context, and form a new prompt text Prompt1 together with the user input Q1.
[0099] S11: Input Prompt1 to the large language model and get the answer.
[0100] The knowledge question answering method based on the vector recall optimization strategy under the RAG framework of this application has achieved significant performance improvement on the private test set by innovating the existing RAG vector similarity retrieval method. In 5,000 pairs of QA texts, the recall rate increased from the original 70% to 90%, and the overall retrieval effect was significantly improved.
[0101] Embodiment 3
[0102] Please refer to Figure 3 Based on the same inventive concept, an embodiment of the present application provides a knowledge question-answering device based on a vector recall optimization strategy under a RAG framework, which takes the following form.
[0103] 1. Knowledge base construction module, used to construct the knowledge base.
[0104] The knowledge base building blocks include:
[0105] The extraction module 11 is used to extract text content C1 based on different types of documents;
[0106] The first generating module 12 is used to generate a plurality of text segments P1 according to the first setting rule by using a regular expression to extract the text, and to generate a unique segment ID P2 by using a snowflake algorithm;
[0107] The persistence module 13 is used to persist P1 and P2 into a non-relational database or store them through a database;
[0108] The second generating module 14 is used for generating a plurality of small text segments P1.C1 according to the second setting rule by using a regular expression from P1; and
[0109] The storage module 15 is used for P1.C1 to generate vector E1 through the vector model, and store E1, P1.C1 and the unique identifier P2 of the parent large block text of the generated small block text into the vector database;
[0110] 2. User question and answer module, used to realize user question and answer based on the constructed knowledge base.
[0111] User Q&A module, including:
[0112] The third generation module 21 is used for generating a vector value QE1 through an embedding vector model for question Q1; wherein the question Q1 is input by a user;
[0113] The search module 22 is used to search the vector value QE1 for multiple small text paragraph arrays PK1 with similar semantics in the vector library, wherein the large paragraph ID P2 of each small paragraph parent is also found at the same time;
[0114] Aggregation module 23 is used to aggregate the small text paragraph array PK1 according to the parent large paragraph ID P2, and accumulate semantic similarity to generate array PK2;
[0115] The recall module 24 is used to sort the semantic similarity PK2.S1 of PK2 in reverse order, retain K1 content to generate an array PK3; recall the most similar large block of text segments by sorting the semantic similarity PK2.S1 in reverse order;
[0116] Composition module 25 is used for large text paragraph array PK3 as a reference knowledge base, and together with user input Q1, forms a new prompt text Prompt1; and
[0117] The processing module 26 is used to input Prompt1 into the large language model and obtain the answer.
[0118] The above-mentioned knowledge question and answer device based on the vector recall optimization strategy under the RAG framework is used to implement the knowledge question and answer method based on the vector recall optimization strategy under the RAG framework in the above-mentioned embodiments. Each module in the device corresponds to each step in the method and will not be repeated.
[0119] Embodiment 4
[0120] Based on the same inventive concept, an embodiment of the present application provides an electronic device, including: a memory and a processor; wherein the memory is used to store one or more computer instructions; the one or more computer instructions are executed by the processor to implement the knowledge question and answer method based on the vector recall optimization strategy under the RAG framework as described in any one of the above embodiments.
[0121] Among them, the above one or more computer instructions can be formed into a program.
[0122] Embodiment 5
[0123] Based on the same inventive concept, an embodiment of the present application provides a readable storage medium, on which computer instructions are stored; wherein, when the computer instructions are executed by the processor, the knowledge question and answer method based on the vector recall optimization strategy under the RAG framework described in any one of the above embodiments is implemented.
[0124] Among them, the above one or more computer instructions can be formed into a program.
[0125] The above program can be run in the processor, or it can be stored in the memory (or computer-readable medium), which includes permanent and non-permanent, removable and non-removable media. Information storage can be achieved by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0126] These computer programs can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps of the functions specified in one or more blocks can be implemented by different modules corresponding to different steps.
[0127] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A knowledge question answering method based on a vector recall optimization strategy under a RAG framework, characterized in that: include: Implement user question and answer based on the constructed knowledge base; Wherein, the user question and answer based on the constructed knowledge base includes: Question Q1 generates a vector value QE1 through an embedding vector model; wherein the question Q1 is input by a user; The vector value QE1 retrieves multiple small text paragraph arrays PK1 with similar semantics in the vector library, wherein the large paragraph ID P2 of each small paragraph parent is also found at the same time; The small text paragraph array PK1 is aggregated according to the parent large paragraph ID P2, and the semantic similarity is accumulated to generate the array PK2; According to the semantic similarity of PK2, PK2.S1 is arranged in reverse order, and K1 content is retained to generate array PK3; the most similar large block of text segments is recalled by arranging the semantic similarity PK2.S1 in reverse order; The large text paragraph array PK3 is used as a reference knowledge base and together with the user input Q1, forms a new prompt text Prompt1; Input Prompt1 into the large language model and get the answer.
2. According to claim 1, a knowledge question answering method based on a vector recall optimization strategy under a RAG framework is characterized in that: The accumulated semantic similarity generation array PK2 includes: Accumulate the semantic similarities of the small paragraphs under the same parent large paragraph to generate array PK2; The array PK2 contains the accumulated semantic similarity PK2.S1 of the parent large block text ID P2 and the associated small block similarities.
3. According to claim 1, a knowledge question answering method based on a vector recall optimization strategy under a RAG framework is characterized in that: The larger the PK2.S1 value, the higher the semantic similarity, which is used to generate the subsequent large model prompt text.
4. According to claim 1, a knowledge question answering method based on a vector recall optimization strategy under a RAG framework is characterized in that: The large text paragraph array PK3 as a reference knowledge base includes: The chunk ID P2 in the chunk text paragraph array PK3 queries the corresponding chunk paragraph text in the non-relational database as a reference knowledge base context.
5. According to claim 1, a knowledge question answering method based on a vector recall optimization strategy under a RAG framework is characterized in that: The method for constructing the knowledge base includes: Extract text content C1 based on different types of documents; The extracted text is used to generate a number of text segments P1 according to the first set rule through regular expressions, and a unique segment ID P2 is generated through the snowflake algorithm; P1 and P2 are persisted in a non-relational database or stored in a database; P1 generates several small text segments P1.C1 through regular expressions according to the second set rule; P1.C1 generates vector E1 through a vector model, and stores E1, P1.C1 and the unique identifier P2 of the parent large block of text that generates the small block of text into the vector database.
6. According to claim 5, a knowledge question answering method based on a vector recall optimization strategy under a RAG framework is characterized in that: Generating a plurality of text segments P1 according to the set rules is generating a plurality of text segments P1 according to at least one rule of paragraph, space, line break, symbol and text length L1; and / or, The generating of a plurality of small text segments P1.C1 according to the second set rule is generating a plurality of small text segments P1.C1 according to at least one rule of paragraph, space, line break, symbol and text length L2.
7. According to claim 5, a knowledge question answering method based on a vector recall optimization strategy under a RAG framework is characterized in that: The non-relational database is set to elasticsearch; and / or, The database is set to MongoDB or Redis.
8. A knowledge question answering device based on a vector recall optimization strategy under a RAG framework, characterized in that: include: A knowledge base construction module is used to construct a knowledge base; and / or, User question and answer module, used to realize user question and answer based on the constructed knowledge base; Wherein, the knowledge base construction module includes: An extraction module, used for extracting text content C1 based on different types of documents; A first generation module is used to generate a plurality of text segments P1 according to a first set rule by using a regular expression to extract the text, and to generate a unique segment ID P2 by using a snowflake algorithm; The persistence module is used to persist P1 and P2 to a non-relational database or store them through a database; A second generation module is used for P1 to generate a plurality of small text segments P1.C1 according to a second set rule by using a regular expression; and A storage module is used for P1.C1 to generate vector E1 through a vector model, and store E1, P1.C1 and a unique identifier P2 of a parent large text block of the generated small text block into a vector database; Wherein, the user question and answer module includes: A third generation module is used for generating a vector value QE1 through an embedding vector model for question Q1; wherein the question Q1 is input by a user; A search module is used for the vector value QE1 to search for multiple small text paragraph arrays PK1 with similar semantics in the vector library, wherein the large paragraph ID P2 of each small paragraph parent is also found at the same time; Aggregation module, used to aggregate the small text paragraph array PK1 according to the parent large paragraph ID P2, and accumulate semantic similarity to generate array PK2; The recall module is used to sort PK2.S1 in reverse order according to the semantic similarity of PK2, retain K1 content to generate array PK3; recall the most similar large block of text segments by sorting the semantic similarity PK2.S1 in reverse order; A composition module, which is used for the large text paragraph array PK3 as a reference knowledge base and is used together with the user input Q1 to form a new prompt text Prompt1; and The processing module is used to input Prompt1 into the large language model and get the answer.
9. An electronic device, characterized in that: include: Memory, and processor; Wherein, the memory is used to store one or more computer instructions; the one or more computer instructions are executed by the processor to implement the knowledge question answering method based on the vector recall optimization strategy under the RAG framework as described in any one of claims 1 to 7.
10. A readable storage medium, characterized in that: The readable storage medium stores computer instructions; wherein, the computer instructions are executed by a processor to implement the knowledge question answering method based on the vector recall optimization strategy under the RAG framework as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Question and answer method and system based on LangChain and large language model
CN117313859A
Cited By
Knowledge-enhanced question-answering method based on multi-dimensional mixed retrieval strategy
CN119669431A
Large model RAG recall strategy intelligent planning method and device, medium and equipment
CN119760097A
A method, apparatus, medium, and equipment for intelligent planning of large-scale RAG recall strategy.
CN119760097B
Retrieval enhancement generation method and device, equipment and storage medium
CN119903079A
Enhanced retrieval generation method based on father-child segmentation and multi-source recall
CN120723894A
