A knowledge retrieval enhancement generation method and system based on hierarchical document indexing

CN122964050APending Publication Date: 2026-10-23BANK OF GUIYANG CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611300377.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-26
Publication Date
2026-10-23

AI Technical Summary

Technical Problem

[0009]其四,固定Top-K检索方式难以充分利用模型上下文

Benefits of technology

原文回源与上下文构建模块,用于根据所述候选章节节点集合中各章节节点的起始物理页码及结束物理页码,从所述文档的原始文件中提取对应页码范围内的完整连续原文内容,基于提取的原文内容构建输入上下文;

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122964050A_ABST
    Figure CN122964050A_ABST
Patent Text Reader

Abstract

The application discloses a knowledge retrieval enhancement generation method and system based on hierarchical document index, and relates to the technical fields of artificial intelligence and retrieval enhancement generation. The method comprises the following steps: analyzing a document structure to construct a hierarchical document index tree, wherein each chapter node in the tree comprises a node unique identifier, a starting page number and an ending page number; combining the text of the same chapter into a knowledge slice by taking the page number as a constraint, wherein the slice inherits the node unique identifier, and a vector index and a BM25 keyword index are constructed according to the node unique identifier and are stored in association with the node unique identifier; after receiving a user question, performing vector semantic retrieval and keyword retrieval respectively, extracting the node unique identifier associated with the slice in the retrieval result, and aggregating the slices belonging to the same chapter node; extracting complete original text from the original document according to the page number of the candidate chapter node to construct a context; and inputting the context and the user question into a large language model to generate an answer. The application can maintain the semantic integrity of chapters, improve the traceability of knowledge and the accuracy of retrieval.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of artificial intelligence and retrieval enhancement generation technology, and more specifically to a knowledge retrieval enhancement generation method and system based on hierarchical document indexing. Background Technology

[0002] With the rapid development of large language model technology, it has been widely applied in fields such as natural language understanding, intelligent question answering, intelligent operation and maintenance, and knowledge management. However, since the knowledge of large language models mainly comes from the pre-training stage, it has characteristics such as staticity and limited domain coverage. When the model processes professional technical knowledge such as internal enterprise knowledge, industry standards, product manuals, and database operation and maintenance documents, it is prone to problems such as knowledge gaps, inaccurate answers, and model illusions.

[0003] To enhance the application capabilities of large language models in specialized knowledge domains, Retrieval-Augmented Generation (RAG) technology has emerged. RAG technology retrieves relevant knowledge from external knowledge bases before generating a response and inputs this knowledge as context into the large language model. This allows the model to combine external knowledge to complete the response, thereby improving the accuracy and traceability of the answer.

[0004] Currently, existing RAG systems typically consist of a knowledge index building phase and a knowledge retrieval generation phase. In the knowledge index building phase, after parsing the uploaded document, the system segments it into multiple text fragments according to preset rules (such as fixed character length, fixed token length, or sliding window). Then, a vector representation is generated for each text fragment, and a vector index is established. Some systems also build a BM25 full-text search index. In the knowledge retrieval generation phase, the system converts the user's question into a query vector and retrieves the top-K most similar text fragments from the vector database, or obtains matching results through BM25 keyword search. Some systems use a hybrid search method to merge the two search results. Finally, the retrieved text fragments are concatenated and input into a large language model to generate an answer.

[0005] However, existing RAG systems still have the following shortcomings:

[0006] First, document slicing leads to the loss of chapter semantic structure. Existing technologies typically slice documents based on text length rather than the original chapter structure, resulting in a chapter being split into multiple independent segments, or the same segment containing content from multiple chapters. Slicing no longer preserves the complete chapter context, easily causing semantic fragmentation and cross-chapter references in answers.

[0007] Secondly, the search results lack the ability to locate chapters and trace back to the original text. In existing technologies, text slicing usually only preserves simple metadata such as the source document name and page number, which cannot accurately locate the chapter to which the search results belong. It is difficult to trace the search results back to the exact location of the original document, reducing the verifiability and traceability of the answers.

[0008] Third, a single retrieval method struggles to simultaneously address semantic understanding and technical identifier matching. Vector retrieval is weak in accurately matching technical identifiers such as database parameters, configuration items, and error codes, while BM25 retrieval lacks semantic understanding of synonyms and natural language descriptions. In existing hybrid retrieval methods, the two types of search results remain at the text fragment level, lacking a unified knowledge organization unit for effective fusion.

[0009] Fourth, fixed Top-K retrieval methods fail to fully utilize model context. Existing technologies typically use a fixed Top-K approach to select knowledge fragments without considering the differences in contextual requirements between different questions. Complex questions may lack sufficient knowledge, while simple questions may introduce a large amount of low-relevance content. Furthermore, the lack of unified organization among multiple text fragments easily leads to context fragmentation.

[0010] Therefore, there is an urgent need in this field for a knowledge retrieval enhancement generation method that can fully utilize the hierarchical structure of document chapters, achieve chapter-level knowledge location and original text retrieval, and take into account the advantages of semantic retrieval and keyword matching. Summary of the Invention

[0011] In view of the above problems, the present invention is proposed to provide a knowledge retrieval enhancement generation method based on hierarchical document indexing that overcomes or at least partially solves the above problems.

[0012] To achieve the above objectives, the present invention adopts the following technical solution: The document is retrieved, its structure is parsed to identify the chapter hierarchy, and a hierarchical document index tree is constructed accordingly. Each node in the hierarchical document index tree corresponds to a chapter node, and the chapter node contains at least a unique node identifier, a starting physical page number, and an ending physical page number. Using the starting and ending physical page numbers as physical constraints, the main text content belonging to the same chapter node page number range is combined into at least one knowledge slice, and each knowledge slice inherits the unique node identifier of the chapter node to which it belongs; a vector index and a BM25 keyword index are constructed based on the knowledge slice, and both the vector index and the BM25 keyword index are associated and stored with the corresponding unique node identifier; The system receives user questions, performs vector semantic retrieval based on the vector index, and performs keyword retrieval based on the BM25 keyword index to obtain corresponding retrieval results; it extracts the unique identifier of the node associated with each knowledge slice in each retrieval result, and aggregates knowledge slices belonging to the same chapter node to form a candidate chapter node set; Based on the starting and ending physical page numbers of each chapter node in the candidate chapter node set, extract the complete and continuous original text content within the corresponding page number range from the original file of the document, and construct the input context based on the extracted original text content; The input context and the user question are input into the large language model to generate and output the final answer.

[0013] Preferably, constructing the hierarchical document index tree includes: identifying chapter levels based on the document's directory information and main text title features, wherein the method for identifying chapter levels includes at least one of directory parsing, title style recognition, numbering rule matching, and text feature analysis, and establishing parent-child relationships between chapters based on the recognition results; When there is a discrepancy between the table of contents page numbers and the actual page numbers in the main text, the starting and ending page numbers of the chapter nodes are corrected through a title matching and page number verification mechanism.

[0014] Preferably, the chapter node includes: chapter title, chapter level, document number, parent node number, and set of child nodes.

[0015] Preferably, it also includes structure index retrieval: Based on the hierarchical document index tree, semantic matching of the chapter index is performed according to the user question. The chapter title, chapter summary and hierarchical relationship are comprehensively analyzed, the correlation between each chapter node and the user question is calculated, and a set of candidate chapter nodes is output. When forming the candidate chapter node set, knowledge slices belonging to the same chapter node from the structural index retrieval results, vector semantic retrieval results, and BM25 keyword retrieval results are aggregated under that chapter node.

[0016] Preferably, after receiving the user's input question, the process also includes understanding the user's question: The intent of the user's question is identified using a large language model. The user's question is identified as belonging to at least one of the following categories: professional field, technical topic, configuration parameter query, fault handling process, SQL statement related question, operation and maintenance guidance, product function description and API interface description. The user's question is also identified as belonging to at least one of the following categories: product name, database type, version number, configuration parameters, error code, command and SQL keyword. The query is expanded to generate a standardized retrieval request; the query expansion includes at least one of the following processing methods: adding technical terms or synonyms, standardizing technical identifier names, adding contextual information to improve semantic integrity, and retaining original technical parameters and commands.

[0017] Preferably, it further includes: A retrieval planning strategy is generated based on the results of intent recognition and the query pattern selected by the user. When the user selects quick query, the vector semantic retrieval and the keyword retrieval are executed; When a user selects in-depth analysis, a structural index retrieval is added to the vector semantic retrieval and keyword retrieval.

[0018] Preferably, context capacity control is included before constructing the input context: Set a relevance threshold for chapter nodes, and retain only candidate chapter nodes whose relevance is higher than the relevance threshold; The length of the original text corresponding to each candidate chapter node is accumulated sequentially according to the order of relevance from high to low, until the accumulated length reaches the upper limit of the input length allowed by the large language model, at which point loading stops.

[0019] Preferably, after forming the candidate chapter node set, the method further includes performing the following verification on each chapter node in the candidate chapter node set: Chapter hierarchy parent-child relationship validation checks whether the parent-child relationship of chapter nodes in the document hierarchy is complete. Page number boundary integrity check verifies whether the start and end page numbers of each chapter node are complete; Node content integrity verification checks whether the chapter summary, main text content, and page number information are complete. Based on the above verification results, filter out the chapter nodes that fail the verification.

[0020] Preferably, when extracting complete and continuous original text content within a corresponding page number range from the original file of the document, for chapters spanning multiple pages, the main text content is extracted continuously according to the chapter boundaries; the complete and continuous original text content includes at least one of the main text, tables, code examples, and configuration lists corresponding to the chapter nodes; When generating and outputting the final answer, the knowledge source information corresponding to the final answer is also output. The knowledge source information includes the document name, chapter title and page number range corresponding to the chapter node.

[0021] Based on the same inventive concept, this invention also provides a knowledge retrieval enhancement generation system based on hierarchical document indexing, used to execute any of the above-described knowledge retrieval enhancement generation methods, including: The document parsing and index building module is used to parse the document structure to identify the chapter hierarchy, and build a hierarchical document index tree accordingly; each node in the hierarchical document index tree corresponds to a chapter node, and the chapter node contains at least a unique node identifier, a starting physical page number, and an ending physical page number; The dual-index construction module is used to combine the main text content belonging to the same chapter node page number range into at least one knowledge slice, using the starting physical page number and the ending physical page number as physical constraints, and each knowledge slice inherits the node unique identifier of the chapter node to which it belongs; based on the knowledge slice, a vector index and a BM25 keyword index are constructed, and both the vector index and the BM25 keyword index are associated and stored with the corresponding node unique identifier; The multi-path retrieval and node aggregation module is used to receive user input questions, perform vector semantic retrieval based on the vector index, and perform keyword retrieval based on the BM25 keyword index to obtain the corresponding retrieval results; extract the unique identifier of the node associated with each knowledge slice in each retrieval result, and aggregate the knowledge slices belonging to the same chapter node to form a candidate chapter node set; The original text retrieval and context construction module is used to extract complete and continuous original text content within the corresponding page range from the original file of the document based on the starting physical page number and ending physical page number of each chapter node in the candidate chapter node set, and construct the input context based on the extracted original text content; An enhanced generation module is used to input the input context and the user question into a large language model, generate and output the final answer.

[0022] The beneficial effects of the above-described technical solutions provided in the embodiments of the present invention include at least the following: (i) Maintain the semantic integrity of the chapters.

[0023] A hierarchical document index tree is constructed, with chapter nodes as the knowledge organization unit and chapter boundaries as constraints to generate knowledge slices. This enables knowledge retrieval to make full use of the chapter hierarchy, effectively maintain the semantic integrity of chapters, and avoid the semantic fragmentation problem caused by traditional slicing methods.

[0024] (ii) Improve knowledge traceability.

[0025] Establish a mapping relationship between chapter nodes and the physical page numbers of the original document, and extract the content of the original document based on the chapter nodes. This allows the generated answers to be associated with the document name, chapter title, and page number range, making it easier for users to quickly locate and verify the source of knowledge.

[0026] (iii) Achieve complementary advantages of multi-path retrieval.

[0027] By combining vector semantic retrieval with BM25 keyword retrieval, both types of indexes are stored in association with the unique identifier of the chapter node, enabling the results of different retrieval methods to be uniformly aggregated at the chapter node level, taking into account both semantic understanding capabilities and the matching accuracy of professional technical identifiers.

[0028] (iv) Improve the quality of the context.

[0029] By using chapter nodes as a unified knowledge organization object, node aggregation is performed on multi-path retrieval results, and context is constructed based on the original documents from the chapter nodes. This makes the knowledge content of the input large language model have better continuity and completeness, and avoids context fragmentation caused by fixed Top-K fragment splicing.

[0030] (v) Ensure the verifiability of the answer.

[0031] After determining the candidate chapter nodes, the complete original text content is extracted from the original document based on the page number information to construct the context. This enables the large language model to generate answers based on the original document, fundamentally avoiding information loss and context breakage caused by slicing and splicing, and improving the accuracy and verifiability of the generated answers. Attached Figure Description

[0032] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0033] Figure 1 This is a flowchart of a knowledge retrieval enhancement generation method based on hierarchical document indexing provided in an embodiment of the present invention; Figure 2 This is a flowchart of multi-path collaborative knowledge retrieval and node aggregation under the deep analysis mode provided in this embodiment of the invention; Figure 3 This is a framework diagram of a knowledge retrieval enhancement generation system based on hierarchical document indexing provided in an embodiment of the present invention. Detailed Implementation

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

[0035] Example 1 This invention discloses a knowledge retrieval enhancement generation method based on hierarchical document indexing, comprising: The document is retrieved, its structure is parsed to identify the chapter hierarchy, and a hierarchical document index tree is constructed accordingly. Each node in the hierarchical document index tree corresponds to a chapter node, and each chapter node contains at least a unique node identifier, a starting physical page number, and an ending physical page number. Using the starting and ending physical page numbers as physical constraints, the main text content belonging to the same chapter node page number range is grouped into at least one knowledge slice, and each knowledge slice inherits the node unique identifier of its respective chapter node; a vector index and a BM25 keyword index are constructed based on the knowledge slices, and both the vector index and the BM25 keyword index are associated and stored with the corresponding node unique identifier; The system receives user questions, performs vector semantic retrieval based on the vector index, and performs keyword retrieval based on the BM25 keyword index to obtain the corresponding search results; it extracts the unique identifiers of the nodes associated with each knowledge slice in each search result, and aggregates the knowledge slices belonging to the same chapter node to form a candidate chapter node set; Based on the starting and ending physical page numbers of each chapter node in the candidate chapter node set, extract the complete and continuous original text content within the corresponding page number range from the original document file, and construct the input context based on the extracted original text content; Input the context and user question into a large language model to generate and output the final answer.

[0036] The following is combined with Figure 1 The present invention will be described in detail below: Step S1: Perform document parsing and identify chapter levels to build a hierarchical document index tree. First, the document to be used to build the knowledge base is obtained. The document can be in PDF, Word, Markdown, HTML, or TXT format, etc. For scanned documents, the text content is extracted using OCR recognition. The system then calls a PDF parser to parse the PDF document, extracting basic document information (including document name, version number, file type, etc.), table of contents, document text, page numbers, heading levels, and optional charts and attachments. After parsing, a unified document object is formed.

[0037] After obtaining a unified document object, the document is classified into chapters based on the table of contents information and the characteristics of the main text headings, automatically establishing the document's hierarchical structure. Specifically, chapter identification utilizes the following methods: table of contents parsing to obtain the chapter titles and their corresponding page numbers; heading style identification to determine the heading level by recognizing the style characteristics of headings in the main text; numbering rule matching to determine the heading level by matching the format rules of chapter numbers; and text feature analysis to determine the heading level by comprehensively analyzing the layout characteristics of the headings. Through these methods, first-level headings, second-level headings, third-level headings, and more granular chapters are identified, and parent-child relationships between chapters are established.

[0038] Subsequently, a hierarchical document index tree is constructed, organized by chapter. Each chapter in the tree corresponds to a unique chapter node, and the nodes are connected through parent-child relationships to form a complete chapter tree structure. Each chapter node contains at least the following attributes:

[0039] Chapter summaries can be extracted through rules or generated by calling a large language model, and are used for subsequent document filtering and structure retrieval. When there is a discrepancy between the table of contents page numbers and the actual page numbers in the main text, the chapter positions are corrected through title matching and page number verification mechanisms.

[0040] In this way, the document is transformed from traditional linear text into a hierarchical tree structure, providing a structural foundation for subsequent page number mapping and knowledge slicing.

[0041] Step S2: Establish the mapping relationship between chapter nodes and physical page numbers After constructing the hierarchical document index tree and obtaining the starting and ending page numbers of each chapter node, a mapping relationship between chapter nodes and physical page numbers is established to achieve accurate location of knowledge content and backtracking of the original text. Specifically, based on the table of contents page number, the position of the main text title, and the chapter boundaries, the corresponding starting and ending page numbers are determined for each chapter node. When there is a discrepancy between the table of contents page number and the actual page number in the main text, the chapter position is corrected through a title matching and page number verification mechanism to ensure that the chapter node is consistent with the actual document content.

[0042] Based on this, the content of each page of the document is mapped to its finest-grained chapter node, enabling subsequent search results to accurately locate specific chapters and supporting the retrieval of the original content within the corresponding page range based on the chapter node. After the mapping is completed, the mapping relationship is stored in the StartPage and EndPage properties of the chapter node for subsequent original text retrieval steps.

[0043] Step S3: Generate knowledge slices and construct dual indexes using chapter boundaries as constraints. After establishing the mapping relationship between chapter nodes and physical page numbers, the text content belonging to the same chapter node's page number range is grouped into at least one knowledge slice, using the start and end physical page numbers as physical constraints. For each chapter node, based on its StartPage and EndPage, all text content within that page number range is extracted from the document object, and the text within that range is sliced ​​according to a preset slicing strategy. The slicing strategy can use fixed character length slices, fixed token length slices, sliding window slices, or natural paragraph slices. Regardless of the slicing strategy used, each knowledge slice inherits the NodeID of its respective chapter node as metadata. Each knowledge slice stores at least the following metadata: slice content, NodeID, DocumentID, slice number, start page number, and end page number.

[0044] After slicing, each knowledge slice carries a unique identifier for its corresponding chapter node. Based on this, a vector index and a BM25 keyword index are simultaneously constructed based on the knowledge slices, and both types of indexes are associated and stored with the corresponding node's unique identifier. The vector index is constructed as follows: The embedding model is invoked to convert the text content of each knowledge slice into a corresponding vector representation. This vector data is then stored in a vector database, and a vector index is created. Each vector data is associated with its corresponding NodeID. The embedding model can be a BGE series model, E5 series model, GTE series model, or M3 series model. The vector database can be Milvus, FAISS, Elasticsearch Vector, OpenSearch, or pgvector.

[0045] The BM25 index is constructed as follows: a full-text search engine is used to segment knowledge slices, count term frequencies and inverse document frequencies, build an inverted index, and associate index entries with their corresponding NodeIDs for storage. The full-text search engine can be Lucene, Elasticsearch, or OpenSearch.

[0046] The vector index and the BM25 index are linked using a unified NodeID, enabling the fusion of the two types of search results at the chapter node level. This completes the construction of the professional technical document knowledge index, which can then be used for subsequent user problem understanding and multi-path knowledge retrieval steps.

[0047] Step S4: Understand the user's question and generate a search planning strategy After the knowledge index is built, when a user inputs a natural language question through the knowledge question-answering system, the system performs a unified understanding of the user's question and generates a more suitable query expression for knowledge retrieval. User questions can be, for example, database operation and maintenance issues, configuration parameter queries, troubleshooting procedures, product function descriptions, or technical specification queries. First, a large language model is used to identify the intent of the user's question, including identifying at least one of the following: the question's professional field, technical topic, configuration parameter query, troubleshooting procedure, SQL statement related questions, operation and maintenance guidance, product function description, or API interface description. Simultaneously, it identifies professional technical identifiers involved in the user's question, such as product name, database type, version number, configuration parameters, error codes, commands, and SQL keywords.

[0048] Next, after obtaining the technical topic and professional technical identifiers of the user's question through intent recognition, the user's question is expanded to generate a standardized query expression more suitable for knowledge retrieval. Query expansion includes at least one of the following processing methods: Supplement with professional terminology or synonyms; Standardize the names of database objects, configuration items, and technical identifiers; Supplementing contextual information improves the semantic completeness of queries; Eliminate colloquialisms to improve search accuracy; Retain the original technical parameters, commands, product names, and other key identifiers.

[0049] For example, if a user enters "How to configure HA", the query will be expanded to generate "Database High Availability (HA) configuration methods, master-slave switchover configuration and related parameter descriptions"; if a user enters "What does calc_as_decimal mean", the parameter name "calc_as_decimal" will be retained and its product and function description will be added.

[0050] After receiving a standardized search request, the search planning module generates a corresponding search strategy based on the query mode selected by the user.

[0051] When a user selects a quick query, vector semantic search and BM25 keyword search are performed first to quickly obtain candidate knowledge with lower search overhead. When users select in-depth analysis, in addition to vector semantic retrieval and BM25 keyword retrieval, chapter index tree retrieval is added to analyze the document structure and further enhance the ability to locate knowledge of complex issues.

[0052] The retrieval planning module centrally schedules subsequent retrieval processes, including determining retrieval paths, invoking corresponding retrieval modules, and controlling the fusion method of retrieval results. After generating the retrieval planning strategy, the strategy instructions are issued to each retrieval module to execute multi-path knowledge retrieval.

[0053] Step S5: Perform multi-path collaborative knowledge retrieval After the retrieval planning strategy is distributed to each retrieval module, this application performs multi-path collaborative knowledge retrieval, with each retrieval proceeding in parallel.

[0054] The first approach involves performing a structural index retrieval based on the hierarchical document index tree, semantically matching the chapter index according to the user's question.

[0055] Specifically, semantic similarity is calculated between user questions and expanded query results and the titles and / or summaries of each chapter node. A comprehensive analysis of chapter titles, summaries, and hierarchical relationships is performed to calculate the relevance between each chapter node and the user question, and a candidate chapter node set is output. Since the data size of the structured index is much smaller than the original full-text document, document structure analysis can be completed quickly with low computational overhead. For scenarios with large document sizes, the index can be segmented according to the chapter tree structure, and structured index analysis can be completed using controlled concurrency.

[0056] The second approach involves performing vector semantic retrieval based on vector indexes.

[0057] Specifically, the same embedding model used in the knowledge index building phase is invoked to convert the expanded query question into a query vector. The similarity between the query vector and all knowledge slice vectors in the knowledge base is calculated in the vector database. Similarity calculation methods can include cosine similarity, inner product, or Euclidean distance. The top-K knowledge slices are returned based on their similarity scores. Since each knowledge slice carries the NodeID of its respective chapter node, the results obtained from vector retrieval can be directly mapped to the corresponding chapter node. Vector retrieval is primarily used to handle semantically related issues such as concept explanations, technical principles, functional descriptions, and synonym expressions.

[0058] The third approach involves performing keyword retrieval based on the BM25 keyword index. Specifically, user questions are segmented into words, retaining technical identifiers such as database object names, configuration parameters, system views, error codes, commands, and SQL keywords. The BM25 algorithm is used to calculate the relevance score between keywords and knowledge slices in the knowledge base, and the top-K knowledge slices are returned based on the scores. Each knowledge slice is associated with the NodeID of its respective chapter node, so the BM25 search results are ultimately mapped to the corresponding chapter node. BM25 search is mainly used for scenarios requiring precise matching, such as parameter queries, error code queries, and command descriptions.

[0059] After the above three-way search is completed, the search results of each way will be output to the node aggregation step according to the corresponding search strategy.

[0060] Step S6: Map the multi-path search results to chapter nodes and perform node validation. After obtaining the search results from each search path, the knowledge slices returned by different search paths are uniformly mapped to their respective chapter nodes, and then aggregated at the chapter node level according to the corresponding search strategy.

[0061] Node aggregation specifically includes the following steps: The process involves mapping search results based on NodeIDs, extracting the NodeIDs associated with each knowledge slice in each search result; merging multiple knowledge slices belonging to the same chapter node, i.e., grouping all knowledge slices with the same NodeID under the corresponding chapter node; removing duplicate chapter nodes, i.e., retaining only one chapter node when multiple search results match the same NodeID; integrating the relevance information of each search path, i.e., combining the relevance scores of each search path for the same chapter node; and generating a unified set of candidate chapter nodes. Through node-level aggregation, the scattered text slices in the traditional RAG system are reorganized into complete chapter knowledge.

[0062] After obtaining the set of candidate chapter nodes, the candidate chapter nodes are uniformly verified to filter out nodes that do not meet the integrity requirements.

[0063] Node verification includes at least one of the following: Chapter hierarchy parent-child relationship verification, that is, checking whether the parent-child relationship of chapter nodes in the document hierarchy is complete, to avoid mixing of knowledge across chapters; Page number boundary integrity verification verifies whether the starting and ending page numbers of each chapter node are complete. When there is a discrepancy between the table of contents page number and the actual page number of the main text, the chapter position is corrected through title matching and page number verification mechanism to ensure the accuracy of knowledge retrieval. Node content integrity verification checks whether the chapter summary, main text, and page number information are complete. Chapter nodes that fail the verification are filtered out.

[0064] After verification, the candidate chapter nodes are uniformly relevance-ranked. The ranking combines the relevance scores of the structural index retrieval results, vector retrieval results, and BM25 retrieval results to form a unified chapter node relevance score. Candidate chapter nodes are then filtered based on the relevance score and a preset threshold, and sorted from highest to lowest relevance. After verification and ranking, the filtered set of candidate chapter nodes is output to the context construction step.

[0065] Combination Figure 2As shown, the retrieval planning module generates a retrieval strategy based on the user-selected query mode (deep analysis) and sends the strategy instructions to each retrieval module to execute multi-path knowledge retrieval. The three-path retrieval—structural index retrieval, vector semantic retrieval, and BM25 keyword retrieval—are performed in parallel. After each retrieval is completed, the retrieval results are output to the node mapping and node aggregation steps. After node mapping, node aggregation, node verification, and relevance ranking, the candidate chapter node set is output to the context construction step.

[0066] It should be noted that when a user selects the quick query mode, structural index retrieval is not performed; only vector semantic retrieval and BM25 keyword retrieval are performed.

[0067] Step S7: Perform chapter node selection and context capacity control, extract complete chapter content from the original document and construct the context. After obtaining the set of verified and sorted candidate chapter nodes, the candidate chapter nodes are first filtered according to the relevance score in order to control the amount of knowledge entering the large language model.

[0068] Specifically, a relevance threshold for chapter nodes is set, retaining only chapter nodes with a relevance higher than the preset threshold to prevent low-quality knowledge from entering the generation stage. Simultaneously, capacity control is applied to candidate chapter nodes based on the context window length supported by the large language model. Capacity control does not employ a fixed Top-K approach, but rather follows this method: The length of the original text corresponding to each candidate chapter node is sequentially accumulated according to their relevance from high to low. Loading stops when the accumulated length reaches the upper limit of the input length allowed by the large language model. This method ensures that the knowledge content entering the context is highly relevant and fully utilizes the context window of the large language model.

[0069] After completing the node selection, the original document is read back from the source based on the Page-Node Mapping information corresponding to the selected chapter node.

[0070] Specifically, based on the start and end page numbers recorded in the chapter nodes, the complete text content within the corresponding page range is extracted from the original document, instead of directly using pre-stored text slices in the knowledge base. For chapters spanning multiple pages, the text content is extracted continuously along the chapter boundaries to ensure the integrity of the chapter content. For chapters containing special content such as charts, code examples, and configuration lists, the corresponding content is extracted simultaneously to preserve the semantic integrity of the original document.

[0071] After obtaining the complete chapter content extracted from the source, the content of each chapter is uniformly organized according to the chapter hierarchy and knowledge organization rules to form contextual information for use by the large language model. During context construction, information such as chapter titles, chapter levels, page ranges, and main text content is retained. When multiple chapters enter the context simultaneously, they are sorted according to chapter relevance and document level, maintaining the continuity of chapter content and avoiding semantic fragmentation caused by cross-mixing of different chapter content. Simultaneously, to prevent the context length from exceeding the model input limit, the context content is dynamically pruned according to the maximum input length supported by the model.

[0072] After completing the context construction, the user question, contextual knowledge, and system prompts are assembled to form the final prompt words for the large input language model. The prompt words mainly include the following: The system includes roles and answer requirements, the user's original question, expanded query results, chapter titles and page numbers, chapter text content, and other auxiliary information. After assembling the prompt words, the prompt words are output to the large language model generation step.

[0073] Step S8: Perform large language model enhancement to generate and output traceable answers. After obtaining the assembled prompts, the prompts are input into a large language model, which then combines this with the retrieved professional knowledge to generate the final answer. During the generation process, the large language model primarily relies on the retrieved knowledge content to understand, summarize, reason, and conclude relevant knowledge, and combines this with the user's question to generate an accurate, complete answer that fits the professional technical scenario. When generating the final answer, the model also outputs the knowledge source information corresponding to the final answer, including the document name, chapter title, and page range corresponding to the chapter node, allowing the user to quickly locate the original document to verify the answer content.

[0074] Example 2 Combination Figure 3 As shown, based on the same inventive concept, this invention also provides a knowledge retrieval enhancement generation system based on hierarchical document indexing, used to execute any of the above-described knowledge retrieval enhancement generation methods, including: The document parsing and index building module is used to parse the document structure to identify the chapter hierarchy, and build a hierarchical document index tree accordingly. Each node in the hierarchical document index tree corresponds to a chapter node, and the chapter node contains at least a unique node identifier, the starting physical page number, and the ending physical page number. The dual-index construction module is used to combine the main text content belonging to the same chapter node page number range into at least one knowledge slice, using the start physical page number and end physical page number as physical constraints. Each knowledge slice inherits the node unique identifier of its respective chapter node. Based on the knowledge slice, a vector index and a BM25 keyword index are constructed, and both the vector index and the BM25 keyword index are associated and stored with the corresponding node unique identifier. The multi-path retrieval and node aggregation module is used to receive user input questions, perform vector semantic retrieval based on vector index, and perform keyword retrieval based on BM25 keyword index to obtain the corresponding retrieval results; extract the unique identifier of the node associated with each knowledge slice in each retrieval result, and aggregate the knowledge slices belonging to the same chapter node to form a candidate chapter node set; The original text retrieval and context construction module is used to extract complete and continuous original text content within the corresponding page range from the original document based on the starting and ending physical page numbers of each chapter node in the candidate chapter node set, and construct the input context based on the extracted original text content; The enhanced generation module is used to input the input context and user question into the large language model, generate and output the final answer.

[0075] Those skilled in the art will understand that the large language models in the above embodiments include, but are not limited to, GPT series models, Claude series models, LLaMA series models, Wenxin Yiyan, Tongyi Qianwen, ChatGLM, etc. Embedding models include, but are not limited to, BGE series models, E5 series models, GTE series models, M3 series models, etc. Vector databases include, but are not limited to, Milvus, FAISS, Elasticsearch Vector, OpenSearch, pgvector, etc. Full-text search engines include, but are not limited to, Lucene, Elasticsearch, OpenSearch, etc.

[0076] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section.

[0077] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A knowledge retrieval enhancement generation method based on hierarchical document indexing, characterized in that, include: Obtain the document, parse the document structure to identify the chapter hierarchy, and build a hierarchical document index tree accordingly; Each node in the hierarchical document index tree corresponds to a chapter node, and the chapter node contains at least a unique node identifier, a starting physical page number, and an ending physical page number. Using the starting and ending physical page numbers as physical constraints, the main text content belonging to the same chapter node page number range is combined into at least one knowledge slice, and each knowledge slice inherits the unique node identifier of the chapter node to which it belongs; a vector index and a BM25 keyword index are constructed based on the knowledge slice, and both the vector index and the BM25 keyword index are associated and stored with the corresponding unique node identifier; The system receives user questions, performs vector semantic retrieval based on the vector index, and performs keyword retrieval based on the BM25 keyword index to obtain corresponding retrieval results; it extracts the unique identifier of the node associated with each knowledge slice in each retrieval result, and aggregates knowledge slices belonging to the same chapter node to form a candidate chapter node set; Based on the starting and ending physical page numbers of each chapter node in the candidate chapter node set, extract the complete and continuous original text content within the corresponding page number range from the original file of the document, and construct the input context based on the extracted original text content; The input context and the user question are input into the large language model to generate and output the final answer.

2. The method according to claim 1, characterized in that, Constructing the hierarchical document index tree includes: identifying chapter levels based on the document's directory information and main text title features. The methods for identifying chapter levels include at least one of directory parsing, title style recognition, numbering rule matching, and text feature analysis. Parent-child relationships between chapters are established based on the recognition results. When there is a discrepancy between the table of contents page numbers and the actual page numbers in the main text, the starting and ending page numbers of the chapter nodes are corrected through a title matching and page number verification mechanism.

3. The method according to claim 1, characterized in that, The chapter nodes include: chapter title, chapter level, document number, parent node number, and set of child nodes.

4. The method according to claim 1, characterized in that, It also includes structure index retrieval: Based on the hierarchical document index tree, semantic matching of the chapter index is performed according to the user question. The chapter title, chapter summary and hierarchical relationship are comprehensively analyzed, the correlation between each chapter node and the user question is calculated, and a set of candidate chapter nodes is output. When forming the candidate chapter node set, knowledge slices belonging to the same chapter node from the structural index retrieval results, vector semantic retrieval results, and BM25 keyword retrieval results are aggregated under that chapter node.

5. The method according to claim 1, characterized in that, After receiving the user's input question, the process also includes understanding the user's question: The intent of the user's question is identified using a large language model. The user's question is identified as belonging to at least one of the following categories: professional field, technical topic, configuration parameter query, fault handling process, SQL statement related question, operation and maintenance guidance, product function description and API interface description. The user's question is also identified as belonging to at least one of the following professional technical identifiers: product name, database type, version number, configuration parameters, error code, command and SQL keyword. The query is expanded to generate a standardized retrieval request; the query expansion includes at least one of the following processing methods: adding technical terms or synonyms, standardizing technical identifier names, adding contextual information to improve semantic integrity, and retaining original technical parameters and commands.

6. The method according to claim 5, characterized in that, Also includes: A retrieval planning strategy is generated based on the results of intent recognition and the query pattern selected by the user. When the user selects quick query, the vector semantic retrieval and the keyword retrieval are executed; When a user selects in-depth analysis, a structural index retrieval is added to the vector semantic retrieval and keyword retrieval.

7. The method according to claim 1, characterized in that, Before constructing the input context, context capacity control is also included: Set a relevance threshold for chapter nodes, and retain only candidate chapter nodes whose relevance is higher than the relevance threshold; The length of the original text corresponding to each candidate chapter node is accumulated sequentially according to the order of relevance from high to low, until the accumulated length reaches the upper limit of the input length allowed by the large language model, at which point loading stops.

8. The method according to claim 1, characterized in that, After forming the candidate chapter node set, the following verification is performed on each chapter node in the candidate chapter node set: Chapter hierarchy parent-child relationship validation checks whether the parent-child relationship of chapter nodes in the document hierarchy is complete. Page number boundary integrity check verifies whether the start and end page numbers of each chapter node are complete; Node content integrity verification checks whether the chapter summary, main text content, and page number information are complete. Based on the above verification results, filter out the chapter nodes that fail the verification.

9. The method according to claim 1, characterized in that, When extracting complete and continuous original text content within the corresponding page number range from the original file of the document, for chapters spanning multiple pages, the main text content is extracted continuously according to the chapter boundaries; the complete and continuous original text content includes at least one of the main text, tables, code examples, and configuration lists corresponding to the chapter nodes; When generating and outputting the final answer, the knowledge source information corresponding to the final answer is also output. The knowledge source information includes the document name, chapter title and page number range corresponding to the chapter node.

10. A knowledge retrieval enhancement generation system based on hierarchical document indexing, characterized in that, For performing the method as described in claims 1-9, comprising: The document parsing and index building module is used to parse the document structure to identify the chapter hierarchy, and build a hierarchical document index tree accordingly; each node in the hierarchical document index tree corresponds to a chapter node, and the chapter node contains at least a unique node identifier, a starting physical page number, and an ending physical page number; The dual-index construction module is used to combine the main text content belonging to the same chapter node page number range into at least one knowledge slice, using the starting physical page number and the ending physical page number as physical constraints, and each knowledge slice inherits the node unique identifier of the chapter node to which it belongs; based on the knowledge slice, a vector index and a BM25 keyword index are constructed, and both the vector index and the BM25 keyword index are associated and stored with the corresponding node unique identifier; The multi-path retrieval and node aggregation module is used to receive user input questions, perform vector semantic retrieval based on the vector index, and perform keyword retrieval based on the BM25 keyword index to obtain the corresponding retrieval results; extract the unique identifier of the node associated with each knowledge slice in each retrieval result, and aggregate the knowledge slices belonging to the same chapter node to form a candidate chapter node set; The original text retrieval and context construction module is used to extract complete and continuous original text content within the corresponding page range from the original file of the document based on the starting physical page number and ending physical page number of each chapter node in the candidate chapter node set, and construct the input context based on the extracted original text content; An enhanced generation module is used to input the input context and the user question into a large language model, generate and output the final answer.