A Method for Engineering Knowledge Base Construction and Deep Retrieval
By performing multi-level tree structure recognition and heterogeneous content parsing on engineering knowledge documents, embedding vectors are generated to construct an engineering knowledge base. Furthermore, by optimizing the retrieval process through query rewriting, the problems of granularity mismatch and information ambiguity in engineering knowledge retrieval are solved, achieving high-quality knowledge retrieval results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-29
- Publication Date
- 2026-03-13
Smart Images

Figure CN120893548B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent retrieval technology, and in particular to a method for constructing and deeply retrieving an engineering knowledge base. Background Technology
[0002] Throughout the entire lifecycle of an engineering project, from initial design and construction to post-construction operation and maintenance, technical personnel will raise numerous specialized questions regarding core dimensions such as cost control, quality management, and safety standards. The answers to these questions are often scattered across various engineering documents, including industry standards, technical specifications, project reports, and inspection records. Therefore, efficient and accurate knowledge retrieval technology is urgently needed to support business decision-making.
[0003] Compared to general knowledge retrieval scenarios, knowledge retrieval in the engineering field faces more prominent technical challenges, with the core contradictions manifesting in two aspects: First, the mismatch in granularity. Engineering documents are often written in a systematic chapter structure (such as specifications, technical chapters, etc.), resulting in lengthy documents covering multiple dimensions of content. However, individual queries typically focus on specific technical details, scenario-based problems, or specific indicators, leading to a natural mismatch between the overall document structure and the local query requirements. Second, the ambiguity of information expression. In the engineering field, the same technical concept, indicator, or process often has multiple ways of being expressed (such as professional terms, colloquialisms, scenario-based descriptions, etc.). This semantic diversity significantly increases the difficulty of information matching during the retrieval process.
[0004] Retrieval Augmentation (RAG) technology, as an important retrieval paradigm in the era of large language models, provides a new path for domain knowledge retrieval. Its core mechanism integrates domain knowledge into a large language model through a process of document segmentation, vector mapping, similarity retrieval, and generative augmentation: first, the domain document is split into several knowledge fragments and converted into vectors; then, relevant content is retrieved based on the semantic similarity between the query and the fragments; finally, a generative large model outputs results that are both accurate and comprehensive. Theoretically, RAG technology can alleviate the granularity mismatch problem through domain knowledge injection and reduce the impact of information ambiguity by leveraging the semantic understanding capabilities of large language models.
[0005] However, traditional RAG technology still has significant limitations in practical applications in the engineering field, making it difficult to meet the needs of high-quality retrieval:
[0006] (1) Insufficient quality of knowledge chunking
[0007] Traditional RAG (Research Aggregator) relies on simple segmentation methods with fixed lengths or punctuation order, completely ignoring the inherent hierarchical structure of engineering documents (such as chapter titles, clause levels, etc.). This segmentation model easily leads to two types of problems: First, semantic fragmentation, where logically related content is split into different segments, or unrelated content is merged into the same segment, resulting in a lack of semantic integrity of knowledge fragments; second, single-feature utilization, relying solely on textual semantic features for retrieval, ignoring key structural features such as document chapter relationships and logical structure, thereby interfering with retrieval accuracy and affecting the quality of the final answer.
[0008] (2) Insufficient relevance of the search
[0009] Traditional RAGs directly use the user's original question as the search query, lacking in-depth analysis of the query intent. This "surface matching" model fails to distinguish the relevance between paragraph content and the core query requirements, which may result in key knowledge truly relevant to the user's intent not being retrieved, while irrelevant information is included in the results, reducing the accuracy of the search.
[0010] (3) Insufficient retrieval completeness
[0011] On the one hand, traditional RAGs adopt a one-time search and generate model, lacking iterative optimization and thinking mechanisms for the search process, making it difficult to discover potential knowledge gaps, resulting in the omission of necessary knowledge related to implicit needs; on the other hand, the semantic dimension of a single knowledge fragment is limited, often lacking contextual information such as preconditions and related technical descriptions to support its understanding, while these contexts may contain key related knowledge, ultimately resulting in insufficient semantic completeness of the search results. Summary of the Invention
[0012] To address the aforementioned technical problems, the technical solution adopted by this invention is as follows:
[0013] This invention provides a method for constructing and deeply retrieving an engineering knowledge base, the method comprising the following steps:
[0014] S1, builds an engineering knowledge base based on engineering knowledge documents.
[0015] S2: Upon receiving a user's question, a list of blank knowledge questions is generated by query rewriting. The list is then traversed to retrieve the engineering knowledge base. After knowledge grouping, relevance sorting, and loop termination judgment, a response to the user's question is generated based on the existing knowledge accumulated during the loop after the loop terminates.
[0016] Specifically, S1 includes:
[0017] S11 identifies the knowledge level of each input engineering knowledge document, forming a multi-level tree structure, where the chapter titles and their corresponding chapter contents in the engineering knowledge document constitute the nodes of the multi-level tree structure.
[0018] S12 parses and processes the heterogeneous content of each node to generate knowledge fragments.
[0019] S13 generates embedding vectors for each knowledge fragment based on a combination of path embedding and content embedding.
[0020] S14, store the association relationship between knowledge fragments and nodes, the hierarchical relationship between nodes, the mapping relationship between nodes and source documents, as well as the vector data of knowledge fragments, related information and original information of engineering knowledge documents, to complete the construction of the engineering knowledge base.
[0021] This invention provides a method for constructing and deeply retrieving an engineering knowledge base. The method comprises two core processes: knowledge base construction and deep retrieval. In the knowledge base construction stage, knowledge hierarchy identification is performed on engineering knowledge documents to form a multi-level tree structure with chapter titles and corresponding content as nodes. Heterogeneous content (text, tables, images, etc.) of each node is parsed to generate knowledge fragments. An embedding vector for each knowledge fragment is generated using a combination of path embedding and content embedding, and the relationships between knowledge points, vector data, and original information are stored, completing the knowledge base construction. In the deep retrieval stage, upon receiving a user question, a list of blank knowledge questions is generated through query rewriting. This list is traversed to retrieve information from the knowledge base. The retrieval process is optimized through knowledge grouping, relevance sorting, and loop termination judgment. Finally, based on the accumulated existing knowledge, a traceable and verifiable response is generated and output. This invention improves the reuse efficiency and retrieval accuracy of engineering knowledge through structured knowledge organization, deep parsing of heterogeneous content, and intelligent retrieval optimization.
[0022] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0024] Figure 1 A flowchart illustrating an engineering knowledge base construction and deep retrieval method provided in this embodiment of the invention;
[0025] Figure 2 This is a schematic diagram illustrating the construction of the engineering knowledge base in an embodiment of the present invention. Detailed Implementation
[0026] 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.
[0027] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the description of this invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.
[0028] It should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe the steps as sequential processes, many of these steps can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the steps can be rearranged. A process can be terminated when its operation is complete, but it may also have additional steps not included in the figures. A process can correspond to a method, function, procedure, subroutine, subroutine, etc.
[0029] The present invention aims to establish a high-quality knowledge base in the field of engineering and to enable high-quality retrieval of engineering knowledge, thereby helping to improve the efficiency and quality of knowledge retrieval for engineering professionals.
[0030] The key technical problems to be solved by this invention include: the quality problem of engineering knowledge base, which requires proposing better parsing techniques for knowledge documents in the engineering field, improving the quality of knowledge segmentation and block division, and improving the semantic integrity of knowledge segments; the relevance problem of knowledge retrieval, which requires considering what technologies to implement to ensure that the knowledge retrieval results are highly relevant to the user's query; and the completeness problem of knowledge retrieval, which requires proposing and applying better knowledge retrieval methods to ensure the completeness and sufficiency of the knowledge in the retrieval results, thereby improving the quality of knowledge question answering.
[0031] Based on the fundamental principles of RAG technology, this invention proposes a new technology for constructing and deeply retrieving high-quality knowledge bases for the engineering field. This technology improves the quality of knowledge segmentation in engineering knowledge bases, solves the problem of insufficient knowledge retrieval quality caused by the mismatch between the granularity of queries and engineering knowledge, as well as the inherent ambiguity of information, and enhances the relevance, completeness, and accuracy of knowledge retrieval queries in engineering knowledge bases.
[0032] Furthermore, this invention discloses a method for constructing and deeply retrieving an engineering knowledge base, such as... Figure 1 As shown, the method includes the following steps:
[0033] S1, builds an engineering knowledge base based on engineering knowledge documents.
[0034] Upon receiving a user's question, a list of blank knowledge questions is generated through query rewriting. The list is then traversed to search the engineering knowledge base. After knowledge grouping, relevance sorting, and loop termination judgment, a response to the user's question is generated based on the existing knowledge accumulated during the loop.
[0035] S2: Upon receiving a user's question, a list of blank knowledge questions is generated by query rewriting. The list is then traversed to retrieve the engineering knowledge base. After knowledge grouping, relevance sorting, and loop termination judgment, a response to the user's question is generated based on the existing knowledge accumulated during the loop after the loop terminates.
[0036] Furthermore, such as Figure 2 As shown, S1 specifically includes:
[0037] S11 identifies the knowledge level of each input engineering knowledge document, forming a multi-level tree structure, where the chapter titles and their corresponding chapter contents in the engineering knowledge document constitute the nodes of the multi-level tree structure.
[0038] Engineering knowledge documents refer to various structured or unstructured materials generated throughout the entire lifecycle of engineering fields (such as mechanical engineering, civil engineering, electrical engineering, and software engineering), encompassing stages such as design, research and development, construction, operation and maintenance, acceptance, and technical summaries. These documents serve to carry, record, and transmit engineering expertise. In terms of content type, engineering knowledge documents typically encompass heterogeneous formats, including but not limited to:
[0039] Text-based documents: technical specifications, design specifications, construction plans, process manuals, fault analysis reports, technical disclosure documents, academic papers, patent documents, etc.
[0040] Tables: Engineering parameter tables, material performance data tables, test record tables, schedule tables, etc.;
[0041] Graphics / Images: Design drawings (CAD drawings, BIM model views), flowcharts, schematic diagrams, equipment structure diagrams, experimental data visualization charts, on-site working condition photos, etc.
[0042] Other structured data: such as parameter configuration files exported from engineering databases, data conclusions in simulation analysis reports, etc.
[0043] From the perspective of knowledge attributes, the content carried by engineering knowledge documents has professionalism, hierarchy, and relevance: Professionalism is reflected in the content focusing on professional field knowledge such as engineering technical principles, standards and specifications, and practical experience; Hierarchy is reflected in the fact that documents are usually logically divided by chapters, items, etc. (such as the "chapter - section - article" structure of a manual), forming a natural knowledge hierarchy; Relevance is reflected in the technical dependencies between different documents and chapters (such as the association between design specifications and construction plans, and the association between fault cases and maintenance manuals).
[0044] In this invention, engineering knowledge documents are the core original materials for constructing an engineering knowledge base. Through knowledge level identification, heterogeneous content analysis, and vector representation of them, the structured precipitation and efficient reuse of knowledge are achieved, providing basic data support for knowledge retrieval and decision - making support in the engineering field.
[0045] Specifically, S11 specifically includes:
[0046] S111, extracting chapter titles from engineering knowledge documents through heuristic rules, and the heuristic rules include: judging titles based on the built - in tag attributes of the document, judging titles based on the starting character tags of the titles, and judging titles based on text style features.
[0047] Among them, judging titles based on the built - in tag attributes of the document includes: for docx and doc - type documents, parsing the document structure through the Python package docx to extract the built - in tag attributes of the text lines; if the built - in tag attributes of the text lines are hierarchical title tags such as Heading1, Heading2, etc., directly determine that the text line is the chapter title of the corresponding level.
[0048] Judging titles based on the starting character tags of the titles includes: matching the starting characters of the text lines through regular expressions. If the starting character is a preset title identifier (such as Arabic numerals + decimal point "1.1", Chinese serial numbers "一、" "(1)", English letters "A." "a)", etc.), then determine that the text line is the chapter title.
[0049] Judging titles based on text style features includes: reading text styles for docx and doc documents through the Python package docx, and extracting text styles for pdf files through the Python package pdfplumber; if the font size of the text line is greater than a preset threshold (such as greater than 12 - point font), and has features such as bold and centered alignment, and there are obvious style differences from adjacent text lines, then determine it as the chapter title.
[0050] S112, inputting the extracted chapter titles into a large - language model, and the large - language model constructs a multi - level tree - like structure based on the relative granularity of the chapter titles. Among them, the content between adjacent chapter titles is associated with the corresponding superior chapter title, forming nodes containing chapter titles and their corresponding chapter contents.
[0051] In this embodiment of the invention, the large language model can be, for example, moonshot-v1-auto. The prompt word clearly defines the task requirements: "The following is a list of chapter titles in the document (each title occupies a single line). Please identify the relationships between each level based on the hierarchical logic of the titles and output a tree structure in JSON format. Requirements: The root node key is 'root', containing first-level titles; second-level titles are nested under first-level titles, and so on; the title hierarchy is determined by sequence number and granularity (e.g., '1.1' is a subheading of '1'). Example: [Input Example] → [Output Example]."
[0052] The large language model parses the hierarchical relationship between titles based on prompt words and generates a JSON structure containing the title hierarchy. Based on this JSON structure, the content between adjacent chapter titles is associated with the corresponding parent title node, forming a node of "chapter title + corresponding chapter content", and finally constructing a complete multi-level tree structure.
[0053] S12 parses and processes the heterogeneous content of each node to generate knowledge fragments.
[0054] S12 specifically includes:
[0055] S121. For plain text content in a node, if the text length exceeds p words, it is first split into paragraphs. If the paragraph length still exceeds p words, it is then split into multiple semantically independent knowledge fragments based on paragraph semantics. If the text length does not exceed p words, or the length of a single paragraph after paragraph splitting does not exceed p words, then the text or paragraph is directly treated as a knowledge fragment.
[0056] In this embodiment of the invention, p=512. Through S121, the entire plain text content within a node can be divided into one or more semantically independent knowledge fragments.
[0057] S122, for the table content in the node, extract the column names and row names from the table content and restore the unmerged cell structure. After reconstructing the table content into a standardized Python dictionary format, convert it into JSON data to form a knowledge fragment.
[0058] In this embodiment of the invention, the unmerged cell structure is restored and the content of the merged cells is filled to maintain data integrity. The keys in the Python dictionary format are a combination of "column name-row name" identifiers, and the values are the corresponding cell data.
[0059] S123, For the image content in the node, extract the semantic information from the image content through the visual big model, and use the extracted semantic information as knowledge fragments.
[0060] If a node contains image-formatted content, this step is used for processing. Specifically, the image is extracted separately, prompts are designed, and a large visual model (e.g., qwen2.5-vl-72b) is used to extract the semantic information of the image, converting the original image into semantic information. In an illustrative embodiment, an example prompt is: "You are an image semantic extraction assistant, and you need to complete the following tasks: 1. Describe the image content completely in Chinese, including core elements, layout, and visual focus; 2. Accurately identify and extract all text (including formulas, annotations, and data) in the image; 3. Explain the semantic logic expressed by the image (if it is a flowchart, explain the technical process step by step; if it is a data table, interpret the data relationships; if it is a diagram, explain the principle or structure); 4. If there is key information such as time, location, or event, it needs to be clearly labeled."
[0061] S13 generates embedding vectors for each knowledge fragment based on a combination of path embedding and content embedding.
[0062] In this embodiment of the invention, the embedding vector of each knowledge fragment is generated based on a multi-level tree-structured title hierarchy. Further, S13 specifically includes:
[0063] S131: Starting from the root title of the multi-level tree structure, perform hierarchical traversal and sorting according to the parent-child relationship between nodes to obtain a node sequence arranged in hierarchical order, ensuring that the parent node of each node can be completely traced.
[0064] S132, traverse each node in the node sequence, call the embedding model to vectorize the chapter title of each node, and generate the corresponding chapter title embedding vector.
[0065] In this embodiment of the invention, the embedding model adopts bge-large-zh-v1.5.
[0066] S133, For any target node, extract the chapter title embedding vectors of all parent nodes to which the node belongs, and calculate the arithmetic mean of the chapter title embedding vectors of all parent nodes element by element according to the vector dimension to obtain the path embedding vector of the target node. The path embedding vector is used to represent the hierarchical association context of the target node in the multi-level tree structure.
[0067] S134. For each knowledge fragment in the target node, use an embedding model to vectorize it and generate a content embedding vector for that knowledge fragment, which is used to represent the core semantic features of the knowledge fragment.
[0068] In the embodiments of the present invention, the target node refers to the specific node to be processed currently in the multi-level tree structure, specifically the node that serves as the operation object in steps such as path embedding calculation and knowledge fragment association. Specifically, in the process of generating the embedding vector of the knowledge fragment (such as the path embedding calculation step), the target node is the specific node for which the path embedding vector needs to be generated: by extracting the chapter title embedding vectors of all the superior parent nodes (from the direct parent node to the root node) to which the node belongs, calculating the mean value to obtain its path embedding, so as to represent the hierarchical association context of the node in the tree structure. Subsequently, the knowledge fragment contained in this node will be fused with its own content embedding based on this path embedding to generate the final embedding vector.
[0069] S135, calculate the arithmetic mean of the content embedding vector of each knowledge fragment and the path embedding vector of the belonging target node element by element according to the dimension, and use the obtained mean vector as the final embedding vector of this knowledge fragment.
[0070] In the present invention, vectorization processing refers to converting text information (including chapter titles and knowledge fragment contents) into numerical vectors of a fixed dimension through a preset embedding model, so that the semantic information of the text can be quantitatively represented by the distance in the vector space.
[0071] Among them, the vectorization processing of the chapter title includes the following steps:
[0072] Text preprocessing: Standardize the chapter title of the node, including removing redundant symbols such as special punctuation marks, format marks, unifying Chinese and English punctuation marks such as converting “,” to “,”, correcting typos or non-standard expressions in the title such as unifying “砼” to “concrete”, and ensuring that the title text format is consistent.
[0073] Model input encoding: Input the preprocessed chapter title text into the embedding model, and the model performs semantic encoding on the text through the internal Transformer network structure, specifically including:
[0074] Tokenize the title text: Split the continuous text into a sequence of tokens recognizable by the model, such as splitting “1.2 Concrete maintenance” into “1.2”, “concrete”, and “maintenance”;
[0075] Convert the tokens into initial vectors through the token embedding layer, and then capture the semantic associations between the tokens through multiple attention mechanisms, such as the collocation relationship between “concrete” and “maintenance”;
[0076] Vector generation: The model output layer generates fixed-dimensional vectors (e.g., bge-large-zh-v1.5 outputs 768-dimensional vectors). These vectors are the embedded vectors of the chapter titles, which can represent the core semantics and hierarchical features of the titles. For example, the vectors of "1.2 Concrete Curing" and "1.1 Concrete Mix Proportion" have high similarity in space, reflecting their association with the theme of "Concrete Construction".
[0077] The vectorization of knowledge fragments includes the following steps:
[0078] Text preprocessing: Specialized processing for different types of knowledge fragments:
[0079] Plain text snippets: Remove redundant line breaks and spaces from paragraphs, and merge short sentences into coherent text, such as correcting "curing temperature ≥5℃" to "curing temperature ≥5℃";
[0080] Table JSON data: Convert structured dictionaries into natural language descriptive text, such as {"material":"cement","label":"C30"} into "material is cement, label is C30";
[0081] Image semantic description: Preserve the complete descriptive text generated by the visual large model, such as "Flowchart showing concrete pouring steps: 1. Formwork installation; 2. Reinforcement binding; 3. Pouring and vibration".
[0082] Model input encoding: The same embedding model as that used for chapter title vectorization is employed to encode the preprocessed knowledge fragment text.
[0083] For segments whose length exceeds the maximum input limit of the model (e.g., bge-large-zh-v1.5 supports 512 words), a sliding window truncation method (window size 512 words, step size 256 words) is used to generate multiple sub-segments, which are then encoded separately and the average is taken as the final vector.
[0084] For short text fragments (≤512 words), input the entire fragment directly into the model for encoding.
[0085] Vector generation: The model outputs an embedding vector of the same dimension as the chapter title vector (e.g., 768-dimensional). This vector is the content embedding vector of the knowledge fragment, which can accurately represent the core semantics of the fragment. For example, the vector of "curing temperature ≥ 5℃" is close to the query vector of "construction environment temperature requirements" in space.
[0086] Through the above steps, the integration of path embedding and content embedding is achieved: path embedding preserves the hierarchical relationship information of knowledge in the tree structure (such as chapter affiliation), while content embedding captures the core semantics of knowledge fragments; the combination of the two enables the vector representation of knowledge fragments to include not only what the content is, but also where the content is located in the knowledge system, effectively improving the semantic matching accuracy of subsequent retrieval. On the one hand, content embedding reduces matching errors caused by ambiguity in engineering terminology, and on the other hand, path embedding distinguishes the differences between similar content in different knowledge levels, while providing traceable hierarchical context for retrieval results, enhancing the transparency and reliability of knowledge retrieval.
[0087] S14, store the association relationship between knowledge fragments and nodes, the hierarchical relationship between nodes, the mapping relationship between nodes and source documents, as well as the vector data of knowledge fragments, related information and original information of engineering knowledge documents, to complete the construction of the engineering knowledge base.
[0088] In this embodiment of the invention, the original information of the engineering knowledge document includes the original engineering knowledge document file and the image data file extracted from the engineering knowledge document.
[0089] Furthermore, S14 specifically includes:
[0090] S141 uses a MySQL relational database to store the association between knowledge fragments and nodes, the hierarchical relationship between nodes, and the mapping relationship between nodes and source documents.
[0091] In this embodiment of the invention, the association between knowledge fragments and nodes is used to establish a mapping between knowledge fragments and their respective nodes, clarifying the context of the knowledge fragment. Knowledge fragments and nodes can be associated through a unique identifier field. Unique IDs, such as fragment_id and node_id, are assigned to knowledge fragments and nodes respectively in the database, and a foreign key node_id is set in the table corresponding to the knowledge fragment, which is linked to the primary key node_id in the node table. Specifically, the association is used to record which node each knowledge fragment, such as a plain text fragment, a JSON fragment converted from a table, or an image semantic extraction fragment, belongs to, ensuring that its source node can be traced through the knowledge fragment, providing a basis for subsequent node-based knowledge grouping and context supplementation.
[0092] The hierarchical relationships between nodes are used to maintain the parent-child relationships of nodes in a multi-level tree structure, supporting the tracing and reconstruction of the tree structure's hierarchy. Parent and child nodes within the same hierarchical structure are linked through the parent node identifier field. A `parent_node_id` field is set in the node table as a foreign key, linked to the primary key `node_id` of this table: for the root node of the tree structure, `parent_node_id` is empty (or set to a preset value indicating no parent node); for non-root nodes, `parent_node_id` points to the `node_id` of its direct parent node. Specifically, the hierarchical relationships between nodes are used to record the direct parent node information of each node. By recursively querying `parent_node_id`, the complete hierarchical path of the node can be traced, such as "root title → first-level chapter → second-level subsection → current node," thus supporting the generation of path embedding vectors and the complete reconstruction of the tree structure.
[0093] The mapping relationship between nodes and source documents refers to the association between each node and its original engineering document within the multi-level tree structure of engineering knowledge documents. Specifically, during the construction of an engineering knowledge base, a single engineering document (such as a standard specification or inspection report) is parsed into multiple nodes (each node corresponding to a chapter title and its content within the document). The relationship between nodes and source documents records which original document each node originates from, including but not limited to the document's unique identifier (such as document ID), document name, storage path, and other associated information. The core function of this relationship is to establish a traceable link between knowledge nodes and their original documents. In subsequent retrieval processes, the source document can be located through the node, ensuring knowledge traceability and providing fundamental data support for knowledge integrity verification and document version management.
[0094] S142 stores the embedding vectors of each knowledge fragment and related information of the knowledge fragment through the ElasticSearch vector database.
[0095] The relevant information for each knowledge fragment refers to the metadata and content description information associated with that knowledge fragment in Elasticsearch, excluding its embedding vector. This information comprises the fundamental attributes of the knowledge fragment, used to assist in the accuracy of vector retrieval and the understandability of the results. Specifically, it includes:
[0096] Basic identification information: the unique ID of the knowledge fragment and the ID of the node to which it belongs (used to associate it with nodes in the tree structure);
[0097] Content description information: The original content of the knowledge fragment (such as the specific text of a plain text fragment, JSON data after table parsing, and semantic description text after image parsing);
[0098] Type attribute information: The source type of the knowledge fragment (such as "plain text", "table", "image semantics"), used to distinguish fragments of different heterogeneous data;
[0099] Contextual information: Briefly record the position of the knowledge fragment in the node or the association identifier of adjacent fragments (to help restore the complete semantics when grouping knowledge later).
[0100] This information, along with the embedded vectors, is stored in ElasticSearch. During retrieval, not only are knowledge fragments matched based on vector similarity, but also information such as content descriptions and type attributes are combined to optimize the retrieval results, ensuring that the retrieved knowledge fragments meet both semantic similarity and content relevance requirements.
[0101] S143 stores the original files of the engineering knowledge document and the image data files extracted from the engineering knowledge document through the MINIO distributed object storage system.
[0102] In this embodiment of the invention, the knowledge gap problem is a sub-problem required to answer the original question. Specifically, it is a knowledge gap that needs to be filled before answering the main question, and a sub-problem that constitutes the necessary knowledge foundation for answering and solving the original question.
[0103] Furthermore, in S2, the step of generating a knowledge gap question list through query rewriting specifically includes:
[0104] S211: Organize existing knowledge, the list of executed searches, and the user's original question into suggestions.
[0105] Specifically, existing knowledge (accumulated relevant knowledge fragments and node content), executed search lists (historical subquery records), and the user's original question can be organized according to a preset format and combined into structured prompts. Each part of the information is separated by clear identifiers such as "[Existing Knowledge]", "[Executed Search List]", and "[User's Original Question]", ensuring that the large language model can clearly identify the input boundaries.
[0106] S212, invoke the large language model to parse the prompt words and generate an initial list of blank knowledge questions related to the user's question.
[0107] In this embodiment of the invention, a targeted prompt word-guided model is designed to focus on knowledge gap analysis. An example prompt word is: "You are a professional query rewriting expert and need to generate subqueries based on the following information: 1. Analyze the gap between [existing knowledge] and [user's original question] to locate the key information points that are not covered; 2. The generated subqueries must be semantically independent, with each subquery targeting a specific knowledge gap; 3. The number of subqueries should not exceed 10, and they must not be semantically duplicated with the queries in the [executed retrieval list]; 4. Return in JSON format, with keys 'query_1', 'query_2', etc., returning only JSON results. [Executed retrieval list]: [List of executed queries] [Existing knowledge]: [Existing knowledge] [User's original question]: [User's original question] Please generate a subquery list:"; The large language model outputs an initial subquery list based on the prompt word.
[0108] S213, by using vectorized semantic similarity calculation, duplicate sub-problems in the initial knowledge gap problem list are filtered and removed to obtain the final knowledge gap problem list.
[0109] Specifically, the sub-questions in the initial knowledge gap question list are vectorized using a vectorization model to obtain sub-question vectors. The cosine similarity between any two sub-question vectors is calculated. If the similarity between two sub-queries exceeds the duplication threshold, they are judged as semantic duplication, and one of them is retained. After deduplication, the final knowledge gap question list is obtained.
[0110] In this embodiment of the invention, the vectorization model adopts the same model as the knowledge fragment embedding, such as bge-large-zh-v1.5. The repetition threshold can be 0.8.
[0111] Through the above steps, the query and rewriting of the user's original question are completed. The generated knowledge gap question list accurately locates the gap between the current existing knowledge and the user's question. Subsequently, the existing knowledge will be supplemented and improved by traversing the list to search the engineering knowledge base.
[0112] Furthermore, in S2, the traversal of the list to retrieve knowledge fragments in the engineering knowledge base specifically includes:
[0113] S221, for each sub-problem in the knowledge gap problem list, the sub-problem is converted into an embedding vector through an embedding model.
[0114] S222, construct an ElasticSearch query statement based on the embedded vector, perform vector similarity retrieval in the ElasticSearch vector database, and obtain knowledge fragments related to the semantics of the sub-problem.
[0115] The query specifies the retrieval target as the embedding vector field of knowledge fragments in the knowledge base. Semantically related knowledge fragments can be matched using vector distance calculations (such as cosine similarity). After performing the search in the ElasticSearch vector database, results are sorted from high to low based on similarity scores. A similarity threshold (e.g., 0.6) is set to filter valid results, while limiting the number of knowledge fragments returned in a single sub-question search (e.g., Top 50) to avoid redundant data. Finally, the query obtains the relevant information (e.g., node ID, hierarchical path) of the knowledge fragments that meet the criteria, providing a foundation for subsequent knowledge grouping and sorting. The main purpose of knowledge fragment grouping is that the retrieved direct knowledge fragments are relatively short and semantically simple, and may lack necessary contextual content, which may contain potential related knowledge. By grouping the knowledge fragments, they can be restored to nodes, i.e., the original complete chapter content of the engineering document, thus revealing complete semantic information.
[0116] Furthermore, in S2, the knowledge grouping specifically includes:
[0117] S231, Based on the identification information of the retrieved knowledge fragment, query the node to which the knowledge fragment belongs from the MySQL database.
[0118] Each retrieved knowledge fragment carries unique identification information (including knowledge fragment ID and the ID of the node to which it belongs). Based on this identification information, the pre-stored knowledge fragment-node association table in the MySQL database is queried, and the original node to which the knowledge fragment belongs (i.e., the corresponding chapter node in the project document) is accurately located by the node ID.
[0119] S232, Read the complete content of the node in the multi-level tree structure, and use the complete content of the node as the context information of the knowledge fragment.
[0120] Specifically, the complete content of the node in the multi-level tree structure is read from the knowledge base, including: the chapter title and hierarchical path of the node (such as "1. Engineering Design → 1.2 Structural Parameters"), all knowledge fragments contained in the node (covering heterogeneous content such as plain text fragments, table JSON data, and image semantic descriptions), and the arrangement order of each knowledge fragment within the node (maintaining consistency with the logical order of the chapters in the original document).
[0121] S233, group the retrieved knowledge fragments according to the node dimension.
[0122] Specifically, all knowledge fragments belonging to the same node and their complete node content are grouped together to form node-level knowledge units. Through this grouping operation, the originally isolated knowledge fragments are restored to their respective chapter context, supplementing the semantic connections, logical order, and hierarchical background between fragments, and avoiding semantic fragmentation or information loss caused by a single short fragment.
[0123] Furthermore, in S2, the relevance ranking specifically includes:
[0124] S241, calculate the cosine similarity between the embedding vector of each retrieved knowledge fragment and the embedding vector of the corresponding knowledge gap question to obtain the semantic relevance.
[0125] For each sub-problem in the knowledge gap problem list, calculate the cosine similarity between its embedding vector and the embedding vectors of all knowledge fragments retrieved for that sub-problem, and obtain the semantic relevance of each knowledge fragment to the current sub-problem. The value ranges from 0 to 1, and the higher the value, the closer the semantics.
[0126] S242, calculate the mean of the semantic relevance of all knowledge fragments, and solve the interpolation between the semantic relevance of each knowledge fragment and the mean.
[0127] The interpolation of the semantic relevance of each knowledge fragment to the mean is the difference between the semantic relevance of a single knowledge fragment and the average relevance of all fragments, which is used to measure the degree of deviation of the relevance of that fragment from the overall average level.
[0128] Specifically, for all knowledge fragments corresponding to the current sub-problem, the arithmetic mean of their semantic relevance is calculated; for each knowledge fragment, the interpolation between its semantic relevance and the mean is calculated, i.e., the fragment relevance. If the fragment relevance is higher than the mean, the interpolation is positive (strengthening its importance); if it is lower than the mean, the interpolation is negative (weakening its influence), thereby highlighting the contribution of highly relevant fragments.
[0129] S243, the total interpolated sum of knowledge fragments contained in a node is used as the node weight, and the nodes are sorted from high to low weight. A preset number of the top-ranked nodes are selected as the knowledge and context information of the corresponding knowledge gap problem and added to the existing knowledge for cumulative storage.
[0130] Specifically, taking nodes as units, the interpolation of all knowledge fragments contained in a node is accumulated, that is, the sum of the fragment relevance of all fragments under the same node, to obtain the weight of the node. The higher the weight, the closer the semantic relationship between the node as a whole and the sub-problem. Nodes are sorted from high to low weight, and a preset number (such as Top 5) of the top nodes are selected. The complete content of these nodes is extracted, including chapter titles, hierarchical paths and all knowledge fragments, that is, the "node-level knowledge units" formed after knowledge grouping, which are used as the core knowledge and context corresponding to the current sub-problem. The content of these nodes is added to the existing knowledge for cumulative storage, and the same node is deduplicated by node ID to avoid storing the same node repeatedly.
[0131] Furthermore, in S2, the loop termination determination specifically includes:
[0132] S251, determine whether the number of retrieval rounds executed has exceeded a preset threshold. If it has, terminate the loop. If it has not, construct prompt words based on the executed retrieval list, existing knowledge, and the user's original question. Call the large language model to determine whether the existing knowledge is sufficient to answer the user's question. If it is sufficient, terminate the loop. Otherwise, return to the query rewriting step in step S2 to continue the loop.
[0133] Specifically, the system has a built-in retrieval round counter, initially set to 0, which automatically increments by 1 after each completion of the "query rewriting → retrieval → grouping → sorting → knowledge accumulation" process. First, it checks if the current counter value exceeds a preset threshold. If it does, the loop is forcibly terminated regardless of the current knowledge sufficiency, preventing inefficient retrieval due to the infinite generation of knowledge gaps. If the round threshold is not exceeded, the system proceeds to the knowledge sufficiency assessment stage.
[0134] Prompt word construction: Prompt words are generated according to the structure of "[Executed Search List] + [Current Existing Knowledge] + [User Original Question]". The "Current Existing Knowledge" needs to be organized into a structured summary of node-level knowledge units (including core conclusions, key data and hierarchical relationships). The "Executed Search List" needs to list all historical subquery texts to ensure that the large language model has a comprehensive grasp of the search progress and knowledge accumulation status.
[0135] Large Language Model Judgment: The large language model (e.g., moonshot-v1-auto) is invoked. Example prompt: "Based on historical queries in the [Executed Search List] and [Current Existing Knowledge], determine whether sufficient information has been obtained to answer the [User's Original Question]. Requirements: 1. If the knowledge covers the core elements of the user's question (e.g., technical principles, parameter ranges, implementation steps, etc.) and no key information is missing, return 'Sufficient'; 2. If there are uncovered core elements or key logical gaps, return 'Insufficient'; 3. Only return 'Sufficient' or 'Insufficient' without additional explanation."
[0136] The loop proceeds to the decision stage: if the model returns "sufficient", the loop terminates and enters the subsequent response generation stage; if it returns "insufficient", the round counter is incremented by 1, and the process returns to the query rewriting stage in S2 to generate a new list of knowledge gap questions for continued retrieval.
[0137] In this embodiment of the invention, the preset threshold is set to 3-5 rounds, which can be dynamically adjusted according to the complexity of engineering knowledge.
[0138] Furthermore, after the loop terminates, a response to the user's question is generated based on the existing knowledge accumulated during the loop, specifically including:
[0139] S252, based on the executed search list, the existing knowledge accumulated at the end of the loop, and the prompt word template filled in by the user's original question, calls the large language model to generate the original answer based on the existing knowledge.
[0140] In this embodiment of the invention, the prompt word template must clearly specify: input elements: the executed search list (presenting all subqueries in list form), the existing knowledge accumulated at the end of the loop (organized into structured content, including node-level paths, core knowledge fragments, and heterogeneous data summaries, such as "1.2 structural parameters → table data: concrete strength grade C30"), and the user's original question; output constraints: calling a large language model (such as moonshot-v1-auto), requiring it to generate answers based solely on "existing knowledge," and prohibiting the introduction of external information; if it is determined that the existing knowledge is irrelevant to the user's question, the preset statement "Sorry, the answer you requested was not found in the knowledge base" must be strictly returned; if it is relevant, the structure of "conclusion + knowledge base basis" must be adopted (such as "According to the content of section 1.2, the concrete curing temperature should be ≥5℃, see row 3 of the table for specific data"), to ensure that the correspondence between the answer and the knowledge fragment is traceable.
[0141] S253, the original answer generated by the large model is segmented into sentences, and each sentence is vectorized by embedding the model.
[0142] The sentence segmentation process employs a combination of punctuation mark splitting and semantic verification. The original answer is split into independent sentences based on punctuation marks such as periods, question marks, and semicolons. A large language model is then used to verify the semantic integrity of each sentence (avoiding ambiguity caused by splitting, e.g., splitting "If the temperature < 5℃, insulation measures need to be taken" into two valid sentences). Vectorization transformation uses a model consistent with knowledge fragment embedding (e.g., bge-large-zh-v1.5) to vectorize each valid sentence, generating sentence embedding vectors to ensure consistency with the vector space of knowledge fragments in the knowledge base.
[0143] S254. Calculate the cosine similarity between each sentence vector and the knowledge fragment vector in the engineering knowledge base. If the similarity exceeds the preset threshold, it is determined that the content of the sentence comes from the corresponding knowledge fragment, and its correlation with the knowledge base is verified.
[0144] Specifically, the cosine similarity between each sentence vector and all knowledge fragment vectors in the engineering knowledge base is calculated, and the top 3 knowledge fragments with the highest similarity and their scores are recorded. If the highest similarity score exceeds a preset threshold, the sentence content is determined to originate from the corresponding knowledge fragment. If multiple fragments among the top 3 exceed the threshold, the one with the highest score is taken as the primary source. If all scores are below the threshold, it is marked as "failed verification" and determined to potentially contain "unsubstantiated content." The preset threshold can be 0.6.
[0145] S255: Integrate all sentences that pass the relevance verification to generate the final response content; if there are sentences that fail the verification, correct them based on existing knowledge before integrating and outputting the response.
[0146] Specifically, for sentences that pass verification, the original expression is retained, integrated in logical order, and a source identifier (e.g., "[from node 1.2.3]") is added after the sentence to enhance traceability. For sentences that fail verification, the large language model is invoked for correction, with a prompt explicitly requiring "restate the core information of this sentence based on existing knowledge; if it cannot be corrected, delete it." After correction, S23-S24 verification is performed again to ensure that the corrected content is associated with the knowledge base. All sentences that pass verification (including the corrected content) are integrated to form a complete and logically coherent response, along with a backtracking list (listing all referenced knowledge fragment IDs and corresponding node paths) for users to verify the source of knowledge.
[0147] This invention also provides an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being configured to perform the method described in this invention.
[0148] This invention also provides a computer-readable storage medium storing computer-executable instructions for performing the methods described in this invention.
[0149] It should be understood that the various forms of processes shown above can be used to reorder, add, or delete steps. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this invention can be achieved, and this is not limited herein.
[0150] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. An engineering knowledge base construction and deep retrieval method, characterized in that, The method comprises the following steps: S1, constructing an engineering knowledge base based on engineering knowledge documents; S2, when a user question is received, generating a knowledge blank question list through query rewriting, retrieving the engineering knowledge base by traversing the list, grouping knowledge, sorting relevance, and judging loop termination, and after loop termination, generating reply content for the user question based on existing knowledge accumulated during the loop; S1 specifically comprises: S11, identifying the knowledge level of each input engineering knowledge document to form a multi-level tree structure, wherein each chapter title and its corresponding chapter content in the engineering knowledge document constitute a node of the multi-level tree structure; S12, separately analyzing and processing the heterogeneous content of each node to generate knowledge segments; S13, generating an embedding vector for each knowledge segment based on a combination of path embedding and content embedding; S14, storing the association between knowledge segments and nodes, the hierarchical relationship between nodes, the mapping relationship between nodes and source documents, and the vector data, related information, and original information of the engineering knowledge documents, and completing the construction of the engineering knowledge base; S13 specifically comprises: Starting from the root title of the multi-level tree structure, performing hierarchical traversal and sorting according to the parent-child membership relationship between nodes to obtain a node sequence arranged in hierarchical order; Traversing each node in the node sequence, calling an embedding model to vectorize the chapter titles of each node to generate corresponding chapter title embedding vectors; For any target node, extract the chapter title embedding vectors of all parent nodes to which the target node belongs, calculate the arithmetic mean of the chapter title embedding vectors of all parent nodes by element by element according to the vector dimension, and obtain the path embedding vector of the target node; For each knowledge segment in the target node, use an embedding model to perform vectorization processing to generate a content embedding vector for the knowledge segment; Calculate the arithmetic mean of the content embedding vector of each knowledge segment and the path embedding vector of the target node by element by element according to the dimension, and use the mean vector as the final embedding vector of the knowledge segment; In S2, the knowledge grouping specifically comprises: Based on the identification information of the knowledge segment obtained by retrieval, querying the node to which the knowledge segment belongs from the MySQL database; Read the complete content of the node in the multi-level tree structure, and use the complete content of the node as the context information of the knowledge segment; Group the retrieved knowledge segments by node dimension; In S2, the relevance sorting specifically comprises: Calculate the cosine similarity between the embedding vector of each retrieved knowledge segment and the embedding vector of the corresponding knowledge blank question to obtain the semantic relevance; Calculate the mean of the semantic relevance of all knowledge segments, and solve the interpolation of the semantic relevance of each knowledge segment and the mean; Accumulate the interpolation sum of the knowledge segments contained in the node as the node weight, sort the nodes by weight from high to low, select the content of the top nodes as the knowledge and context information of the corresponding knowledge blank question, and add it to the existing knowledge accumulated storage.
2. The method of claim 1, wherein, S11 specifically comprises: The chapter titles are extracted from the engineering knowledge document through heuristic rules, and the heuristic rules include: judging the title based on the document built-in label attribute, judging the title based on the title starting character label, and judging the title based on the text style features; The extracted chapter titles are input into a large language model, and the large language model constructs a multi-level tree structure based on the relative granularity of the chapter titles, wherein the content correlation between adjacent chapter titles is associated with the corresponding upper chapter title, and a node containing chapter titles and corresponding chapter content is formed.
3. The method of claim 1, wherein, S12 specifically includes: For pure text content in the node, if the text length exceeds p word units, first based on paragraph splitting, if the paragraph length still exceeds p word units, then based on paragraph semantic splitting into multiple semantically independent knowledge segments; if the text length does not exceed p word units, or the length of a single paragraph after paragraph splitting does not exceed p word units, then directly take the text or paragraph as a knowledge segment; For table content in the node, extract the column name, row name and restore the unmerged cell structure in the table content, and convert the table content into a standardized Python dictionary format and then into JSON data to form a knowledge segment; For image content in the node, extract semantic information from the image content through a visual large model, and take the extracted semantic information as a knowledge segment.
4. The method of claim 1, wherein, S14 specifically includes: Store the association relationship between knowledge segments and nodes, the hierarchical relationship between nodes, and the mapping relationship between nodes and source documents through a MySQL relational database; Store the embedding vectors of each knowledge segment and the related information of the knowledge segment through an ElasticSearch vector database; Store the engineering knowledge document original file and the extracted image data file in the engineering knowledge document through a MINIO distributed object storage system.
5. The method of claim 1, wherein, In S2, the knowledge blank question list is generated by query rewriting, specifically including: Organize the current existing knowledge, the executed search list and the user's original question into prompt words; Call a large language model to analyze the prompt words and generate an initial knowledge blank question list related to the user's question, wherein the knowledge blank question is a sub-question required to answer the original question; Calculate the semantic similarity through vectorization to filter and remove duplicate sub-questions in the initial knowledge blank question list to obtain the final knowledge blank question list.
6. The method of claim 5, wherein, In S2, the knowledge segment retrieval in the engineering knowledge base is retrieved by iterating the list, specifically including: For each sub-question in the knowledge blank question list, convert the sub-question into an embedding vector through an embedding model; Based on the embedding vector, construct an ElasticSearch query statement, and perform vector similarity retrieval in the ElasticSearch vector database to obtain knowledge segments related to the semantic of the sub-question.
7. The method of claim 1, wherein, In S2, the loop termination judgment specifically includes: It is judged whether the executed search round exceeds a preset threshold, and if it exceeds, the cycle is terminated; if it does not exceed, a prompt word is constructed based on the executed search list, the current existing knowledge and the user's original question, a large language model is called to judge whether the current existing knowledge is sufficient to answer the user's question, and if it is sufficient to answer, the cycle is terminated, otherwise the query rewriting link in step S2 is returned to continue the cycle.
Citation Information
Patent Citations
Knowledge retrieval method, system and equipment based on document structure context enhancement and medium
CN119807359A
Hierarchical semantic-driven retrieval enhancement generation method and system
CN120632119A