A method for detecting brain content compliance review based on KG and RAG collaborative knowledge enhancement
By constructing a deep integration mechanism based on KG and RAG, we have achieved high efficiency, accuracy and interpretability in software inspection and testing compliance review, solving the problems of low efficiency and insufficient accuracy in existing technologies, and improving the overall effectiveness of compliance review.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SICHUAN UNIV
- Filing Date
- 2026-02-03
- Publication Date
- 2026-06-02
AI Technical Summary
In existing technologies, the combination of knowledge graph (KG) and retrieval augmented generation (RAG) has failed to fully leverage its advantages in structured association mining and precise text retrieval in software inspection and testing compliance review, resulting in low efficiency and insufficient accuracy in compliance review, and the large model-generated results lack interpretability.
A deep integration mechanism based on KG and RAG is constructed to form an integrated knowledge base through entity extraction, relation extraction and vectorization. Combined with dense and sparse vector retrieval, highly relevant documents and subgraphs are filtered, and structured prompt words are used to constrain the large language model to generate results, ensuring the reliability and interpretability of compliance review.
It significantly improves the efficiency and accuracy of compliance review, reduces labor costs, ensures a strong correlation between the generated results and the compliance basis, and solves the problems of omissions and judgment biases that exist in traditional methods.
Smart Images

Figure CN122133655A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence and software inspection and testing technology, specifically to a content compliance review method based on a "detection brain" with collaborative knowledge enhancement of KG and RAG. Background Technology
[0002] The rapid development of the software and information technology industry has made compliance review of software testing and inspection a core element in ensuring the industry's standardized operation and mitigating technological risks. Compliance reviews require a comprehensive examination of the software product's testing and inspection processes, technical specifications, and security requirements, based on a vast amount of domestic and international laws, regulations, national standards, and other documents, to ensure compliance with industry access and operational standards.
[0003] Traditional software testing and compliance review methods primarily rely on manual retrieval and judgment, which is not only inefficient and costly in terms of manpower, but also prone to omissions or biases due to factors such as the large volume of documents, complex overlapping clauses, and differences in subjective human judgment. With the continuous growth in the number of compliance documents and the accelerated pace of clause updates, the manual review model can no longer meet the needs of efficient and accurate compliance reviews.
[0004] To address the pain points of manual review, automated compliance review solutions based on rule engines or single search technologies have gradually emerged in the industry. Rule engine-based methods automate reviews by pre-setting judgment rules corresponding to compliance clauses; however, rule formulation relies on the experience of professionals, making it difficult to cover all complex scenarios. Furthermore, frequent manual adjustments are required when clauses are updated, resulting in poor flexibility and scalability. Single search technologies (such as keyword search and traditional vector search) can achieve rapid retrieval of compliance documents, but they have significant limitations: keyword search is susceptible to semantic ambiguity and struggles to capture deep connections between clauses; while traditional vector search can reflect textual semantic similarity, it lacks the ability to mine structured relationships within compliance knowledge, leading to insufficient relevance and accuracy of search results, thus affecting the reliability of the final review conclusion.
[0005] In recent years, knowledge graphs (KG) and retrieval-enhanced generation (RAG) technologies have demonstrated significant advantages in knowledge-intensive tasks. Knowledge graphs can transform scattered compliance knowledge into structured entity-relationship networks, clearly presenting the logical connections between core elements such as regulatory clauses, detection indicators, and applicable scenarios. RAG technology, through the synergy of retrieval and generation, provides accurate external knowledge support for large models, preventing generated results from deviating from compliance basis. However, in existing technologies, the combination of KG and RAG often remains at the level of simple functional superposition: either only knowledge graphs are used for entity matching, failing to fully leverage their structured relationships to guide retrieval; or only RAG is relied upon for text fragment retrieval, lacking the mining of global connections in compliance knowledge, resulting in the failure to fully release the synergistic enhancement effect of the two.
[0006] The construction of knowledge bases related to current compliance reviews still faces challenges: massive compliance documents contain both structured (such as clause numbers and key data) and unstructured (such as clause descriptions and judgment criteria) information, and existing parsing technologies struggle to accurately extract and correlate these two types of information; compliance documents come from a wide range of sources (covering different countries and types), and the lack of unified coding and management rules makes it difficult to guarantee the orderliness and uniqueness of the knowledge base; the retrieved compliance text fragments and knowledge graph subgraphs are mostly independent outputs without effective fusion processing, making it difficult for large models to fully utilize the detailed information of the text and the structured correlation information of the graph when generating review results, affecting the accuracy and interpretability of the review results.
[0007] When generalized large language models are directly applied to compliance review tasks, they are prone to "illusion" phenomena, generating conclusions without compliance basis and failing to clearly explain the logic behind the clause citations in the review results. Therefore, how to construct a knowledge enhancement mechanism that deeply collaborates with KG and RAG, integrating structured and unstructured compliance knowledge to achieve efficient and accurate compliance information retrieval and fusion, and combining this with large models to generate reliable and interpretable compliance review results, has become a critical issue that urgently needs to be addressed in the field of software testing and inspection compliance review. Summary of the Invention
[0008] To address the shortcomings of existing technologies, the present invention aims to provide a content compliance review method for a "detection brain" based on collaborative knowledge enhancement using KG and RAG. By constructing a deep integration mechanism between KG (Knowledge Graph) and RAG (Retrieval Enhancement Generation), the invention fully leverages the advantages of KG in structured modeling and association mining of compliance knowledge, as well as the core capabilities of RAG in accurate text retrieval and external knowledge enhancement. This achieves complementary and synergistic effects between the two technologies, thereby significantly improving the efficiency, accuracy, and interpretability of software inspection and compliance review.
[0009] This invention is implemented as follows: a content compliance review method for "detecting the brain" based on KG and RAG collaborative knowledge enhancement, comprising the following steps:
[0010] Step S1: Collect multiple original documents related to software inspection and detection to construct an original document set; and preprocess the multiple original documents in the original document set to obtain a reference document set; wherein, the reference document set includes multiple ordered reference documents;
[0011] Step S2: On the one hand, entity extraction and relation extraction are performed on each reference document in the reference document set to construct a knowledge graph corresponding to each reference document; on the other hand, each reference document in the reference document set is transformed into a corresponding high-dimensional vector.
[0012] Step S3: Construct an integrated knowledge base for "detecting the brain" based on multiple reference documents, corresponding high-dimensional vectors, and corresponding knowledge graphs;
[0013] Step S4: Receive the software inspection and testing report to be reviewed input by the user; on the one hand, convert the software inspection and testing report to be reviewed into a corresponding retrieval vector, and compare the similarity of the retrieval vector with the high-dimensional vector in the "Detection Brain" integrated knowledge base, and then retrieve highly relevant reference documents from the "Detection Brain" integrated knowledge base based on the comparison results; on the other hand, perform entity extraction on the software inspection and testing report to be reviewed, and select highly relevant subgraphs from the knowledge graph in the "Detection Brain" integrated knowledge base based on the entity extraction results of the software inspection and testing report to be reviewed.
[0014] Step S5: The highly relevant reference documents and the highly relevant subgraphs are fused to form structured knowledge, and structured prompt words are generated based on the structured knowledge;
[0015] Step S6: Based on the structured prompts and the structured knowledge, output the compliance review results of the inspection and testing report of the software to be reviewed.
[0016] As a further aspect of the present invention: the preprocessing of multiple original documents in the original document set to obtain a reference document set includes:
[0017] The pre-trained PaddleOCR-VL model is used to preprocess multiple original documents in the original document set to obtain multiple reference documents;
[0018] Multiple reference documents are encoded to obtain multiple ordered reference documents, and the reference document set is constructed based on the multiple ordered reference documents.
[0019] As a further aspect of the present invention: in step S2, entity extraction is performed on each reference document in the reference document set, including:
[0020] For each sentence in each reference document ,in, For sentences Individual words in the sentence are processed using the bert-base-chinese model. Perform contextual semantic encoding to output the sentence. context vector , ,in, For each word The corresponding high-dimensional semantic vector will divide each word High-dimensional semantic vectors It is fed into a linear transformation layer and then passed through a weight matrix. Mapping and bias terms After adjustment, then through The function calculates each word Probability distribution of various preset entity labels :
[0021] ;
[0022] In the formula: For each word Corresponding preset entity tags;
[0023] Based on each word Probability distribution of various preset entity labels Filter out entity label results whose probability meets the threshold to obtain each word The entity tags of each word are used to output the final output. The corresponding structured entity list; wherein, the structured entity list contains three types of core information: each word in the reference document. Each word The associated entity tag, each word Start-end position index in the reference document;
[0024] Construct an entity set for each reference document based on the structured entity list corresponding to all words in each reference document.
[0025] As a further aspect of the present invention: in step S2, relation extraction is performed on each reference document in the reference document set to construct a knowledge graph corresponding to each reference document, including:
[0026] Entity pairs are enumerated based on the entity set corresponding to each reference document, and a special input sequence corresponding to each entity pair is constructed based on each entity pair and its context content in the reference document. This special input sequence It contains "head entity - document context - tail entity"; this special input sequence is processed through the bert-base-chinese model. Perform semantic encoding to output this specific input sequence. [CLS] vector ; Special input sequence [CLS] vector It is fed into a linear transformation layer and then passed through a weight matrix. Mapping and bias terms After adjustment, then through The function calculates the probability distribution of each entity pair belonging to various preset relations. The formula is as follows:
[0027] ;
[0028] in, It is the preset relationship corresponding to each entity pair;
[0029] Based on the probability distribution of each entity pair belonging to various preset relationships The results of relationships whose probabilities meet the threshold are filtered out to obtain the relationship to which each entity belongs;
[0030] A knowledge graph is constructed for each reference document based on the entity set corresponding to each reference document and the relationships between each entity pair in that entity set.
[0031] As a further aspect of the present invention: in step S2, each reference document in the reference document set is converted into a corresponding high-dimensional vector, including:
[0032] Semantic segmentation is performed on each reference document in the reference document set to obtain multiple blocks in each reference document;
[0033] The first step is dense vectorization, which involves inputting each block d from each reference document into the embedding model to output a dense vector for each block d. , The representation method is as follows:
[0034] ;
[0035] In the formula: For block A word in the text; For words obtained through the Embedding model Dense vectors, The total number of words in block d;
[0036] The second step is to perform sparse vectorization, which involves segmenting each block d in each reference document into words to obtain multiple word segments in each block d.
[0037] (1) Use the TF-IDF algorithm to perform sparse vectorization on the various word segments in each block d; a certain word segmentation The frequency of occurrence in its corresponding block d is The formula is:
[0038] ;
[0039] In the formula: Indicates a certain type of participle Frequency of occurrence in its respective block d; Indicates block Total number of word segmentations in the text;
[0040] A certain type of word segmentation Its importance in the relevant reference document is: The formula is:
[0041] ;
[0042] In the formula: This indicates the total number of blocks in the associated reference document. This indicates that the referenced document contains a certain type of word segmentation. The number of blocks;
[0043] Then, the TF-IDF algorithm is used to obtain a certain word segmentation in block d. TF-IDF sparse vectors The formula is:
[0044] ;
[0045] This leads to the TF-IDF sparse vector for each block d. The formula is:
[0046] ;
[0047] In the formula: 𝑚 is the number of word segmentation types in block d;
[0048] (2) Use the BM25 algorithm to perform sparse vectorization on the various word segments in each block d; first, use the BM25 algorithm to obtain a certain word segment in block d. BM25 sparse vector The formula is:
[0049] ;
[0050] In the formula: For a certain type of word segmentation Importance within the relevant reference document; Indicates a certain type of participle Frequency of occurrence in its respective block d; and All parameters are adjustable; For the corresponding block Length; This is the average length of all blocks in the corresponding reference document;
[0051] This leads to the BM25 sparse vector for each block d. The formula is:
[0052] ;
[0053] In the formula: 𝑚 is the number of word segmentation types in block d;
[0054] The third step is vector fusion, which involves dense vectors from all blocks d of all reference documents. TF-IDF sparse vectors and BM25 sparse vector The data is stored in a vector database; the integrated knowledge base for "detecting the brain" is constructed based on all blocks d of all reference documents, the corresponding vector database, and the corresponding knowledge graph.
[0055] As a further aspect of the present invention: In step S4, the inspection and testing report of the software to be reviewed is converted into a corresponding retrieval vector, and the retrieval vector is compared with the high-dimensional vector in the integrated knowledge base of the "Detection Brain". Then, based on the comparison result, highly relevant reference documents are retrieved from the integrated knowledge base of the "Detection Brain", including:
[0056] The inspection and testing report of the software to be reviewed is divided into multiple text blocks. Each text block is obtained through the Embedding model. The dense vectors are obtained by using both the TF-IDF and BM25 algorithms to obtain each text block. TF-IDF sparse vectors and BM25 sparse vectors;
[0057] The first step is to extract a text block from the inspection and testing report of the software to be reviewed. The dense vector of the text block is compared with the dense vector of each block d in the vector database to obtain the similarity of the text block. Dense vector similarity with each block d The formula is:
[0058] ;
[0059] in, For a certain text block Dense vectors, For each block d in the vector database, a dense vector. The dot product of two dense vectors. For a certain text block The magnitude of a dense vector, Let be the magnitude of the dense vector for each block d. dense vector The dimensional components, dense vector The dimensional components, The dimension of the dense vector;
[0060] The second step is to extract a text block from the inspection and testing report of the software to be reviewed. The TF-IDF sparse vector of the text block is compared with the TF-IDF sparse vector of each block d in the vector database to obtain the similarity of the text block. TF-IDF sparse vector similarity with each block d Simultaneously, a text block from the inspection and testing report of the software under review... The BM25 sparse vector is compared with the BM25 sparse vector of each block d in the vector database to obtain the text block. BM25 sparse vector similarity with each block d ;
[0061] The third step is to modify the text block. TF-IDF sparse vector similarity with each block d Similarity to BM25 sparse vectors Perform weighted fusion to obtain the text block. Sparse vector fusion similarity between each block d The formula is:
[0062] ;
[0063] In the formula, , These are weight parameters;
[0064] The fourth step is to process the text block. Dense vector similarity with each block d Similarity fusion with sparse vectors Perform weighted fusion to obtain the text block. Final fusion similarity with each block d The formula is:
[0065] ;
[0066] In the formula, These are weight parameters;
[0067] Fifth step, based on the text block Final fusion similarity with each block d The multiple blocks in the "Brain Detection" integrated knowledge base are sorted in descending order, and the top-5 highly relevant blocks are selected from the "Brain Detection" integrated knowledge base.
[0068] As a further aspect of the present invention: the text block in the inspection and testing report of the software to be reviewed... The TF-IDF sparse vector of the text block is compared with the TF-IDF sparse vector of each block d in the vector database to obtain the similarity of the text block. TF-IDF sparse vector similarity with each block d ,include:
[0069] For a certain text block A certain type of word segmentation Using the TF-IDF algorithm to obtain a certain word segmentation TF-IDF sparse vectors Then a certain type of word segmentation TF-IDF sparse vector similarity between the block d and the segment d for:
[0070] ;
[0071] In the formula: 𝑚 is the number of word segmentation types in block d; For a certain type of word segmentation TF-IDF sparse vectors The dimensional vector; For block TF-IDF sparse vector of a certain word segment j The dimensional vector; This represents the total dimension of the vector.
[0072] According to the text block Each type of word segmentation TF-IDF sparse vector similarity between the block d and the segment d To obtain the text block TF-IDF sparse vector similarity with each block d .
[0073] As a further aspect of the present invention: the text block in the inspection and testing report of the software to be reviewed... The BM25 sparse vector is compared with the BM25 sparse vector of each block d in the vector database to obtain the text block. BM25 sparse vector similarity with each block d ,include:
[0074] For a certain text block A certain type of word segmentation Using the BM25 algorithm to obtain a certain word segmentation BM25 sparse vector Then a certain type of word segmentation BM25 sparse vector similarity between the block d and the segment d for:
[0075] ;
[0076] In the formula: 𝑚 is the number of word segmentation types in block d; For a certain type of word segmentation BM25 sparse vector The dimensional vector; For block BM25 sparse vector of a certain word segment j The dimensional vector; This represents the total dimension of the vector.
[0077] According to the text block Each type of word segmentation BM25 sparse vector similarity between the block d and the segment d To obtain the text block BM25 sparse vector similarity with each block d .
[0078] As a further aspect of the present invention: in step S4, entity extraction is performed on the inspection and testing report of the software to be reviewed, and highly relevant subgraphs are selected from the knowledge graph within the integrated knowledge base of the "Detection Brain" based on the entity extraction results of the inspection and testing report of the software to be reviewed, including:
[0079] Entity extraction is performed on the inspection and testing report of the software to be reviewed to obtain the entity set of the inspection and testing report of the software to be reviewed. , where entity set , For entity collection The i-th entity in;
[0080] Using the breadth-first search algorithm , entity collection Each entity pair in Path search is performed on multiple knowledge graphs G within the integrated "brain detection" knowledge base, using the following formula:
[0081] ;
[0082] In the formula: This represents the de novo entities retrieved from multiple knowledge graphs G for each entity pair. End-to-end entity Length not exceeding All paths;
[0083] For the entity set Each entity in the set is filtered through all paths in multiple knowledge graphs G to obtain the entity set. The shortest path for each entity pair in the set of knowledge graphs G, and based on the entity set. The most concise path of all entity pairs in multiple knowledge graphs G is used to obtain the highly relevant subgraph;
[0084] The selection principle for the simplest path is as follows: (1) The path length is defined by the number of edges contained in the path. For the same entity pair (2) Among multiple paths in multiple knowledge graphs G, the path with the shortest length is retained first; (3) For the entity set Different entity pairs in If different entities pair If there are overlaps among all the corresponding shortest paths, the longer path among the overlapping paths is retained.
[0085] As a further aspect of the present invention: steps S5 and S6 include:
[0086] The structured knowledge is embedded into a preset structured prompt word template to generate structured prompt words that meet the input requirements of the LLM large language model;
[0087] The structured prompts and structured knowledge are input into the LLM large language model to output the compliance review results of the inspection and testing report of the software to be reviewed.
[0088] Compared with the prior art, the beneficial effects of the present invention are:
[0089] (1) Deeply integrate KG and RAG technologies, leveraging the advantages of KG's structured association mining and the precise text retrieval capabilities of RAG to achieve complementary and synergistic knowledge;
[0090] (2) Innovate a dual-path retrieval and fusion mechanism to take into account both deep semantic association and precise keyword matching, thereby improving the comprehensiveness and accuracy of retrieval;
[0091] (3) Construct a standardized knowledge base coding and processing workflow to solve the problem of chaotic management of heterogeneous documents;
[0092] (4) By empowering large models with structured knowledge, “illusion” can be effectively suppressed, the output results are accurate and interpretable, the efficiency and reliability of compliance review can be greatly improved, and the labor cost can be reduced. Attached Figure Description
[0093] Figure 1 The flowchart illustrates a content compliance review method for "detecting the brain" based on KG and RAG collaborative knowledge enhancement, provided by this invention.
[0094] Figure 2 The flowchart illustrates a specific implementation method of the "detection brain" content compliance review method based on KG and RAG collaborative knowledge enhancement provided by this invention.
[0095] Figure 3 The flowchart for constructing the knowledge graph provided by this invention.
[0096] Figure 4 A flowchart illustrating the construction process of the vector database provided by this invention.
[0097] Figure 5 The flowchart for the fusion retrieval process provided by this invention. Detailed Implementation
[0098] The present invention will be further described in detail below with reference to embodiments, but the implementation of the present invention is not limited thereto.
[0099] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, 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 a part of the embodiments of the present invention, not all of them. 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. Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to represent selected embodiments of the invention. 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.
[0100] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.
[0101] Definitions:
[0102] KG: Knowledge Graph is a semantic network based on graph structure in the field of artificial intelligence. Its core is to store, organize and represent massive amounts of information in a structured way using "entity-relationship-entity" triples. It connects scattered knowledge nodes into a network through explicit semantic associations. Essentially, it is a machine-understandable and computable knowledge system that can help artificial intelligence systems understand the intrinsic connections between knowledge like humans do.
[0103] RAG: Retrieval-Augmented Generation (RAG) is an artificial intelligence technology that combines retrieval and generation. Its core is to retrieve relevant and accurate information from an external knowledge base before the generative model answers a question. This information is then used as context input to assist the generative model in generating an answer. This approach retains the fluency of the generative model while supplementing it with the latest and most professional knowledge through real-time retrieval, effectively solving the problems of knowledge lag and the generation of false information in traditional generative models.
[0104] Embedding Model: The embedding model is a core foundational model in the field of artificial intelligence. Its core function is to map unstructured data such as text, images, and audio, or discrete information such as entities and concepts, into low-dimensional, dense real-valued vectors (i.e., "embedded vectors"). The spatial distance or similarity of the vectors corresponds to the degree of semantic association of the original information—the closer the semantics, the closer the vectors, thus enabling computers to quantitatively understand and compute the semantic information of unstructured data.
[0105] Pipeline: Pipeline is a core technical architecture in fields such as artificial intelligence and data processing. It refers to breaking down complex tasks into a series of orderly and reusable independent steps (such as data acquisition, preprocessing, model inference, and result output). Each step only completes a specific function and passes the result to the next step, forming an automated "input-processing-output" process. This can improve task execution efficiency, reduce module coupling, and facilitate maintenance and iteration.
[0106] OCR (Optical Character Recognition) is a technology that converts printed or handwritten text in an image into editable and searchable digital text. Its core is to enable computers to "understand" the text content in an image through steps such as image preprocessing, character localization, feature extraction, and recognition matching, without the need for manual input. This can greatly improve the efficiency of text extraction and enable secondary editing and analysis of the text.
[0107] LLM (Large Language Model) is a deep learning model trained on massive amounts of text data. Through a large number of parameters and architectures such as Transformer, it learns the syntax, semantics, logic and knowledge associations of a language. It has core capabilities such as understanding natural language, generating coherent text, completing dialogue interaction, and logical reasoning. It can be adapted to a variety of scenarios without being fine-tuned for specific tasks, and is the core foundational model for natural language processing tasks in the field of artificial intelligence.
[0108] This invention is based on the following theoretical foundation:
[0109] This invention deeply integrates Knowledge Graph (KG) and Retrieval Augmentation (RAG) technologies to construct a deep collaborative mechanism between the two. Knowledge Graph, centered on the "entity-relationship-entity" triple, transforms scattered, unstructured compliance knowledge such as laws, regulations, and testing indicators into a machine-understandable structured network. Its core theory lies in "semantic association explicitness." Through entity and relation extraction, information such as legal clauses and testing indicators is transformed into a network of nodes and edges, following the logic of "structured knowledge modeling → visualization of association logic → traceable retrieval path," providing clear knowledge association links for compliance review and compensating for the shortcomings of pure text retrieval in capturing deep logic. The core theory of RAG technology is "generation and retrieval synergy," providing precise external knowledge support to the generation model through the retrieval module, solving the problems of knowledge lag and "illusion" in traditional large models. This invention does not simply superimpose the two but constructs a deep integration mechanism. It leverages the structured association mining advantages of KG to guide the retrieval direction of RAG, while utilizing RAG's precise text retrieval capabilities to provide rich contextual details for entity associations in KG, achieving complementary and synergistic knowledge.
[0110] To address the limitations of single retrieval technologies, a dual-path retrieval architecture combining dense vectorization and sparse vectorization is employed. This design is based on the theory of complementary deep semantic understanding and precise keyword matching. Dense vectorization leverages the contextual encoding capabilities of pre-trained language models (such as BGE-M3) to transform text into high-dimensional vectors containing deep semantics. Following the core logic of "semantic similarity = vector space distance," it effectively understands synonyms and contextual ambiguities, resolving semantic matching issues in fuzzy user queries. Sparse vectorization, through TF-IDF and BM25 algorithms, focuses on the frequency and importance features of keywords in the text, achieving precise location of surface-level keywords, particularly adept at handling precise queries containing specific regulatory numbers and testing terms. Furthermore, this invention intelligently balances the weights of the two retrieval results through a relative score fusion algorithm, preventing a single result from dominating the fusion conclusion. This ensures that the retrieval results maintain semantic consistency while ensuring direct matching of key information. This dual-path fusion mechanism completely overcomes the shortcomings of "weak keyword response" in single dense vector retrieval and "poor semantic understanding" in single sparse vector retrieval, providing the knowledge base with high-quality, high-recall retrieval results.
[0111] By utilizing structured templates, the generation of large-scale models is constrained to achieve accurate and interpretable output. When general-purpose large-scale models are directly applied to compliance reviews, they are prone to "illusions" due to a lack of domain knowledge, resulting in unfounded conclusions. This invention embeds the structured knowledge (including highly relevant text fragments and graph subgraphs) fused from previous steps into a pre-set structured prompt template, constructing a complete and logically coherent large-scale model input instruction. This structured input method provides the LLM with a clear review logic framework and core basis, forcing its generation process to strictly adhere to the "conclusion-basis-logic" traceability system. Through this dual constraint mechanism, the large-scale model is no longer free-form but outputs based on highly relevant data in the "detection brain" knowledge base, combined with the business rules and judgment standards of software inspection and compliance review. This not only fundamentally suppresses the generation of "illusions" and ensures a strong correlation between the output results and compliance basis, but also relies on explicit entity relationship links and textual clause evidence in the knowledge base to give the review results a certain degree of accuracy and interpretability, enhancing the reliability of automated review.
[0112] Example 1:
[0113] This invention provides a content compliance review method for "detection brain" based on KG and RAG collaborative knowledge enhancement, such as... Figure 1 As shown, please also refer to Figure 2By constructing a deep integration mechanism between KG and RAG, we can fully leverage KG's advantages in structured modeling and correlation mining of compliance knowledge, and RAG's core capabilities in precise text retrieval and external knowledge enhancement. This will achieve complementary and synergistic effects between the two technologies, thereby significantly improving the efficiency, accuracy, and interpretability of software inspection and testing compliance reviews. The steps include:
[0114] Step S1: Collect multiple original documents related to software inspection and detection to construct an original document set; and preprocess the multiple original documents in the original document set to obtain a reference document set; wherein, the reference document set includes multiple ordered reference documents;
[0115] Step S2: On the one hand, for each reference document in the reference document set, entity (regulatory name, testing indicators, applicable scenarios, and other core entities) and relationship (“compliance basis-scope of application”, “testing indicators-judgment criteria”, and other related relationships) are extracted to generate node information and connection information of the knowledge graph, so as to construct the knowledge graph corresponding to each reference document, realize the structured modeling and explicit association of compliance knowledge, and make up for the shortcomings of pure text retrieval in capturing deep associations; on the other hand, each reference document in the reference document set is transformed into a corresponding high-dimensional vector, and each reference document is associated with and stored with the corresponding high-dimensional vector.
[0116] Step S3: Construct an integrated knowledge base for "detecting the brain" based on multiple reference documents, corresponding high-dimensional vectors, and corresponding knowledge graphs; among them, the knowledge complementarity is achieved through the three-in-one storage of "text-vector-graph", which greatly improves the comprehensiveness and efficiency of subsequent retrieval.
[0117] Step S4: Receive the software inspection and testing report to be reviewed input by the user; on the one hand, convert the software inspection and testing report to be reviewed into a corresponding retrieval vector, and compare the similarity of the retrieval vector with the high-dimensional vector in the "Detection Brain" integrated knowledge base, and then retrieve highly relevant reference documents from the "Detection Brain" integrated knowledge base based on the comparison results; on the other hand, perform entity extraction on the software inspection and testing report to be reviewed, and select highly relevant subgraphs from the knowledge graph in the "Detection Brain" integrated knowledge base based on the entity extraction results of the software inspection and testing report to be reviewed.
[0118] It should be noted that the inspection and testing report of the software to be reviewed is simultaneously sent to the large model text retrieval module to start the dual-path retrieval process of mixed text retrieval and graph retrieval.
[0119] The software inspection and testing report under review is subjected to a mixed text search to generate search vectors (dense and sparse search vectors). By fusing these two vectors, both deep semantic relationships and precise keyword matching are considered. The search vectors are then compared with text vector data within the integrated knowledge base of the "Detection Brain" to calculate and match similarity, obtaining highly relevant reference documents. This dual-vector fusion not only overcomes the limitations of single-vector retrieval but also improves the accuracy and comprehensiveness of text retrieval. The software inspection and testing report under review is then fed into a graph retrieval module. After semantic segmentation, entity nodes are precisely matched, and relationships are queried to select subgraphs highly relevant to the requirements. By retrieving highly relevant graph subgraphs, the structured relational logic of compliance knowledge, which is difficult to cover with text retrieval, can be uncovered, overcoming the limitation of pure text retrieval's focus on details and neglect of connections, thus improving the completeness of knowledge retrieval.
[0120] Step S5: The highly relevant reference documents and the highly relevant subgraphs are fused to form structured knowledge, and structured prompt words are generated based on the structured knowledge. The fusion of the highly relevant reference documents and the highly relevant subgraphs allows the specific clauses and technical details in the reference documents to complement the entity relationships and logical links presented in the graph, ultimately integrating them to form structured knowledge containing key text clauses, entity relationships, and core logical links.
[0121] It should be noted that by synergistically integrating highly relevant reference documents and highly relevant subgraphs, structured knowledge that combines textual details with logical connections is formed. Through the collaboration of document segmentation and subgraphs, the complementary integration of unstructured textual information and structured relational information is achieved. Then, by embedding preset structured prompt word templates, input instructions for the compliance big model are generated and sent to the general LLM big language model. The standardized input format can effectively guide the big model to focus on the core of the review, thereby improving the accuracy and interpretability of the review results.
[0122] Step S6: Based on the structured prompts and the structured knowledge, output the compliance review results of the inspection and testing report of the software to be reviewed.
[0123] It should be noted that the general-purpose LLM large language model uses structured input prompts as a guiding framework, integrates structured knowledge, and follows the domain logic and judgment rules of software inspection and compliance review to output compliance review results that are accurate and interpretable. This process effectively ensures a strong correlation between the output results and the compliance basis through a dual mechanism of structured knowledge empowerment and domain logic constraints, significantly suppressing the occurrence of the "illusion" phenomenon of large models. At the same time, relying on the explicit entity association links and textual clause evidence in the knowledge base, it constructs a complete traceability system of "conclusion-basis-logic", and significantly reduces the cost of manual intervention by directly outputting standardized compliance judgment conclusions.
[0124] Example 2:
[0125] This embodiment is a further optimization based on the above embodiments. The similarities with the aforementioned technical solutions will not be repeated here. Furthermore, to better implement the "detection brain" content compliance review method based on KG and RAG collaborative knowledge enhancement described in this invention, the preprocessing of multiple original documents in the original document set to obtain a reference document set includes:
[0126] The pre-trained PaddleOCR-VL model is used to preprocess multiple original documents in the original document set to obtain multiple reference documents;
[0127] Multiple reference documents are encoded to obtain multiple ordered reference documents, and the reference document set is constructed based on the multiple ordered reference documents.
[0128] Specifically, multiple original documents (including PDF, Word, and scanned copies) related to the inspection and testing of the software and information technology industry both domestically and internationally were collected. These documents contained structured information such as clause numbers, technical indicators, and judgment thresholds, as well as unstructured text such as clause descriptions and explanations of applicable scenarios. A pre-trained PaddleOCR-VL model was used to perform document parsing and information extraction. The PaddleOCR-VL model, through its cross-modal semantic understanding capabilities, can accurately identify diverse content such as tables, formulas, and paragraph text in the original documents, overcoming the limitation of traditional OCR which can only recognize plain text. This enables the simultaneous and accurate extraction of structured and unstructured text. Furthermore, addressing issues such as blurry scanned original documents, incorrect formatting, and mixed multilingual text, the PaddleOCR-VL model effectively improves the accuracy of information extraction from low-quality documents through adaptive noise reduction, layout analysis, and multilingual recognition optimization. This solves the pain points of traditional parsing methods, such as information omission, field misalignment, and semantic fragmentation.
[0129] Therefore, by parsing the original documents using the pre-trained PaddleOCR-VL model, multiple heterogeneous and disordered original documents are transformed into standardized reference documents that can be directly used for subsequent knowledge graph construction and vectorization processing. This ensures the accuracy of subsequent KG entity extraction and relation extraction, avoiding distortion in knowledge graph construction due to information extraction bias. It provides a high-quality document foundation for RAG retrieval, ensuring the reliability of vector conversion and semantic matching. It significantly reduces manual preprocessing costs, improves document parsing efficiency and standardization, and enables unified processing of documents of various formats and qualities. This lays a solid data foundation for the knowledge augmentation system that combines KG and RAG, ensuring the accuracy and stability of the entire compliance review process.
[0130] Furthermore, for multiple reference documents (covering reference documents from different countries / regions, different levels, and different publishing institutions), in order to thoroughly solve the problems of chaotic document classification, ambiguous source identification, duplicate storage, and difficulty in retrieval and tracing in traditional knowledge bases, this invention innovatively designs a set of knowledge base coding rules that combine uniqueness, scalability, and semantic relevance. The coding rule adopts a four-level structured coding structure of "country / region identifier - document category code - hierarchical subdivision code - unique serial number": The first level introduces the two-letter country code of ISO 3166-1 (such as CN for China, US for the United States, EU for the European Union, etc.) to accurately distinguish reference documents from different countries / regions and solve the pain point of confusion in the source of cross-border / cross-regional reference documents; The second level is an expandable classification code (such as LA for laws and regulations, GB for national standards, IN for industry specifications, DB for local standards, etc.) and reserves custom coding positions (such as adding international organization standard code IO) to adapt to the future expansion needs of compliance document categories; The third level is a hierarchical subdivision code, which is further subdivided according to the level of the reference document publishing organization (such as 01 for the national level, 02 for the industry level, and 03 for the enterprise level) or the type of clause (such as T for technical indicators, S for safety requirements, and P for process specifications) to improve the granularity of classification; The fourth level is a unique serial number (using an 8-digit auto-incrementing code) to ensure that each reference document and its subdivided blocks are uniquely identified.
[0131] The core function of this coding rule is to uniformly identify and classify multiple reference documents through standardized coding logic. This allows the core attributes of reference documents, such as their source, category, and level, to be intuitively represented through coding. This provides fundamental support for the orderly storage and rapid indexing of the subsequent knowledge base, and also provides accurate identification criteria for entity-document association mapping in KG construction and source tracing in RAG retrieval. The coding system achieves unique identification of reference documents through a four-level combination, completely solving the problem of chaotic identification in traditional knowledge bases. Its reserved extension bits give the system strong flexibility, allowing seamless adaptation to future additions of reference document types and regions. The semantic information contained in the coding can serve as efficient filtering conditions, forming a dual optimization of "coarse coding screening + fine semantic screening" with vector and graph retrieval, significantly improving retrieval efficiency. Ultimately, this system achieves standardized management of multiple reference documents, providing reliable and low-cost underlying data support for knowledge augmentation through KG and RAG collaboration.
[0132] Example 3:
[0133] This embodiment is a further optimization based on the above embodiments. The similarities with the aforementioned technical solutions will not be repeated here. Furthermore, to better realize the "detection brain" content compliance review method based on KG and RAG collaborative knowledge enhancement described in this invention, in step S2, entity extraction is performed on each reference document in the reference document set, such as... Figure 3 As shown, it includes:
[0134] This paper employs a pre-trained Chinese word segmentation model, bert-base-chinese, to perform entity extraction. The aim is to address the shortcomings of traditional entity extraction methods, such as insufficient semantic understanding of professional domain documents, ambiguous entity boundary recognition, and low accuracy in category determination. This entity extraction process transforms the task into sentence-level word classification; specifically, for each sentence in each reference document... ,in, For sentences Individual words in the text encompass frequently occurring professional terms in the reference documents, such as standard numbers, regulation names, test items, issuing organizations, testing indicators, and judgment criteria; firstly, the sentence is analyzed using the bert-base-chinese model. Perform contextual semantic encoding to output the sentence. High-dimensional semantic vectors , ,in, For each word The corresponding high-dimensional semantic vectors contain rich context-dependent information; among them, the bert-base-chinese model relies on the semantic understanding ability formed by pre-training on massive Chinese corpus, which can accurately capture the contextual association of professional words in the field of software inspection and testing, and effectively overcome the defects of traditional word vector models that cannot handle polysemy and semantic isolation.
[0135] Then each word High-dimensional semantic vectors It is fed into a simple linear transformation layer and then through a learnable weight matrix. Perform feature mapping and bias terms After dynamic adjustment, precise enhancement of domain entity characteristics is achieved, and then through... The function transforms the mapped feature vectors into words. Probability distribution of various preset entity labels :
[0136] ;
[0137] In the formula: For each word The corresponding preset entity labels; among them, the preset entity label system has been pre-optimized for software testing and inspection scenarios, covering core categories such as standard number, regulation name, test item, issuing organization, testing indicator, judgment standard, and scope of application, to ensure coverage of the key entity types required for the construction of compliance knowledge graph;
[0138] Based on each word Probability distribution of various preset entity labels The entity label results that meet the probability threshold (e.g., the threshold is 0.85) are filtered out to obtain the results for each word. The entity labels can filter out low-probability noise data, ultimately outputting each word. The corresponding structured entity list; wherein, the structured entity list contains three types of core information: each word in the reference document. (Ensuring the original semantic integrity of entities), each word The associated entity tags (clearly defining the entity's attribute positioning within the compliance knowledge system), and each word The start-end position index in the reference document (provides a precise mapping basis for entity boundaries for subsequent relation extraction);
[0139] Construct an entity set for each reference document based on the structured entity list corresponding to all words in each reference document.
[0140] Example 4:
[0141] This embodiment is a further optimization based on the above embodiments. The similarities with the aforementioned technical solutions will not be repeated here. Furthermore, to better realize the "detection brain" content compliance review method based on KG and RAG collaborative knowledge enhancement described in this invention, in step S2, relations are extracted from each reference document in the reference document set to construct a knowledge graph corresponding to each reference document, such as... Figure 3 As shown, it includes:
[0142] For each reference document, a pipeline approach is used to perform relation extraction. The core objective is to accurately mine the semantic relationships between entities, solving the problems of chaotic entity pair matching, insufficient utilization of contextual information, and low accuracy in domain relation identification in traditional relation extraction, thus providing reliable edge connection data support for knowledge graph construction. Specifically, firstly, entity pairs are enumerated based on the entity set corresponding to each reference document, traversing all pairwise combinations of entities in the entity set to ensure that no potentially related entity pairs are missed; and secondly, a special input sequence is constructed for each entity pair based on its contextual content in the reference document. This special input sequence It includes "head entity - document context - tail entity", where the text context is selected as the smallest semantic unit in the reference document that contains the entity pair. This tightly binds the entity pair with its semantic environment, avoids misjudgment of relations caused by detachment from context, and effectively overcomes the shortcomings of traditional relation extraction that only rely on the entity itself and ignores contextual association.
[0143] The relation extraction task was transformed into a precise text classification task, using a pre-trained BERT-base-chinese model as the core relation classifier. This BERT-base-chinese model, relying on deep semantic understanding capabilities developed through training on massive amounts of Chinese corpus, can fully capture the semantic dependencies between entity pairs and context in the software inspection and testing domain (such as the logical relationship between "detection indicators" and "judgment criteria" in compliance clauses, and the correspondence between "regulatory names" and "scope of application"), significantly improving the ability to identify domain-specific relations. The BERT-base-chinese model was then used to analyze this specific input sequence. Perform global semantic encoding to output this special input sequence. [CLS] vector The [CLS] vector It condenses the entire special input sequence The global semantic information can comprehensively represent the combined relational features of the head entity, tail entity, and context.
[0144] Then the special input sequence [CLS] vector It is fed into a linear transformation layer and then through a learnable weight matrix. Perform feature mapping and bias terms After dynamic adjustment, the characteristics of domain relationships are precisely strengthened, and then through... The function transforms the mapped feature vectors into a probability distribution for each entity pair belonging to various preset relations. The formula is as follows:
[0145] ;
[0146] in, Each entity pair corresponds to a pre-defined relationship; among them, various pre-defined relationships cover the core association types in the field of software testing and inspection, including "compliance basis - scope of application", "test indicators - judgment criteria", "issuing organization - regulation name", "test item - technical requirements", etc., to ensure comprehensive coverage of the relationship types required for knowledge graph construction;
[0147] Based on the probability distribution of each entity pair belonging to various preset relationships By filtering out relationships whose probabilities meet a threshold, low-probability noisy associations can be eliminated, thus obtaining the relationship to which each entity belongs and ensuring the accuracy of relationship extraction; among which, based on the above probability distribution Set thresholds (supports dynamic optimization based on domain scenarios);
[0148] Based on the entity set corresponding to each reference document and the relationships associated with each entity in that entity set, a complete knowledge graph data structure of "node-edge-attribute" is formed for each reference document. This design optimizes the entire process of "entity enumeration-context binding-semantic encoding-relation classification" through a pipeline, which not only solves the pain points of ambiguous associations and inaccurate relationship category determination of domain entities, but also enhances the efficiency of context information utilization through the global semantic encoding capability of the BERT-base-chinese model, ensuring that the relationship extraction results are highly consistent with the semantic logic of the reference documents. The complete knowledge graph data structure output provides clear entity association links for subsequent graph retrieval, and complements RAG retrieval, enabling the knowledge enhancement system to have both text detail recall capability and structured relationship mining capability, significantly improving the accuracy and interpretability of compliance review, and laying a core structured knowledge foundation for the efficient implementation of the entire method.
[0149] Example 5:
[0150] This embodiment is a further optimization based on the above embodiment. The similarities with the aforementioned technical solutions will not be repeated here. Furthermore, to better realize the "detecting brain" content compliance review method based on KG and RAG collaborative knowledge enhancement described in this invention, in step S2, each reference document in the reference document set is converted into a corresponding high-dimensional vector, such as... Figure 4 As shown, it includes:
[0151] Each reference document in the reference document set is semantically segmented to obtain multiple blocks within each document. Each reference document in the set undergoes preprocessing to remove redundant spaces, invalid symbols, and other interfering information. Then, each preprocessed reference document is semantically segmented to obtain multiple blocks within each document. This segmentation method fully aligns with the "layered clauses and logical coherence" characteristics of compliance documents, preserving the complete semantics of regulatory clauses better than fixed-length segmentation. Simultaneously, a parameter combination of a block size of 500 and a block overlap size of 50 is set. The block size of 500 is suitable for the typical length of a single section in Chinese compliance text, fully accommodating the core information of a single clause. The block overlap size of 50 ensures semantic continuity between adjacent blocks, preventing logical breaks in clauses due to segmentation and effectively reducing the loss of semantic information.
[0152] The first step involves dense vectorization, focusing on capturing deep semantic relationships within blocks to address the limitations of traditional keyword retrieval in understanding synonyms and contextual ambiguities. Dense vectorization is achieved using the LlamaIndex framework and the BGE-M3 Embedding model. This model, pre-trained on massive amounts of Chinese corpus, excels particularly in semantic encoding of professional domain texts, accurately capturing implicit relationships between professional terms such as "detection indicators" and "judgment criteria," and "compliance basis" and "applicable scenarios." Each block d from each reference document is input into the Embedding model. The Embedding model uses a multi-layer Transformer structure to perform contextual encoding on block d, encoding each word within block d. This is transformed into a dense vector containing semantic information, and finally the dense vector of each block d is output. , The representation method is as follows:
[0153] ;
[0154] In the formula: For block A word in the text; For words obtained through the Embedding model The dense vectors that incorporate the word Semantic features within the context of the reference document, rather than isolated word vectors; Given the total number of words in block d, ensure a dense vector. Completely covers all semantic information of the segment;
[0155] The second step is to perform sparse vectorization, which involves segmenting each block d in each reference document into words to obtain multiple word segments in each block d.
[0156] (1) Use the TF-IDF algorithm to perform sparse vectorization on the various word segments in each block d; the core of the TF-IDF algorithm is to use frequency... With importance The product of these terms quantifies the distinguishability of a word segment within its corresponding reference document. A specific word segmentation method... The frequency of occurrence in its corresponding block d is The formula is:
[0157] ;
[0158] In the formula: Indicates a certain type of participle Frequency of occurrence in its respective block d; Indicates block The total number of word segmentations in the text; Directly reflects word segmentation The degree of coreness within its respective block d, such as the high frequency of "software security" appearing in security regulations, naturally results in a higher TF value;
[0159] A certain type of word segmentation Its importance in the relevant reference document is: The formula is:
[0160] ;
[0161] In the formula: This indicates the total number of blocks in the associated reference document. This indicates that the referenced document contains a certain type of word segmentation. The number of blocks; by using logarithmic operations to weaken the weight of high-frequency common words, and to strengthen the distinguishability of rare words such as "specific standard number" and "exclusive detection indicator", we can ensure that these core search terms occupy a higher weight in the vector.
[0162] Then, the TF-IDF algorithm is used to obtain a certain word segmentation in block d. TF-IDF sparse vectors The formula is:
[0163] ;
[0164] This leads to the TF-IDF sparse vector for each block d. The formula is:
[0165] ;
[0166] In the formula: 𝑚 is the number of word segmentation types in block d;
[0167] (2) The BM25 algorithm is used to sparsely vectorize the various word segments in each block d. The BM25 algorithm, as an optimized relevance ranking function, is used to evaluate the relevance between the block and the query word segment, further solving the problem that the TF-IDF algorithm does not consider the difference in block length. It is especially suitable for scenarios where "long clauses and short clauses coexist" in the block. The BM25 algorithm can more accurately evaluate the actual relevance between the search term and the block. Especially when the user query contains specific law numbers and detection terms, it can quickly lock the high matching degree block.
[0168] First, the BM25 algorithm is used to obtain a certain word segmentation in block d. BM25 sparse vector The formula is:
[0169] ;
[0170] In the formula: For a certain type of word segmentation Importance within the relevant reference document; Indicates a certain type of participle The frequency of occurrence within its respective block d; and each parameter is optimized for the characteristics of the block: and All parameters are adjustable. The value is 1.2, which is in the middle of the [0,2] interval. This ensures that the word frequency has an impact on the relevance while avoiding excessive saturation of the weight of high-frequency words. The value is 0.75, which focuses on preserving the impact of document length within the range of [0,1], while avoiding weight bias for extremely long documents; For the corresponding block Length, The average length of all blocks in the reference document is used as the ratio to dynamically adjust the impact of block length on the results, ensuring the fairness of the correlation calculation between long and short clause blocks.
[0171] It should be noted that, To control the parameters of word frequency saturation, when When the frequency is large, the saturation of word frequency is high, meaning that the influence of word frequency on BM25 value gradually weakens as word frequency increases. To control the parameters of block length saturation, when When the block length is large, the effect of the block length on the BM25 value gradually weakens as the block length increases.
[0172] This leads to the BM25 sparse vector for each block d. The formula is:
[0173] ;
[0174] In the formula: 𝑚 is the number of word segmentation types in block d;
[0175] The sparse vectorization process described above focuses on the frequency and importance characteristics of keywords in block d, compensating for the shortcomings of dense vectors in precise keyword matching and addressing the practical need in compliance reviews to "quickly locate text containing specific regulatory numbers and testing terms." The process begins with word segmentation of the reference document, using a word segmentation tool adapted to professional Chinese text to ensure complete segmentation of professional terms and standard numbers such as "GB / T 25000.51-2016" and "functional testing," avoiding keyword loss due to segmentation errors. Subsequently, sparse vectors are constructed using the TF-IDF and BM25 algorithms respectively. These two algorithms complement each other—the TF-IDF algorithm emphasizes the importance of words in a single block, while the BM25 algorithm optimizes the weighted relationship between word frequency and block length through a probabilistic model, making it more suitable for multi-document retrieval scenarios.
[0176] The third step is vector fusion, which involves dense vectors from all blocks d of all reference documents. TF-IDF sparse vectors and BM25 sparse vector The data is stored in a vector database; the integrated knowledge base for "detecting the brain" is constructed based on all blocks d of all reference documents, the corresponding vector database, and the corresponding knowledge graph.
[0177] It should be noted that the above vectorization process is executed step by step based on the core principles of semantic integrity and retrieval usability of the reference documents. This vectorization process innovatively adopts a dual-path architecture of "dense vectorization + sparse vectorization". The core purpose is to solve the shortcomings of single vectorization methods in reference document retrieval, such as "semantic ambiguity" or "loss of details". By complementing the advantages of the two vectors, it provides feature support for subsequent RAG hybrid retrieval that takes into account both semantic depth and keyword accuracy, ensuring the comprehensiveness and accuracy of compliance knowledge retrieval.
[0178] It should be noted that the aforementioned dual-path vectorization design enables the reference document to possess the advantages of both "deep semantic understanding" and "precise keyword positioning": dense vectors capture the contextual semantics of the reference document through the BGE-M3 model, solving the semantic matching problem for fuzzy user queries (such as "software data security compliance requirements"); sparse vectors, through the collaboration of TF-IDF and BM25, ensure efficient recall for precise keyword queries (such as "GB / T 25000.51-2016 clauses"). This architecture overcomes the shortcomings of "weak keyword response" in single dense vector retrieval and compensates for the "poor semantic understanding" in single sparse vector retrieval, providing a high-quality vector foundation for subsequent RAG hybrid retrieval, directly improving the accuracy and efficiency of compliance knowledge retrieval, and providing core technical support for the efficient review of the "detection brain".
[0179] Example 6:
[0180] This embodiment is a further optimization based on the above embodiment. The similarities with the aforementioned technical solutions will not be repeated here. To further better realize the "Detection Brain" content compliance review method based on KG and RAG collaborative knowledge enhancement described in this invention, in step S4, the inspection and testing report of the software to be reviewed is converted into a corresponding retrieval vector, and the retrieval vector is compared with the high-dimensional vector in the "Detection Brain" integrated knowledge base for similarity. Then, based on the comparison result, highly relevant reference documents are retrieved from the "Detection Brain" integrated knowledge base, such as... Figure 5 As shown, it includes:
[0181] The inspection and testing report of the software to be reviewed is divided into multiple text blocks. Each text block is obtained through the Embedding model. The dense vectors are obtained; the TF-IDF algorithm and the BM25 algorithm are used to obtain each text block respectively. TF-IDF sparse vectors and BM25 sparse vectors;
[0182] It should be noted that each text block was obtained using the TF-IDF algorithm and the BM25 algorithm respectively. Before generating TF-IDF sparse vectors and BM25 sparse vectors, first divide multiple text blocks... The text is fed into a word segmenter for semantic word segmentation. The word segmentation process strictly follows the terminology standards of Chinese semantic logic and software testing, dividing the complete text blocks into segments. The text is broken down into several independent lexical units, retaining core domain terms such as "inspection standards," "testing indicators," and "compliance requirements," while also including common modifiers, ensuring comprehensive capture of key information nodes in the text. After word segmentation, the TF-IDF and BM25 algorithms are used to calculate the corresponding TF-IDF sparse vector and BM25 sparse vector for each segmented word, respectively, to obtain each text block. TF-IDF sparse vectors and BM25 sparse vectors.
[0183] The two classic sparse vector algorithms are used in combination: the TF-IDF algorithm excels at highlighting keywords that appear frequently in the text block but are scarce in the entire software inspection report by measuring the word frequency in the text block and their importance in the entire software inspection report, thus effectively identifying core semantic identifiers; while the BM25 algorithm optimizes the word frequency saturation problem based on the TF-IDF algorithm by introducing a text block length normalization mechanism, which is more suitable for handling text blocks of varying lengths in the software inspection field, avoiding similarity calculation bias caused by differences in text block length, while enhancing sensitivity to medium-frequency keywords and improving the balance of retrieval.
[0184] The first step is to perform a mixed text search: Before initiating the mixed text search, the user's submitted software testing and inspection compliance review request is accurately received, and the software testing and inspection report to be reviewed is obtained simultaneously. Considering that the original report often has problems such as lengthy text, complex information hierarchy, and core compliance points being wrapped in redundant content, directly searching it may easily lead to an excessively large search scope and dilute the target information, seriously affecting search efficiency and accuracy. Therefore, it is necessary to first perform fine-grained paragraph segmentation processing on the report to be reviewed, dividing the software testing and inspection report into multiple text blocks. Then, the high-performance BGE-M3 embedding model was selected as the semantic encoding core. In the specific implementation, the BGE-M3 embedding model was used to process each text block after the report was split. Semantic encoding is performed one by one, dividing each text block It is transformed into a high-dimensional dense vector, and the vector dimension is strictly calibrated during the encoding process to ensure that each generated text block is... The dense vectors are completely identical in dimension to the dense vectors in the "Detecting the Brain" knowledge base. This design eliminates the similarity calculation error caused by the mismatch in vector dimensions from the root, ensuring the accuracy and effectiveness of subsequent retrieval calculations.
[0185] A text block in the inspection and testing report of the software to be reviewed The dense vector of the text block is compared with the dense vector of each block d in the vector database to obtain the similarity of the text block. Dense vector similarity with each block d The formula is:
[0186] ;
[0187] in, For a certain text block Dense vectors, For each block d in the vector database, a dense vector. The dot product of two dense vectors. For a certain text block The magnitude of a dense vector, The magnitude of the dense vector for each block d represents their size; dense vector The dimensional components, dense vector The dimensional components, The dimension of the dense vector;
[0188] It should be noted that the similarity calculation process uses the cosine similarity algorithm. The core advantage of this algorithm lies in its ability to accurately measure the semantic relevance of the texts represented by two vectors, unaffected by the absolute numerical value of the vectors, focusing only on the semantic features mapped by the vector directions. Even when the wording of the report to be reviewed differs from that of the knowledge base text, but the core compliance semantics are consistent, this algorithm can still accurately identify the relationship between the two, effectively solving the problem of missing relevant information due to different wording in traditional retrieval methods.
[0189] The second step is to perform sparse vector retrieval similarity matching: This involves matching a text block from the software inspection report to be reviewed. The TF-IDF sparse vector of the text block is compared with the TF-IDF sparse vector of each block d in the vector database to obtain the similarity of the text block. TF-IDF sparse vector similarity with each block d Simultaneously, a text block from the inspection and testing report of the software under review... The BM25 sparse vector is compared with the BM25 sparse vector of each block d in the vector database to obtain the text block. BM25 sparse vector similarity with each block d ;
[0190] It should be noted that sparse vector retrieval similarity matching aims to compensate for the shortcomings of single dense vector retrieval in terms of precise keyword matching and capturing the correlation of surface information in text. By mining the statistical features and frequency information of keywords in the text, it complements dense vector retrieval, further improving the comprehensiveness and accuracy of retrieval results, and solving the problem of insufficient retrieval of relevant information in software inspection and testing compliance review due to the diversity of semantic expressions and the concealment of core keywords.
[0191] Thirdly, to fully leverage the advantages of both the TF-IDF and BM25 algorithms and avoid the limitations of a single algorithm, the system ultimately adopts a linear weighted fusion strategy; this text block... TF-IDF sparse vector similarity with each block d Similarity to BM25 sparse vectors Perform weighted fusion to obtain the text block. Sparse vector fusion similarity between each block d The formula is:
[0192] ;
[0193] In the formula, , Let be the weight parameters, and satisfy ? + = 1;
[0194] The fourth step is to use the Relative Score Fusion (RSF) algorithm to process the text block. Dense vector similarity with each block d Similarity fusion with sparse vectors Perform weighted fusion to obtain the text block. Final fusion similarity with each block d The formula is:
[0195] ;
[0196] In the formula, These are adjustable weight parameters;
[0197] It should be noted that the final fusion similarity The calculation aims to overcome the limitations of either single dense vector retrieval or sparse vector retrieval. The core logic is based on dense vector similarity. Similarity fusion with sparse vectors A systematic approach is adopted, specifically using a relative score fusion algorithm as the core of the fusion process. This algorithm effectively balances the weight of the two retrieval results, preventing a single result from dominating the fusion conclusion. It allows both the deep semantic associations captured by dense vector retrieval and the surface keyword associations mined by sparse vector retrieval to play their full role, ensuring that the fused result is both semantically consistent and does not miss any direct matches of key information.
[0198] Fifth step, based on the text block Final fusion similarity with each block d Multiple blocks in the "Detection Brain" integrated knowledge base are sorted in descending order, and the top-5 highly relevant blocks are selected as the final results of the first stage of text-based mixed retrieval. This selection mechanism ensures a high degree of relevance between highly relevant blocks and review requirements through similarity ranking, while limiting the number of highly relevant blocks to avoid information overload and reduced processing efficiency. This provides refined and efficient core reference information for subsequent KG and RAG collaborative knowledge enhancement stages. Its core advantage lies in achieving an organic balance between retrieval accuracy and efficiency, enabling rapid location of core references from a massive knowledge base, and significantly reducing judgment bias caused by missing or redundant information during the review process.
[0199] Example 7:
[0200] This embodiment is a further optimization based on the above embodiments. The similarities with the aforementioned technical solutions will not be repeated here. Furthermore, to better implement the "detection brain" content compliance review method based on KG and RAG collaborative knowledge enhancement described in this invention, the step involves selecting a text block from the inspection and testing report of the software to be reviewed. The TF-IDF sparse vector of the text block is compared with the TF-IDF sparse vector of each block d in the vector database to obtain the similarity of the text block. TF-IDF sparse vector similarity with each block d ,include:
[0201] For the TF-IDF algorithm, for a specific text block A certain type of word segmentation Using the TF-IDF algorithm to obtain a certain word segmentation TF-IDF sparse vectors Then a certain type of word segmentation TF-IDF sparse vector similarity between the block d and the segment d for:
[0202] ;
[0203] In the formula: 𝑚 is the number of word segmentation types in block d; For a certain type of word segmentation TF-IDF sparse vectors The dimensional vector; For block TF-IDF sparse vector of a certain word segment j The dimensional vector; Let be the total dimension of the vector; where TF-IDF algorithm is... TF-IDF sparse vectors Corresponding dimensional components and blocks TF-IDF sparse vector of a certain word segment j The corresponding dimensional components are multiplied one by one and then summed to obtain the dot product of the two; then the product is calculated separately. TF-IDF sparse vectors The square root of the sum of squares of the components in each dimension, and the block TF-IDF sparse vector of a certain word segment j The square root of the sum of the squares of the components of each dimension is the magnitude of the two vectors; finally, the ratio of the dot product result to the product of the magnitudes of the two vectors is calculated to obtain... With block The TF-IDF sparse vector similarity of a certain word segment j in the text. Among the n word segmentations in block d, the largest TF-IDF sparse vector similarity is selected as... TF-IDF sparse vector similarity between the block d and the segment d This score can be precisely quantified. The correlation strength between each block d in the knowledge base and the keyword statistical features;
[0204] According to the text block Each type of word segmentation TF-IDF sparse vector similarity between the block d and the segment d To obtain the text block TF-IDF sparse vector similarity with each block d .
[0205] Example 8:
[0206] This embodiment is a further optimization based on the above embodiments. The similarities with the aforementioned technical solutions will not be repeated here. Furthermore, to better implement the "detection brain" content compliance review method based on KG and RAG collaborative knowledge enhancement described in this invention, the step involves selecting a text block from the inspection and testing report of the software to be reviewed. The BM25 sparse vector is compared with the BM25 sparse vector of each block d in the vector database to obtain the text block. BM25 sparse vector similarity with each block d ,include:
[0207] For a certain text block A certain type of word segmentation Using the BM25 algorithm to obtain a certain word segmentation BM25 sparse vector Then a certain type of word segmentation BM25 sparse vector similarity between the block d and the segment d for:
[0208] ;
[0209] In the formula: 𝑚 is the number of word segmentation types in block d; For a certain type of word segmentation BM25 sparse vector The dimensional vector; For block BM25 sparse vector of a certain word segment j The dimensional vector; This represents the total dimension of the vector; where, in the calculation of the BM25 algorithm, for a certain type of word segmentation... Its similarity to the BM25 sparse vector of block d The calculation logic is consistent with the TF-IDF algorithm, only the vectors are replaced with the results vectorized by the BM25 algorithm: word segmentation is calculated similarly. BM25 sparse vector With block BM25 sparse vector of a certain word segment j The dot product of the vectors, divided by the product of the magnitudes of the two vectors, yields a certain word segmentation. With block The BM25 sparse vector similarity of a certain word segment j in the dataset. Among the n word segmentations in block d, the largest BM25 sparse vector similarity is selected as the... BM25 sparse vector similarity between the block d and the segment d This score not only inherits the precise matching advantage of keyword statistical features, but also improves the adaptability to texts of different lengths through algorithm optimization, making the similarity calculation more in line with the text characteristics of the software inspection and detection field.
[0210] According to the text block Each type of word segmentation BM25 sparse vector similarity between the block d and the segment d To obtain the text block BM25 sparse vector similarity with each block d .
[0211] Example 9:
[0212] This embodiment is a further optimization based on the above embodiments. The similarities with the aforementioned technical solutions will not be repeated here. Furthermore, to better realize the "Detection Brain" content compliance review method based on KG and RAG collaborative knowledge enhancement described in this invention, in step S4, entity extraction is performed on the inspection and testing report of the software to be reviewed, and highly relevant subgraphs are selected from the knowledge graph within the integrated knowledge base of the "Detection Brain" based on the entity extraction results of the inspection and testing report of the software to be reviewed. Figure 5 As shown, it includes:
[0213] This invention sets up a graph retrieval stage in the second phase of the search process. This stage is designed to compensate for the shortcomings of the first-stage text-based mixed retrieval in capturing structured knowledge associations. By mining the explicit association paths between entities in the "software inspection and testing" knowledge graph, it extracts structured compliance information that is difficult to directly reflect at the text level. The text blocks obtained after the software inspection and testing report undergoes fine-grained paragraph segmentation are sent to the jieba word segmenter for semantic word segmentation. The word segmentation process fully incorporates the terminology characteristics of the software inspection and testing field, following the logic of Chinese semantic segmentation while retaining core terms in areas such as "inspection standards," "testing methods," "compliance clauses," and "technical indicators." At the same time, it avoids the interference of meaningless stop words on subsequent entity retrieval, ensuring that the word segmentation results accurately cover the key information nodes in the user's needs, providing high-quality input for subsequent entity recognition and matching.
[0214] After word segmentation, entity retrieval is performed using the longest entity-first matching strategy, with the knowledge graph G as the core support. This matching strategy prioritizes the identification and matching of long, multi-character domain entities contained in the user input, effectively avoiding problems such as mismatching of short entity fragments and omission of long entities due to segmentation. Through this strategy, core entities from all domains are comprehensively extracted from the word segmentation results of the text block to obtain the entity set for the software inspection report to be reviewed. , where entity set , For entity collection The i-th entity in ; , These are the name and the identifier, respectively.
[0215] Using the breadth-first search algorithm , entity collection Each entity pair in Path search is performed on multiple knowledge graphs G within the integrated "brain detection" knowledge base, using the following formula:
[0216] ;
[0217] In the formula: This represents the de novo entities retrieved from multiple knowledge graphs G for each entity pair. End-to-end entity Length not exceeding All paths; where, limited The length of 3 is chosen to comprehensively consider the knowledge association characteristics in the software inspection and testing field. A search length that is too short may fail to uncover indirect compliance information between entities, while a search length that is too long can introduce irrelevant paths, leading to information redundancy. Setting the length to 3 ensures that the core logical chain of "entity-directly related entity-indirectly related entity" is covered, while effectively controlling the search scope and guaranteeing retrieval efficiency. The application of the breadth-first search algorithm ensures that entities are searched from the beginning. Starting from this point, it can traverse all reachable related entities layer by layer without missing any potential related entities.
[0218] To improve the effectiveness and refinement of subgraph retrieval results, the entity set... Each entity in the set is filtered through all paths in multiple knowledge graphs G to obtain the entity set. The shortest path for each entity pair in the set of knowledge graphs G, and based on the entity set. The most concise path of all entity pairs in multiple knowledge graphs G is used to obtain the highly relevant subgraph, which serves as the final result of the second-stage graph retrieval.
[0219] The selection principle for the simplest path is as follows: (1) The path length is defined by the number of edges contained in the path. For the same entity pair In multiple paths in multiple knowledge graphs G, the path with the shortest length is retained first, i.e., the shortest path; the shortest path can directly reflect the close relationship between entities and can quickly locate the structured knowledge most relevant to compliance review requirements; (2) for the entity set Different entity pairs in If different entities pair If there are overlaps among all the corresponding shortest paths, the longer path among the overlapping paths is retained to improve the efficiency of knowledge utilization.
[0220] Example 10:
[0221] This embodiment is a further optimization based on the above embodiments. The similarities with the aforementioned technical solutions will not be repeated here. Furthermore, to better realize the "detection brain" content compliance review method based on KG and RAG collaborative knowledge enhancement described in this invention, as follows... Figure 5 As shown, steps S5 and S6 include:
[0222] The structured knowledge is embedded into a pre-defined structured prompt template to generate structured prompts that meet the input requirements of the LLM large language model. This structured prompt template has been specifically optimized for software inspection and compliance review scenarios, pre-defined with a clear information presentation format, review logic guidance, and result output requirements. It organizes structured knowledge materials in a way that is easily understood by the large model, constructing complete and logically coherent input instructions. This structured input method effectively solves the problem of information clutter and lack of emphasis on key points in traditional natural language input, leading to comprehension biases in large models. It allows the large model to quickly grasp the core knowledge and logical framework required for compliance review.
[0223] The structured prompts and structured knowledge are input into the LLM (Large Language Model) to output the compliance review results of the software inspection and testing report to be reviewed. During processing, the LLM model, guided by the input structured knowledge materials and prompts, and combined with the business rules and judgment standards for software inspection and testing compliance review, comprehensively analyzes and judges the compliance of the software inspection and testing report. Ultimately, the LLM model outputs accurate, interpretable compliance review results that fully meet the requirements of the "inspection brain" compliance review scenario. The compliance review results comprehensively cover the compliance judgment conclusion, legal basis citations, details of non-compliance items, and targeted rectification suggestions.
[0224] In summary, the "Detection Brain" content compliance review method based on KG and RAG collaborative knowledge enhancement provided in this invention first collects and standardizes relevant domestic and international software testing and inspection regulations, constructing an integrated "Detection Brain" knowledge base containing knowledge graphs and text vectors. Then, it obtains highly relevant text fragments and subgraphs through a dual-path approach of mixed text retrieval (dense + sparse vector fusion) and graph retrieval. Finally, it fuses the two types of results to generate structured prompt words, inputs them into an LLM (Limited Language Model), and outputs accurate and interpretable compliance review results. This method solves the technical problems of low efficiency in traditional manual review, insufficient accuracy of single-technology retrieval, and the "illusion" of large models, significantly improving the efficiency, accuracy, and interpretability of software testing and inspection compliance review.
[0225] The above description only details the preferred embodiments of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
[0226] It should be understood that although the steps in the flowcharts of the various embodiments of the present invention are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the various embodiments may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least a portion of the sub-steps or stages of other steps.
[0227] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0228] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the disclosure in the specification and embodiments. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and embodiments are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the claims.
Claims
1. A content compliance review method based on KG and RAG collaborative knowledge enhancement, characterized in that, Includes the following steps: Step S1: Collect multiple original documents related to software inspection and detection to construct an original document set; and preprocess the multiple original documents in the original document set to obtain a reference document set; wherein, the reference document set includes multiple ordered reference documents; Step S2: On the one hand, entity extraction and relation extraction are performed on each reference document in the reference document set to construct a knowledge graph corresponding to each reference document; on the other hand, each reference document in the reference document set is transformed into a corresponding high-dimensional vector. Step S3: Construct an integrated knowledge base for "detecting the brain" based on multiple reference documents, corresponding high-dimensional vectors, and corresponding knowledge graphs; Step S4: Receive the software inspection and testing report to be reviewed input by the user; on the one hand, convert the software inspection and testing report to be reviewed into a corresponding retrieval vector, and compare the similarity of the retrieval vector with the high-dimensional vector in the "Detection Brain" integrated knowledge base, and then retrieve highly relevant reference documents from the "Detection Brain" integrated knowledge base based on the comparison results; on the other hand, perform entity extraction on the software inspection and testing report to be reviewed, and select highly relevant subgraphs from the knowledge graph in the "Detection Brain" integrated knowledge base based on the entity extraction results of the software inspection and testing report to be reviewed. Step S5: The highly relevant reference documents and the highly relevant subgraphs are fused to form structured knowledge, and structured prompt words are generated based on the structured knowledge; Step S6: Based on the structured prompts and the structured knowledge, output the compliance review results of the inspection and testing report of the software to be reviewed.
2. The content compliance review method for "detecting the brain" based on KG and RAG collaborative knowledge enhancement according to claim 1, characterized in that, The preprocessing of multiple original documents in the original document set to obtain a reference document set includes: The pre-trained PaddleOCR-VL model is used to preprocess multiple original documents in the original document set to obtain multiple reference documents; Multiple reference documents are encoded to obtain multiple ordered reference documents, and the reference document set is constructed based on the multiple ordered reference documents.
3. The content compliance review method for "detecting the brain" based on KG and RAG collaborative knowledge enhancement according to claim 1, characterized in that, In step S2, entity extraction is performed on each reference document in the reference document set, including: For each sentence in each reference document ,in, For sentences Individual words in the sentence are processed using the bert-base-chinese model. Perform contextual semantic encoding to output the sentence. context vector , ,in, For each word The corresponding high-dimensional semantic vector will divide each word High-dimensional semantic vectors It is fed into a linear transformation layer and then passed through a weight matrix. Mapping and bias terms After adjustment, then through The function calculates each word Probability distribution of various preset entity labels : ; In the formula: For each word Corresponding preset entity tags; Based on each word Probability distribution of various preset entity labels Filter out entity label results whose probability meets the threshold to obtain each word The entity tags of each word are used to output the final output. The corresponding structured entity list; wherein, the structured entity list contains three types of core information: each word in the reference document. Each word The associated entity tag, each word Start-end position index in the reference document; Construct an entity set for each reference document based on the structured entity list corresponding to all words in each reference document.
4. The content compliance review method for "detecting the brain" based on KG and RAG collaborative knowledge enhancement according to claim 3, characterized in that, In step S2, relation extraction is performed on each reference document in the reference document set to construct a knowledge graph corresponding to each reference document, including: Entity pairs are enumerated based on the entity set corresponding to each reference document, and a special input sequence corresponding to each entity pair is constructed based on each entity pair and its context content in the reference document. This special input sequence It contains "head entity - document context - tail entity"; this special input sequence is processed through the bert-base-chinese model. Perform semantic encoding to output this specific input sequence. [CLS] vector ; Special input sequence [CLS] vector It is fed into a linear transformation layer and then passed through a weight matrix. Mapping and bias terms After adjustment, then through The function calculates the probability distribution of each entity pair belonging to various preset relations. The formula is as follows: ; in, It is the preset relationship corresponding to each entity pair; Based on the probability distribution of each entity pair belonging to various preset relationships The results of relationships whose probabilities meet the threshold are filtered out to obtain the relationship to which each entity belongs; A knowledge graph is constructed for each reference document based on the entity set corresponding to each reference document and the relationships between each entity pair in that entity set.
5. The content compliance review method for "detecting the brain" based on KG and RAG collaborative knowledge enhancement according to claim 1, characterized in that, In step S2, each reference document in the reference document set is converted into a corresponding high-dimensional vector, including: Semantic segmentation is performed on each reference document in the reference document set to obtain multiple blocks in each reference document; The first step is dense vectorization, which involves inputting each block d from each reference document into the embedding model to output a dense vector for each block d. , The representation method is as follows: ; In the formula: For block A word in the text; For words obtained through the Embedding model Dense vectors, The total number of words in block d; The second step is to perform sparse vectorization, which involves segmenting each block d in each reference document into words to obtain multiple word segments in each block d. (1) Use the TF-IDF algorithm to perform sparse vectorization on the various word segments in each block d; a certain word segmentation The frequency of occurrence in its corresponding block d is The formula is: ; In the formula: Indicates a certain type of participle Frequency of occurrence in its respective block d; Indicates block Total number of word segmentations in the text; A certain type of word segmentation Its importance in the relevant reference document is: The formula is: ; In the formula: This indicates the total number of blocks in the associated reference document. This indicates that the referenced document contains a certain type of word segmentation. The number of blocks; Then, the TF-IDF algorithm is used to obtain a certain word segmentation in block d. TF-IDF sparse vectors The formula is: ; This leads to the TF-IDF sparse vector for each block d. The formula is: ; In the formula: 𝑚 is the number of word segmentation types in block d; (2) Use the BM25 algorithm to perform sparse vectorization on the various word segments in each block d; first, use the BM25 algorithm to obtain a certain word segment in block d. BM25 sparse vector The formula is: ; In the formula: For a certain type of word segmentation Importance within the relevant reference document; Indicates a certain type of participle Frequency of occurrence in its respective block d; and All parameters are adjustable; For the corresponding block Length; This is the average length of all blocks in the corresponding reference document; This leads to the BM25 sparse vector for each block d. The formula is: ; In the formula: 𝑚 is the number of word segmentation types in block d; The third step is vector fusion, which involves dense vectors from all blocks d of all reference documents. TF-IDF sparse vectors and BM25 sparse vector The data is stored in a vector database; the integrated knowledge base for "detecting the brain" is constructed based on all blocks d of all reference documents, the corresponding vector database, and the corresponding knowledge graph.
6. The content compliance review method for "detecting the brain" based on KG and RAG collaborative knowledge enhancement according to claim 5, characterized in that, In step S4, the software inspection and testing report to be reviewed is converted into a corresponding retrieval vector, and the retrieval vector is compared with the high-dimensional vector in the "Detection Brain" integrated knowledge base for similarity. Then, based on the comparison result, highly relevant reference documents are retrieved from the "Detection Brain" integrated knowledge base, including: The inspection and testing report of the software to be reviewed is divided into multiple text blocks. Each text block is obtained through the Embedding model. The dense vectors are obtained by using both the TF-IDF and BM25 algorithms to obtain each text block. TF-IDF sparse vectors and BM25 sparse vectors; The first step is to extract a text block from the inspection and testing report of the software to be reviewed. The dense vector of the text block is compared with the dense vector of each block d in the vector database to obtain the similarity of the text block. Dense vector similarity with each block d The formula is: ; in, For a certain text block Dense vectors, For each block d in the vector database, a dense vector. The dot product of two dense vectors. For a certain text block The magnitude of a dense vector, Let be the magnitude of the dense vector for each block d. dense vector The dimensional components, dense vector The dimensional components, The dimension of the dense vector; The second step is to extract a text block from the inspection and testing report of the software to be reviewed. The TF-IDF sparse vector of the text block is compared with the TF-IDF sparse vector of each block d in the vector database to obtain the similarity of the text block. TF-IDF sparse vector similarity with each block d Simultaneously, a text block from the inspection and testing report of the software under review... The BM25 sparse vector is compared with the BM25 sparse vector of each block d in the vector database to obtain the text block. BM25 sparse vector similarity with each block d ; The third step is to modify the text block. TF-IDF sparse vector similarity with each block d Similarity to BM25 sparse vectors Perform weighted fusion to obtain the text block. Sparse vector fusion similarity between each block d The formula is: ; In the formula, , These are weight parameters; The fourth step is to process the text block. Dense vector similarity with each block d Similarity fusion with sparse vectors Perform weighted fusion to obtain the text block. Final fusion similarity with each block d The formula is: ; In the formula, These are weight parameters; Fifth step, based on the text block Final fusion similarity with each block d The multiple blocks in the "Brain Detection" integrated knowledge base are sorted in descending order, and the top-5 highly relevant blocks are selected from the "Brain Detection" integrated knowledge base.
7. The content compliance review method for "detecting the brain" based on KG and RAG collaborative knowledge enhancement according to claim 6, characterized in that, The text block in the inspection and testing report of the software to be reviewed The TF-IDF sparse vector of the text block is compared with the TF-IDF sparse vector of each block d in the vector database to obtain the similarity of the text block. TF-IDF sparse vector similarity with each block d ,include: For a certain text block A certain type of word segmentation Using the TF-IDF algorithm to obtain a certain word segmentation TF-IDF sparse vectors Then a certain type of word segmentation TF-IDF sparse vector similarity between the block d and the segment d for: ; In the formula: 𝑚 is the number of word segmentation types in block d; For a certain type of word segmentation TF-IDF sparse vectors The dimensional vector; For block TF-IDF sparse vector of a certain word segment j The dimensional vector; This represents the total dimension of the vector. According to the text block Each type of word segmentation TF-IDF sparse vector similarity between the block d and the segment d To obtain the text block TF-IDF sparse vector similarity with each block d .
8. The content compliance review method for "detecting the brain" based on KG and RAG collaborative knowledge enhancement according to claim 6, characterized in that, The text block in the inspection and testing report of the software to be reviewed The BM25 sparse vector is compared with the BM25 sparse vector of each block d in the vector database to obtain the text block. BM25 sparse vector similarity with each block d ,include: For a certain text block A certain type of word segmentation Using the BM25 algorithm to obtain a certain word segmentation BM25 sparse vector Then a certain type of word segmentation BM25 sparse vector similarity between the block d and the segment d for: ; In the formula: 𝑚 is the number of word segmentation types in block d; For a certain type of word segmentation BM25 sparse vector The dimensional vector; For block BM25 sparse vector of a certain word segment j The dimensional vector; This represents the total dimension of the vector. According to the text block Each type of word segmentation BM25 sparse vector similarity between the block d and the segment d To obtain the text block BM25 sparse vector similarity with each block d .
9. The content compliance review method for "detecting the brain" based on KG and RAG collaborative knowledge enhancement according to claim 1, characterized in that, In step S4, entity extraction is performed on the inspection and testing report of the software to be reviewed, and highly relevant subgraphs are selected from the knowledge graph within the integrated knowledge base of the "Detection Brain" based on the entity extraction results of the inspection and testing report of the software to be reviewed, including: Entity extraction is performed on the inspection and testing report of the software to be reviewed to obtain the entity set of the inspection and testing report of the software to be reviewed. , where entity set , For entity collection The i-th entity in ; Using the breadth-first search algorithm , entity collection Each entity pair in A path search is performed on multiple knowledge graphs G within the integrated "brain detection" knowledge base, using the following formula: ; In the formula: This represents the de novo entities retrieved from multiple knowledge graphs G for each entity pair. End-to-end entity Length not exceeding All paths; For the entity set Each entity in the set is filtered through all paths in multiple knowledge graphs G to obtain the entity set. The shortest path for each entity pair in the set of knowledge graphs G, and based on the entity set. The most concise path of all entity pairs in multiple knowledge graphs G is used to obtain the highly relevant subgraph; The selection criteria for the simplest path are: (1) the path length is defined by the number of edges contained in the path, for the same entity pair (2) Among multiple paths in multiple knowledge graphs G, the path with the shortest length is retained first; (3) For the entity set Different entity pairs in If different entities pair If there are overlaps among all the corresponding shortest paths, the longer path among the overlapping paths is retained.
10. The content compliance review method for "detecting the brain" based on KG and RAG collaborative knowledge enhancement according to claim 1, characterized in that, Steps S5 and S6 include: The structured knowledge is embedded into a preset structured prompt word template to generate structured prompt words that meet the input requirements of the LLM large language model; The structured prompts and structured knowledge are input into the LLM large language model to output the compliance review results of the inspection and testing report of the software to be reviewed.