Large model knowledge base retrieval method based on multi-granularity retrieval
By building a multi-grained knowledge base and combining generative indexes and vector models, the problem of insufficient knowledge base retrieval efficiency and accuracy in the existing technology is solved, and more efficient, accurate and intelligent knowledge retrieval is achieved.
Patent Information
- Application Number
- CN202510188814.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-20
- Publication Date
- 2025-03-18
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When the existing technology faces large-scale, multi-dimensional, semantic complex knowledge bases, the retrieval efficiency and accuracy are insufficient. Especially when dealing with unstructured text data and complex query requirements, it is difficult to achieve multi-grained expression, improve retrieval accuracy and recall, and it is difficult to build and update the knowledge base.
A large-model knowledge base search method based on multi-grained retrieval is adopted to build a knowledge base at three levels: title, fragment and sentence, and combine generative indexes and vector models to improve retrieval accuracy, efficiency and diversity.
Through the advantages of multi-level and multi-grained knowledge representation and generative indexing, the accuracy, efficiency and intelligence of the retrieval system are significantly improved, and the problems of low search accuracy, poor query adaptability and slow knowledge base updates are solved.
Smart Images

Figure CN119646201A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of large model technology, and in particular to a large model knowledge base retrieval method based on multi-granularity retrieval. Background Art
[0002] With the rapid development of information technology, massive amounts of text data and knowledge bases are constantly emerging. How to effectively retrieve, process and utilize these data has become a key issue in many fields. Especially in the fields of natural language processing (NLP) and artificial intelligence (AI), with the continuous advancement of deep learning technology and large models (such as GPT, LLama, etc.), intelligent retrieval technology has gradually become the core technology to improve the efficiency of information acquisition.
[0003] Traditional knowledge base retrieval methods usually rely on retrieval mechanisms based on keyword matching. Although these methods can provide basic retrieval functions in certain specific scenarios, their retrieval efficiency and accuracy often cannot meet actual needs when faced with large-scale, multi-dimensional, and semantically complex knowledge bases. Especially when faced with unstructured text data, traditional methods find it difficult to cope with complex query requirements and cannot effectively extract knowledge from different levels and dimensions.
[0004] Currently, many modern retrieval methods have begun to combine vector space models to capture the semantic relationship between texts by converting texts into high-dimensional vector representations. These methods usually use deep learning models to encode texts, generate vector representations, and then perform retrieval by calculating the similarity between vectors. However, existing retrieval methods still have some problems and challenges: 1. Insufficient multi-granularity expression of knowledge base: Most of the existing retrieval methods based on vector models only focus on the semantic representation of the full text or paragraph level, while ignoring the expression of text content at different granularities. For example, knowledge at different levels such as titles, fragments, and sentences have different semantic importance in the same knowledge base, which makes it difficult for existing retrieval methods to perform effective queries at different levels.
[0005] 2. The contradiction between retrieval precision and recall rate: Although retrieval methods have made some progress in improving recall rate and coverage in recent years, there is still a lot of room for improvement in precision. In existing methods, due to excessive reliance on vector similarity calculation, the retrieval results may contain a large number of irrelevant or low-quality candidates, thus affecting the quality of the retrieval results.
[0006] 3. Lack of effective generative indexing mechanism: In some complex query scenarios, users often do not directly enter standard keywords, but express their query intent through natural language. Existing retrieval methods are poorly adaptable to such generative queries and often rely on fixed indexing strategies or simple pattern matching, which leads to an inability to fully understand the user's query intent, thus affecting the accuracy and relevance of the retrieval.
[0007] 4. Difficulty in building and updating knowledge bases: Traditional knowledge base construction methods usually rely on manual annotation and classification, which is not only labor-intensive and time-consuming, but also difficult to ensure rapid updating and optimization in a dynamically changing information environment. Especially in the application scenarios of large-scale text data, how to efficiently and automatically build and update the knowledge base is still a problem that needs to be solved. Summary of the invention
[0008] In order to overcome the above problems, the present invention proposes a large model knowledge base retrieval method based on multi-granularity retrieval, which aims to improve the retrieval accuracy, efficiency and diversity by building a knowledge base based on multiple levels of knowledge such as titles, fragments, sentences, etc., and combining generative indexes and vector models. The present invention can better adapt to complex query requirements through multi-level and multi-granular knowledge representation, combined with the advantages of large language model generative indexes, thereby effectively improving the performance and accuracy of the intelligent retrieval system.
[0009] In order to achieve the above-mentioned invention object, the technical solution provided by the present invention includes: The large model knowledge base retrieval method based on multi-granularity retrieval includes the following steps: S1. Construct a knowledge base based on knowledge at three levels: title, segment and sentence, wherein the knowledge base includes a vector database storing a first vector and a second vector, and a relational database storing index values and index types corresponding to the first vector and the second vector; the first vector represents an index key of segment-level knowledge and / or sentence-level knowledge, and the second vector represents an index key of title-level knowledge and / or question-level knowledge; S2. Generate a vector value of the user query using the vector model, search for several query index vectors with the highest similarity to the query vector value in the first vector and the second vector respectively, and obtain the query index value and the query index type corresponding to the query index vector in the relational database as a candidate retrieval result; S3. Construct a query prompt word together with several candidate search results and the user query, and input it into the large model to obtain the final query answer.
[0010] Preferably, the method for constructing the knowledge base includes: S101. Obtain the target text and parse the document structure, split and reorganize the text data according to the three levels of title, fragment and sentence, and construct knowledge at three levels of title, fragment and sentence; each level of knowledge includes index key, index value and index type; S102. Using a large language model to construct a generative index based on sentence-level knowledge as question-level knowledge; S103. Generate a first vector of index keys representing segment-level knowledge and / or sentence-level knowledge, and a second vector of index keys representing title-level knowledge and / or question-level knowledge using a vector model; S104. Store the first vector and the second vector in a vector database respectively, and store the index values and index types corresponding to the first vector and the second vector in a relational database to complete the construction of the target large model knowledge base.
[0011] Preferably, the step S101 includes: S1011. Obtain the target text and parse the document structure, traverse and obtain the type and content of each paragraph; S1012. For paragraphs of the title type, the title content is used as the index key, and the text contained in the title, the sub-title, and the text contained in the sub-title are sequentially spliced as the index value to construct title-level knowledge; S1013. For paragraphs of type body, the body content is used as index key and index value respectively to construct fragment-level knowledge; S1014. The paragraphs of the text type are segmented by periods to obtain sentences, and the content of each sentence is used as an index key and an index value to construct sentence-level knowledge.
[0012] Preferably, the step S102 includes: S1021. Use the large language model to extract each knowledge point in the given text sentence sample and generate several related questions; S1022. Filter the best question with the highest matching degree with the knowledge point, and concatenate the given text sentence sample and the best question corresponding to each knowledge point and add them to the prompt word as an example; S1023. Use the prompt words to guide the large language model to output a number of generative indexes based on each sentence-level knowledge, use the generative index as the index key, and use the content of the sentence-level knowledge as the index value to construct question-level knowledge.
[0013] Preferably, the method for obtaining the query index vector includes: S201. Generate a vector value of the user query using a vector model, traverse and calculate the similarity with the vector value in the first vector and the second vector, respectively obtain a number of first vector query results and second vector query results that meet the preset similarity threshold requirements, and merge them into a query index vector.
[0014] Preferably, the method for obtaining the candidate search results includes: S202. Obtaining the index value and index type corresponding to the query index vector in the relational database, and sorting the index value into a title index value, a fragment index value, a sentence index value, and a question index value according to the index type; S203. De-duplicate the index values according to the ranking, build a knowledge candidate pool based on the de-duplicate index values, and calculate the ranking score of each index value in the knowledge candidate pool with respect to the user query; S204. Perform weighted calculation on the vector similarity and ranking score corresponding to each index value in the knowledge candidate pool, and select several query index values with top ranking in the calculation results as candidate retrieval results.
[0015] Preferably, the method for removing duplicate index values by sorting includes: The indexes are placed in the knowledge candidate pool one by one in the order of index type: title, fragment, sentence and question, and it is traversed to see whether there is an inclusion relationship between the current index value and the remaining index values in the knowledge candidate pool. If not, the current index value is retained; if so, the vector similarity between the current index value and the comparison index value in the knowledge candidate pool that has an inclusion relationship and the user query is compared respectively. If the former is larger, the comparison index value is replaced by the current index value; if the latter is larger, the current index value is discarded.
[0016] Beneficial Effects The present invention significantly improves the accuracy, efficiency and intelligence level of the retrieval system through a technical solution combining multi-granularity retrieval, generative indexing and vector model, and solves the problems of low accuracy, poor query adaptability and slow knowledge base update in the prior art. Through the construction of a multi-level and multi-granular knowledge base, the application of a generative indexing mechanism and an efficient retrieval ranking and weighted calculation method, the present invention has broad application prospects and practical value in the fields of intelligent retrieval and large-scale data processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 A schematic diagram of a flow chart of a large model knowledge base retrieval method based on multi-granularity retrieval in a preferred embodiment of the present invention; Figure 2 A schematic flow chart of a method for constructing a knowledge base in a large model knowledge base retrieval method based on multi-granularity retrieval in a preferred embodiment of the present invention. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention is further described below in conjunction with the accompanying drawings. In the description of the present invention, it should be understood that the terms "upper", "lower", "front", "back", "left", "right", "top", "bottom", "inside", "outside" and the like indicate directions or positional relationships based on the directions or positional relationships shown in the accompanying drawings, which are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific direction, be constructed and operated in a specific direction, and therefore cannot be understood as limiting the present invention.
[0019] Embodiment 1 like Figure 1 As shown, the present invention provides a large model knowledge base retrieval method based on multi-granularity retrieval, comprising the steps of: S1. Construct a knowledge base based on knowledge at three levels: title, fragment and sentence, wherein the knowledge base includes a vector database storing a first vector and a second vector, and a relational database of index values and index types corresponding to the first vector and the second vector; the first vector represents an index key of fragment-level knowledge and / or sentence-level knowledge, and the second vector represents an index key of title-level knowledge and / or question-level knowledge.
[0020] The core idea of this step is to organize text data at different granularities and build a knowledge base based on semantic levels of different granularities. Specifically, the text is divided into three levels of knowledge: title level, fragment level, and sentence level. Title level knowledge usually refers to the title part of an article or document, which usually contains the theme or central idea of the entire article and is regarded as the main entry point for information. Fragment level knowledge refers to larger information units in an article, such as paragraphs or chapters. Fragment level knowledge usually contains more context than sentence level information and has higher semantic completeness. Sentence level knowledge refers to a single sentence or a small semantic unit. These sentences usually contain more fine-grained knowledge or information.
[0021] The first vector represents the index key of the segment-level knowledge and / or sentence-level knowledge, which is a vector representation obtained by encoding the text of the segment or sentence through a vectorization model (such as BERT, Roberta, etc.). They capture the semantic information at the segment or sentence level and serve as the basic unit for matching during retrieval.
[0022] The second vector represents the index key of title-level knowledge and / or question-level knowledge, which usually contains the core topic information about the entire article or document. These vectors are used to process queries that focus on global topics or large-scale information.
[0023] Those skilled in the art should understand that the construction process of the knowledge base can adopt conventional technical methods recognized in the art, including but not limited to technical means such as text analysis, information extraction, natural language processing (NLP), machine learning and deep learning. These technologies are widely used in knowledge base construction, and can effectively extract valuable information from a large amount of raw data and store it in a structured manner. Since the specific technical solutions for building a knowledge base have been maturely applied in this field, these conventional methods are no longer elaborated in detail in this embodiment. The relevant technical details can be referred to the existing public literature and technical documents, and the present invention is not limited to a specific technical implementation.
[0024] S2. Generate a vector value of the user query using a vector model, query several query index vectors with the highest similarity to the query vector value in the first vector and the second vector respectively, and obtain the query index value and query index type corresponding to the query index vector in the relational database as candidate retrieval results.
[0025] User queries (usually natural language expressions) are first converted into a vector representation. This vector representation encodes the query content into a high-dimensional vector through a vector model (such as BERT or Roberta). This vector representation can capture the semantic information in the query, such as the relationship between keywords, the context in the query, etc. By converting the query into a vector, the system can compare the query content with the vector stored in the knowledge base to obtain relevant retrieval results.
[0026] The vector value of the user query will be respectively similar to the vectors stored in the first vector and the second vector, and several vectors most relevant to the query content can be obtained. The similarity calculation can use a variety of methods, such as cosine similarity, Euclidean distance, Manhattan distance, etc.
[0027] In some preferred embodiments, a method for obtaining a query index vector is provided, which specifically includes: S201. Generate a vector value of the user query using a vector model, traverse and calculate the similarity with the vector value in the first vector and the second vector, respectively obtain a number of first vector query results and second vector query results that meet the preset similarity threshold requirements, and merge them into a query index vector.
[0028] The vector model includes common pre-trained models such as BERT, Roberta or Sentence-BERT, which can effectively capture the semantic information in the query.
[0029] Since the knowledge base in the system is represented by multiple vectors (i.e., the first vector and the second vector), it is necessary to calculate the similarity between the user query vector and these stored vectors to find the text content most relevant to the user query. The core purpose of similarity calculation is to determine the semantic proximity between the query and the stored content.
[0030] The similarity threshold is used to filter out the most relevant search results. The selection of the threshold can be adjusted according to the needs of the specific application scenario. A lower threshold may introduce more results with weaker relevance, while a higher threshold may miss some potentially relevant results.
[0031] The merged query index vector contains multi-level information of the user query and serves as the basis for the subsequent retrieval process.
[0032] Furthermore, since the query index vector may correspond to multiple index values and index types in a relational database, and these index values and index types may belong to different levels, and their relevance to the user query may also vary, for example, the same paragraph may appear in multiple index types (for example, a paragraph belongs to both a fragment index and sentence-level knowledge). In some preferred embodiments, a method for obtaining more accurate candidate retrieval results through deduplication, sorting, and weighted calculation is provided, specifically including: S202. Obtain the index value and index type corresponding to the query index vector in the relational database, and sort the index value according to the index type into a title index value, a fragment index value, a sentence index value, and a question index value.
[0033] S203. De-duplicate the index values according to the ranking, build a knowledge candidate pool based on the de-duplicate index values, and calculate the ranking score of each index value in the knowledge candidate pool with respect to the user query; for example, the same paragraph may appear in multiple index types (for example, a paragraph belongs to both a fragment index and sentence-level knowledge). Therefore, in order to avoid returning the same search results repeatedly, the system needs to deduplicate these index values.
[0034] Deduplication can be prioritized based on the index type. For example, the index of the title type is generally prioritized, while the index of the fragment or sentence type may be ranked behind. If there are duplicate titles and sentences, the index with higher priority is retained and the redundant part is deleted. It can also be based on content. When the content of some index values is exactly the same, the duplicate items can be deleted and only one index is retained. In some preferred embodiments, a fusion deduplication method based on containment relationship and similarity is given, which specifically includes: The indexes are placed in the knowledge candidate pool one by one in the order of index type: title, fragment, sentence and question, and it is traversed to see whether there is an inclusion relationship between the current index value and the remaining index values in the knowledge candidate pool. If not, the current index value is retained; if so, the vector similarity between the current index value and the comparison index value in the knowledge candidate pool that has an inclusion relationship and the user query is compared respectively. If the former is larger, the comparison index value is replaced by the current index value; if the latter is larger, the current index value is discarded.
[0035] Among them, the sorting is to ensure that in the process of deduplication, different types of index values will be compared and decided according to their order of importance, to prevent low-priority indexes from covering or excluding high-priority indexes. In this embodiment, by checking the inclusion relationship first and then calculating the similarity, the system can perform intelligent deduplication based on the dual dimensions of text structure and semantics. This ensures that in the case of information overlap, the most relevant content can be retained first according to the query requirements.
[0036] The ranking score refers to a value used to measure the relevance and priority of each candidate result to the user's query when ranking candidate results in the information retrieval system. The ranking score reflects how the system evaluates the degree of match between each retrieval result and the query, and its calculation method can be calculated by similarity score, relevance weight or other features (such as the timeliness of the document, user preferences, query history, document length, etc.). In some preferred embodiments, a Rerank model can be used to optimize the ranking score using more contextual information and more complex features, thereby further adjusting the preliminary ranking results. Through the Rerank model, the system can optimize the ranking according to the user's behavior, query history and specific features, so that the retrieval results finally returned are more in line with user needs.
[0037] S204. Perform weighted calculation on the vector similarity and ranking score corresponding to each index value in the knowledge candidate pool, and select several query index values with top ranking in the calculation results as candidate retrieval results. It should be understood that the weight setting during weighted calculation can usually be adjusted according to the needs of different scenarios. For example, if the query is mainly to find a specific text fragment, a higher weight can be given to the similarity score; if the query is more focused on the document topic, the weight of the ranking score can be increased.
[0038] S3. Construct a query prompt word together with several candidate search results and the user query, and input it into the large model to obtain the final query answer.
[0039] The query prompt is a formatted expression used to input query information into the big model. By combining the user's original query with the information obtained from the candidate search results, the system can generate a richer query prompt to help the big model understand the user's needs more accurately and give relevant outputs. In this step, the candidate search results are used as background information that has a high semantic relevance to the user's query and can provide more contextual information for the big model. In some preferred embodiments, the format of the query prompt is as follows: You are a question-and-answer assistant. You need to answer the [user question] based on the information in the following [related knowledge]. If the knowledge in the [related knowledge] cannot answer the [user question], please politely refuse.
[0040]
Related knowledge
User Question
[0041] Embodiment 2 This embodiment is developed on the basis of the above-mentioned embodiment 1. Figure 2 As shown, this embodiment provides a method for constructing a large model knowledge base based on multi-granularity retrieval, including the steps of: S101. Obtain the target text and parse the document structure, split and reorganize the text data according to the three levels of title, fragment and sentence, and construct knowledge at three levels of title, fragment and sentence; each level of knowledge includes index key, index value and index type.
[0042] The large model knowledge base refers to a special knowledge storage system built to support the large language model (LLM) to generate high-quality content. It stores and organizes knowledge in a form suitable for large models, so that the large model can efficiently retrieve the required information and generate more accurate and relevant content. It is not only a container for knowledge organization, but also an important supporting tool for improving the generation capability of large models. The present invention provides strong technical support for the generation of accurate and reliable content for large models by optimizing the construction method of the large model knowledge base.
[0043] The target text refers to the original document content used to build the knowledge base. It is the input data source of the entire knowledge base construction process, and is organized into different levels of knowledge representation after parsing and multi-granularity processing. It includes various types of text files, such as plain text files (txt), rich text files (word, pdf), and other document forms that need to be processed; it can be a document with a clear structure (such as titles and paragraphs) or an unstructured text (such as a scanned document recognized by OCR).
[0044] The document structure analysis of the target text can select a suitable analysis tool according to the format of the target text, using Python's python-docx library for word files and Python's fitz library for pdf files. The specific analysis method can be freely selected by those skilled in the art in the art, and the present invention does not make further limitations.
[0045] The reason why the present invention considers constructing three levels of knowledge, namely title, fragment and sentence, is that by organizing and representing knowledge in a hierarchical manner, it can capture the overall semantic structure of the document and refine it to local key points to meet diverse query requirements and improve the accuracy and efficiency of retrieval. The technical considerations for constructing each level of knowledge are explained below: 1. The construction of title-level knowledge is because, on the one hand, title-level knowledge usually contains the core theme of the document and is a general description of the document content. Through the title structure, one can quickly understand the hierarchy and main content of the document, so it provides high-level semantic information; on the other hand, title-level knowledge can quickly match the user's global query; and thirdly, because the granularity of title knowledge is large, it is easy to quickly filter and rearrange, providing a contextual framework for subsequent fine-grained retrieval.
[0046] 2. The construction of fragment-level knowledge is because a fragment is usually a logically complete paragraph that can carry more specific semantics and provide mid-level semantic information; on the other hand, the integration of fragment-level knowledge with tables, paragraphs and additional information helps to fully express the content of a certain topic.
[0047] 3. The construction of sentence-level knowledge provides fine-grained information matching, which can minimize context redundancy, ensure that the retrieved content is highly relevant to user needs, and reduce the risk of information redundancy and hallucination. On the other hand, it can also be used in subsequent steps to build generative indexes, providing a basis for large language models to generate high-quality question-level knowledge, further enhancing the practicality of the knowledge base.
[0048] The three-level knowledge construction reflects the core concept of the multi-granularity knowledge base construction of the present invention: focusing on the global structure of the document while taking into account local details to ensure the comprehensiveness and accuracy of knowledge expression. This hierarchical design not only improves the adaptability of the knowledge base, but also provides strong technical support for different types of queries.
[0049] Those skilled in the art should know that the construction of the above three levels of knowledge can be obtained by using a vector model commonly used in the art, such as BERT, Roberta, and Sentence-Bert. In some preferred embodiments, a knowledge construction method based on an index structure is provided, specifically including: S1011. Obtain the target text and parse the document structure, traverse and obtain the type and content of each paragraph. The types specifically include title and body, where the paragraph style of the body is divided into two types, namely, the common type representing the standard style and the unique type representing the extended style. The present invention does not make further distinction between the two and both are identified as body.
[0050] S1012. For paragraphs of title type, the title content is used as the index key, and the text contained in the title, the sub-titles, and the text contained in the sub-titles are sequentially spliced as the index value to construct title-level knowledge. Its json representation is as follows: ; Among them, index, value and type represent the index key, index value and index type of knowledge storage respectively. Among them, title and content represent the title name and all the text contents contained under the current title respectively, and "title" is the index type string.
[0051] If there is a table structure before or after the text under the current title, the table structure is parsed and concatenated in the order of row name, column name and cell content, and then added to the text of the current title.
[0052] S1013. For paragraphs of type body, the body content is used as index key and index value respectively to construct fragment-level knowledge. Its json representation is as follows: ; S1014. Segment the paragraphs of the text type by period to obtain sentences, and use the content of each sentence as the index key and index value to construct sentence-level knowledge. Its json representation is as follows: .
[0053] If there is a table structure in the current sentence, the row name, column name, and cell content are concatenated in order as index keys and index values, respectively, to construct sentence-level knowledge.
[0054] In some preferred embodiments, the target text may not have preset document title information, in which case the construction of title-level knowledge needs to be skipped. In other preferred embodiments, for text in a cross-platform portable document format (such as PDF), OCR layout recognition technology can be used to detect each text block. If a title block is identified before the text block, since layout recognition may not be able to obtain multi-level title information, the recognition results of the title block and the text block are spliced in sequence and used as index keys and index values, respectively, to construct fragment-level knowledge. If no title block is identified before the text block, the text block recognition results are used as index keys and index values, respectively, to construct fragment-level knowledge. Furthermore, if there is a table structure in the recognition result, after parsing the table structure, the row name, column name, and cell content are spliced in sequence and used as index keys and index values, respectively, to construct fragment-level knowledge.
[0055] S102. Use the large language model to construct a generative index based on sentence-level knowledge as question-level knowledge. Extract and generate question-level knowledge from sentence-level knowledge to enhance the retrieval capability of the knowledge base. Through the construction of a generative index, the user's query can be directly matched with the generated question, thereby improving the accuracy of the retrieval and the fine-grained information coverage capability. In some preferred embodiments, specific steps are given: S1021. Use a large language model to extract each knowledge point in a given text sentence sample and generate several related questions.
[0056] S1022. Filter the best question with the highest matching degree with the knowledge point, and add the given text sentence sample and the best question corresponding to each knowledge point as an example to the prompt word. Combine the given text sentence sample with the screened question to construct a further generation example to optimize the accuracy of the next round of question generation. The given text sentence sample refers to a specific text sentence provided in advance by a person skilled in the art as input data, which is used to guide the model to understand, analyze, generate or process, and can be a statement or other type of sentence.
[0057] S1023. Use the prompt words to guide the large language model to output several generative indexes based on each sentence-level knowledge, use the generative index as the index key, and use the content of the sentence-level knowledge as the index value to construct question-level knowledge. Use the prompt words to guide the model to generate diversified questions, covering different semantic angles of sentence-level knowledge.
[0058] The following is a specific example to further illustrate the above steps: Given a sample text sentence: "Apples are rich in vitamin C, which can enhance immunity. Bananas are rich in dietary fiber, which helps promote intestinal motility and prevent constipation." The knowledge extracted in step S1021 includes: "Apples are rich in vitamin C, which can enhance immunity" and "Bananas are rich in dietary fiber, which helps promote intestinal peristalsis and prevent constipation." Based on this, questions that can be generated include: "What is the effect of the vitamin C content of apples on immunity?", "Why can apples enhance immunity?", "What are the benefits of eating bananas?", "Which fruits contain dietary fiber like bananas?".
[0059] After manual screening in step S1022, the best questions obtained are: "Why can apples enhance immunity?" and "What are the benefits of eating bananas?", and the given text sentence sample and the best questions are concatenated and added to the prompt words as examples.
[0060] Taking the sentence-level knowledge content "Artificial intelligence is an important part of the intelligent discipline. It attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is a very broad science, including robots, language recognition, image recognition, natural language processing, expert systems, machine learning, computer vision, etc." as an example, the prompt words are as follows: [Example] Input text: Apples are rich in vitamin C, which can enhance immunity. Bananas are rich in dietary fiber, which helps promote intestinal peristalsis and prevent constipation.
[0061] Output questions: ["Why can apples enhance immunity?", "What are the benefits of eating bananas?"]
Practical Application
[0062] Output problem: The final output answer list is ["What are the components of artificial intelligence?", "What directions does artificial intelligence include?"] The example of the question-level knowledge json constructed by the generative index obtained in step S1023 is as follows: { “query”: “What are the components of artificial intelligence?”, "value": "Artificial intelligence is an important part of the intelligent discipline. It attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is a very broad science, including robots, language recognition, image recognition, natural language processing, expert systems, machine learning, computer vision, etc.", "type":"query" }, { “query”: “What directions does artificial intelligence include?”, "value": "Artificial intelligence is an important part of the intelligent discipline. It attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is a very broad science, including robots, language recognition, image recognition, natural language processing, expert systems, machine learning, computer vision, etc.", "type":"query" }, S103. Generate a first vector representing an index key of segment-level knowledge and / or sentence-level knowledge, and a second vector representing an index key of title-level knowledge and / or question-level knowledge using a vector model.
[0063] When generating vector representations, it is necessary to fully consider the differences in the expressions of index keys of different knowledge types: 1. Fragment-level knowledge and sentence-level knowledge: Index keys and index values are usually semantic representations of a piece of text, suitable for capturing global or contextual information. Their vector representation can directly match user queries during retrieval and quickly recall relevant knowledge fragments.
[0064] 2. Title-level knowledge and question-level knowledge: Index keys are shorter and often only reflect the core topics or key issues of knowledge, which are suitable for efficiently locating important entries in the knowledge base. In this way, user queries can be matched with phrased index keys and directly associated with specific knowledge content.
[0065] The first vector is usually a relatively complete text description with global information, which can directly match the user query to locate the text fragments that are highly relevant to the query content. The second vector is more refined, often contains key information, and has a strong correlation with the corresponding index value. By matching the user query with these index keys, the key knowledge units can be quickly located and their associated content can be obtained.
[0066] This step builds hierarchical vector representations for different types of knowledge, which enables vectorized index keys to support efficient retrieval based on semantic similarity, and quickly locates relevant content regardless of whether the user's query is a global description or a specific question. At the same time, fragment-level and sentence-level knowledge provide contextual information, and title-level and question-level knowledge supplement the core summary, thus building a hierarchical knowledge base that can adapt to a variety of query needs.
[0067] S104. Store the first vector and the second vector in a vector database respectively, and store the index values and index types corresponding to the first vector and the second vector in a relational database to complete the construction of the target large model knowledge base.
[0068] In this step, a hierarchical storage strategy is used to process different types of data separately to complete the construction of the target large model knowledge base. Among them, the vector database is dedicated to storing the semantic vector representation of the knowledge index key, which is convenient for quickly finding the knowledge items most similar to the user query through vector retrieval technology (such as cosine similarity or Euclidean distance). The relational database stores index values (such as text content, table information) and corresponding index types (such as fragments, sentences, titles or questions) in a structured manner as the basic data of the knowledge base. Through the mutual cooperation of the two, the storage efficiency and retrieval performance of the knowledge base are significantly improved, and the rapid semantic matching of user queries and knowledge index keys is achieved. It performs well especially when processing massive categorical data, and has both high efficiency and flexibility, providing a good architectural foundation for the expansion and optimization of the knowledge base.
[0069] The above shows and describes the basic principles, main features and advantages of the present invention. It should be understood by those skilled in the art that the present invention is not limited to the above embodiments, and the above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention to be protected. The scope of protection of the present invention is defined by the attached claims and their equivalents.
Claims
1. A large model knowledge base retrieval method based on multi-granularity retrieval, characterized in that: Includes steps: S1. Construct a knowledge base based on knowledge at three levels: title, segment and sentence, wherein the knowledge base includes a vector database storing a first vector and a second vector, and a relational database storing index values and index types corresponding to the first vector and the second vector; the first vector represents an index key of segment-level knowledge and / or sentence-level knowledge, and the second vector represents an index key of title-level knowledge and / or question-level knowledge; S2. Generate a vector value of the user query using the vector model, search for several query index vectors with the highest similarity to the query vector value in the first vector and the second vector respectively, and obtain the query index value and the query index type corresponding to the query index vector in the relational database as a candidate search result; S3. Construct a query prompt word together with several candidate search results and the user query, and input it into the large model to obtain the final query answer.
2. The large model knowledge base retrieval method based on multi-granularity retrieval as claimed in claim 1, characterized in that: The method for constructing the knowledge base includes: S101. Obtain the target text and parse the document structure, split and reorganize the text data according to the three levels of title, fragment and sentence, and construct knowledge at three levels of title, fragment and sentence; each level of knowledge includes index key, index value and index type; S102. Use a large language model to construct a generative index based on sentence-level knowledge as question-level knowledge; S103. Generate a first vector of index keys representing segment-level knowledge and / or sentence-level knowledge, and a second vector of index keys representing title-level knowledge and / or question-level knowledge using a vector model; S104. Store the first vector and the second vector in a vector database respectively, and store the index values and index types corresponding to the first vector and the second vector in a relational database to complete the construction of the target large model knowledge base.
3. The large model knowledge base retrieval method based on multi-granularity retrieval as claimed in claim 2, characterized in that: The step S101 includes: S1011. Obtain the target text and parse the document structure, traverse and obtain the type and content of each paragraph; S1012. For paragraphs of the title type, the title content is used as the index key, and the text contained in the title, the sub-title, and the text contained in the sub-title are sequentially spliced as the index value to construct title-level knowledge; S1013. For paragraphs of type body, the body content is used as index key and index value respectively to construct fragment-level knowledge; S1014. The paragraphs of the text type are segmented by periods to obtain sentences, and the content of each sentence is used as an index key and an index value to construct sentence-level knowledge.
4. The large model knowledge base retrieval method based on multi-granularity retrieval as claimed in claim 2, characterized in that: The step S102 includes: S1021. Use the large language model to extract each knowledge point in the given text sentence sample and generate several related questions; S1022. Filter the best question with the highest matching degree with the knowledge point, and concatenate the given text sentence sample and the best question corresponding to each knowledge point and add them to the prompt word as an example; S1023. Use the prompt words to guide the large language model to output a number of generative indexes based on each sentence-level knowledge, use the generative index as the index key, and use the content of the sentence-level knowledge as the index value to construct question-level knowledge.
5. The large model knowledge base retrieval method based on multi-granularity retrieval as claimed in claim 1, characterized in that: The method for obtaining the query index vector includes: S201. Generate a vector value of the user query using a vector model, traverse and calculate the similarity with the vector value in the first vector and the second vector, respectively obtain a number of first vector query results and second vector query results that meet the preset similarity threshold requirements, and merge them into a query index vector.
6. The large model knowledge base retrieval method based on multi-granularity retrieval as claimed in claim 5, characterized in that: The method for obtaining the candidate search results includes: S202. Obtaining the index value and index type corresponding to the query index vector in the relational database, and sorting the index value into a title index value, a fragment index value, a sentence index value, and a question index value according to the index type; S203. De-duplicate the index values according to the ranking, build a knowledge candidate pool based on the de-duplicate index values, and calculate the ranking score of each index value in the knowledge candidate pool with respect to the user query; S204. Perform weighted calculation on the vector similarity and ranking score corresponding to each index value in the knowledge candidate pool, and select several query index values with top ranking in the calculation results as candidate retrieval results.
7. The large model knowledge base retrieval method based on multi-granularity retrieval as claimed in claim 6, characterized in that: The method for removing duplicate index values by sorting includes: The indexes are placed in the knowledge candidate pool one by one in the order of index type: title, fragment, sentence and question, and it is traversed to see whether there is an inclusion relationship between the current index value and the remaining index values in the knowledge candidate pool. If not, the current index value is retained; if so, the vector similarity between the current index value and the comparison index value in the knowledge candidate pool that has an inclusion relationship and the user query is compared respectively. If the former is larger, the comparison index value is replaced by the current index value; if the latter is larger, the current index value is discarded.
Citation Information
Patent Citations
Retrieval method and device of knowledge base and storage medium
CN116756295A
Knowledge graph-based cue word generation method and device for vector similarity search
CN118210889A
Intelligent document query method and system for enterprise knowledge base
CN118779404A
Domain speech recognition method and system based on RAG
CN119296516A
Cited By
Knowledge base construction method and device and knowledge question and answer processing method and device
CN120373439A
Dynamic knowledge retrieval enhancement method based on large language model
CN120407570A
A method for dynamic knowledge retrieval enhancement based on large language model
CN120407570B
Standard query method and device, equipment, medium and product
CN120705331A
Double-granularity text retrieval method based on atomic sentences
CN120821825A