Dynamically updated law and regulation knowledge graph construction and recall method
By constructing a dynamically updated legal knowledge graph, the problem of insufficient logical connection and hierarchical relationship expression in legal information processing is solved, realizing efficient and accurate legal knowledge retrieval and reasoning, and meeting the needs of in-depth legal analysis.
Patent Information
- Application Number
- CN202511634382.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-10
- Publication Date
- 2026-02-03
AI Technical Summary
Existing methods for processing and retrieving legal and regulatory information are insufficient to effectively model the logical connections and applicable conditions between provisions, resulting in a lack of contextual coherence in search results. They fail to accurately express the hierarchical relationships between laws and regulations at different levels, and complex reasoning is limited, thus failing to meet the needs of in-depth legal analysis.
We construct enhanced vectors that integrate full-text contextual semantics with attribute-rich knowledge graphs. Through regularized segmentation, structured transformation, semantic processing, composite vectorization, and triple fusion, we achieve real-time collection, structured transformation, and dynamic updating of legal and regulatory knowledge. Combined with semantic retrieval and graph reasoning, we achieve precise recall.
It improves the accuracy of semantic expression and the coverage of question recall, ensures the real-time nature and reasoning ability of the knowledge graph, can quickly respond to user queries, and meet the real-time recall and dynamic update requirements of complex legal questions and answers.
Smart Images

Figure CN121457587A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of artificial intelligence and knowledge graph technology, and particularly relates to a method for dynamically updating a legal regulation knowledge graph and recall. BACKGROUND
[0002] In the scenarios of legislative deliberation, archival review, and legal information retrieval, it is a core requirement to quickly and accurately obtain legal basis and related knowledge. However, existing legal regulation information processing and retrieval methods generally rely on text-based or vector-based semantic matching strategies, which have the following shortcomings:
[0003] (1) Insufficient logical relationship expression: it is difficult to effectively model and capture the logical connection and application conditions between provisions, resulting in a lack of contextual coherence in query results;
[0004] (2) Missing hierarchy and effectiveness: it is difficult to accurately express and process the superior-inferior relationship and application priority between different levels of legal regulations, affecting the correct application of legal provisions;
[0005] (3) Limited complex reasoning: when dealing with multi-step problem reasoning across provisions and regulations, it is difficult to provide systematic and structured answers, and it is difficult to meet the needs of in-depth legal analysis.
[0006] Similar challenges exist not only in the legal regulation field, but also in scenarios involving the management and query of a large number of provisions and standardized documents (such as medical standards, industry standards, and contract texts). Therefore, there is an urgent need for a solution that can dynamically update a knowledge graph and integrate semantic and structural features to improve the recall and reasoning capabilities of complex problems. SUMMARY
[0007] To address the shortcomings of existing technologies, the present application provides a method for dynamically updating a legal regulation knowledge graph and recall. The present application constructs an enhanced vector that integrates full-text context semantics and a knowledge graph that is rich in attributes, and cooperatively performs semantic retrieval and graph reasoning, thereby accurately and efficiently achieving real-time recall and dynamic updating of complex regulation question answering.
[0008] To achieve the above-mentioned purpose, the present application provides the following technical solution: a method for dynamically updating a legal regulation knowledge graph and recall, comprising:
[0009] Step S1: Real-time collection of legal regulation databases to obtain legal regulation text data;
[0010] Step S2: Regular fragmentation processing of the legal regulation text data to identify the provision structure and divide it into multiple provision units, and structured conversion of each provision unit to generate a sequence of structured provision objects;
[0011] Step S3, full-text structure recognition and semantic processing are performed on the legal regulation text data to generate segmented-level semantic data and full-text-level semantic data; wherein the segmented-level semantic data includes: a segmented preface outline path, a segmented summary, and a segmented triple corresponding to each article segment; and the full-text-level semantic data includes: full-text metadata and full-text triples;
[0012] Step S4, a context-enhanced semantic vector is generated by performing complex vectorization on the structured article object, the segmented preface directory outline, and the segmented summary;
[0013] Step S5, the full-text triples and the segmented triples are fused, and the relationship attribute information is enhanced to generate fused triples;
[0014] Step S6, the context-enhanced semantic vector is stored in a vector database, and the structured article object sequence and the segmented-level semantic data are stored in an original data index to establish a corresponding relationship;
[0015] Step S7, the fused triples are imported into a graph database to construct a knowledge graph;
[0016] Step S8, based on the knowledge graph, a user query is responded to, entity recognition, semantic expansion, multi-hop graph query, and result fusion are performed, and a structured answer is output.
[0017] Further, the regular segmentation process in step S2 specifically includes:
[0018] Step S21, the legal regulation text data is segmented using a regular expression pattern matching method based on regulation clause structure to obtain an article unit sequence containing a plurality of article units;
[0019] Step S22, the structure integrity of each article unit is checked, and a check log is output;
[0020] Step S23, the article units that pass the check are converted into article objects with a unified field structure, and a plurality of the article objects form the structured article object sequence, wherein the field structure at least includes article number, article title, and article content.
[0021] Further, the full-text structure recognition and semantic processing process in step S3 specifically includes:
[0022] Step S31, a pre-trained language model is used to recognize the full-text directory structure to generate the segmented preface outline path to which each article segment belongs;
[0023] Step S32, the pre-trained language model generates a segment summary representing the core semantics of each legal provision fragment;
[0024] Step S33, based on statistical characteristics, key entities are extracted from each legal provision fragment, and a segment triple is constructed with the document topic as the starting point;
[0025] Step S34, the full-text metadata describing the overall properties of the regulation is extracted from the full-text dimension;
[0026] Step S35, the full-text triple of the global relationship between entities is extracted from the full-text dimension.
[0027] Further, the construction of the segment triple includes:
[0028] Based on the TF-IDF algorithm, the word weight is calculated and the key entity is extracted from the legal provision fragment;
[0029] Taking the document title as the starting entity and the extracted key entity as the target entity, the relationship predicate is generated by injecting relationship cues into the pre-trained language model, thereby forming the segment triple;
[0030] When a single relationship cue does not work well, multiple relationship cues are used with the pre-trained language model to obtain an enhanced triple set with richer relationship descriptions.
[0031] Further, the step S4 includes:
[0032] Step S41, the text content of the legal provision fragment is first vectorized to obtain a content vector;
[0033] Step S42, the segment preface outline path and the segment summary are text-spliced to obtain a context description text, and the spliced context description text is second vectorized to obtain a context vector;
[0034] Step S43, the content vector and the context vector are spliced and combined to generate the context-enhanced semantic vector with both local semantics and global context information.
[0035] Further, the step S5 includes:
[0036] Step S51, the full-text triple and each segment triple are merged;
[0037] Step S52, context attribute information is added to each triple relationship, and the context attribute includes source, title, category, and metadata.
[0038] Further, the step S7 specifically comprises:
[0039] Step S71, converting the fusion triple into a structured data file that can be batch imported into a graph database;
[0040] Step S72, loading the structured data file and performing node deduplication operation based on node primary key and relationship merging operation based on relationship uniqueness during the import process, thereby constructing the knowledge graph.
[0041] Further, the step S8 specifically comprises:
[0042] Step S81, identifying a set of entity nouns from the user query;
[0043] Step S82, vectorizing each entity in the set of entity nouns and performing similarity retrieval in the vector database to obtain a set of semantic expansion entities for each entity;
[0044] Step S83, performing Cartesian product operation on all obtained sets of semantic expansion entities to generate a set of candidate entity pairs;
[0045] Step S84, for each entity pair in the set of candidate entity pairs, performing multi-hop path query in the knowledge graph to obtain a connection path;
[0046] Step S85, merging all obtained connection paths and performing deduplication based on triple features to obtain a path result;
[0047] Step S86, performing semantic polishing and natural language reconstruction on the path result to generate a structured answer that is easy to understand.
[0048] Further, it also includes a dynamic updating mechanism, which comprises:
[0049] When new or revised texts are detected in the legal regulations database, only the changed part is processed by the steps S2 to S5;
[0050] The incremental vector data and graph data obtained by processing are updated to the vector database and the graph database respectively to realize incremental updating of the knowledge graph and avoid full reconstruction;
[0051] Ensure that the incremental updating is completed within a preset time, and the response delay to user queries is lower than a preset threshold.
[0052] Further, the performance indicators of the dynamic updating mechanism include:
[0053] The average updating delay of a single new regulation is not more than 30 minutes.
[0054] The average recall time of a single complex query is no more than 3 seconds.
[0055] The beneficial effects of the present application are:
[0056] The present application proposes a dynamically updated legal regulation knowledge graph construction and recall method, through automatic segmentation and structured processing of regulation texts, context-enhanced semantic vector generation, knowledge graph construction by fusing triplets, and a dynamic updating mechanism, real-time organization and efficient recall of legal regulation knowledge are realized, with the following beneficial effects:
[0057] 1. Improve the accuracy of semantic expression: through the context-enhanced double-path vectorization method, the structured article object is combined with the segmented outline and abstract for composite modeling, which significantly improves the context integrity and accuracy of semantic representation.
[0058] 2. Enhance the coverage of question recall: by combining semantic expansion, Cartesian product combination and multi-hop graph query, cross-article and cross-regulation complex question recall is realized, which improves the deep knowledge question answering and reasoning ability.
[0059] 3. Ensure the real-time of knowledge graph: through the dynamic incremental updating mechanism, incremental updating can be quickly completed when the regulation text changes, ensuring that the knowledge graph is consistent with the latest regulations, enhancing the timeliness and practical value of the system.
[0060] 4. Strengthen the reasoning ability of relationship attributes: by introducing relationship attribute enhancement in the fusion of triplets, not only the logical relationship between articles can be captured, but also the hierarchical effectiveness and application priority of regulations can be better reflected, thereby improving the multi-dimensional reasoning effect. BRIEF DESCRIPTION OF DRAWINGS
[0061] Figure 1 is the step flow chart of the dynamically updated legal regulation knowledge graph construction and recall method in the present application; Figure 2 is the step sub-flow chart of step S2 in the present application; Figure 3 is the step sub-flow chart of step S3 in the present application; Figure 4 is the step sub-flow chart of step S4 in the present application; Figure 5 is the step sub-flow chart of step S5 in the present application; Figure 6 is the step sub-flow chart of step S7 in the present application; Figure 7 is the step sub-flow chart of step S8 in the present application. DETAILED DESCRIPTION
[0062] The application will be further described in detail below with reference to the accompanying drawings and embodiments. Identical parts are denoted by identical reference numerals. It should be noted that the words "front", "rear", "left", "right", "upper" and "lower" used in the following description refer to the directions in the drawings, and the words "bottom" and "top", "inner" and "outer" refer to the directions towards or away from the geometric center of a particular part.
[0063] Embodiment one, with reference to Figures 1 to 7 For the first embodiment of the application, the embodiment provides a dynamic updating legal regulations knowledge graph construction and recall method, which can construct an enhanced vector fused with full-text context semantics and a knowledge graph rich in attributes, and cooperatively perform semantic retrieval and graph reasoning, thereby accurately and efficiently realizing real-time recall and dynamic updating of complex regulations question answering, including:
[0064] Step S1, real-time collection of legal regulations database to obtain legal regulations text data;
[0065] Step S2, regular slicing processing is performed on the legal regulations text data, the structure of the legal regulations text data is identified and divided into a plurality of legal regulation units, the structure of each legal regulation unit is converted, and a sequence of structured legal regulation objects is generated;
[0066] Step S3, full-text structure recognition and semantic processing are performed on the legal regulations text data to generate segmented-level semantic data and full-text-level semantic data; wherein the segmented-level semantic data includes: a segmented preface outline path, a segmented abstract and a segmented triple corresponding to each legal regulation slice; the full-text-level semantic data includes: full-text metadata and full-text triples;
[0067] Step S4, composite vectorization is performed on the structured legal regulation objects and the segmented preface directory outline and the segmented abstract to generate context-enhanced semantic vectors;
[0068] Step S5, the full-text triples and the segmented triples are fused, and the relationship attribute information is enhanced to generate fused triples;
[0069] Step S6, the context-enhanced semantic vectors are stored in a vector database, and the sequence of structured legal regulation objects and the segmented-level semantic data are stored in an original data index to establish a corresponding relationship;
[0070] Step S7, the fused triples are imported into a graph database to construct a knowledge graph;
[0071] Step S8, based on the knowledge graph, responding to user queries, performing entity recognition, semantic expansion, multi-hop graph query and result fusion, and outputting structured answers.
[0072] The implementation details and working principles of each step in Embodiment one include:
[0073] Step S1, legal regulations data real-time collection, implementation details include:
[0074] Real-time docking with national legal regulations database, automatically capturing constitutional law, administrative regulations, supervision regulations, judicial interpretation, local regulations and other text data; while supporting the extension to industry standards, medical guidelines and other normative document data acquisition, with a frequency of 1 time per hour, ensuring data timeliness.
[0075] Step S1 working principle:
[0076] Through API interface call or compliance crawler technology, establish real-time data channel with official legal regulations database, parse and store original text according to preset data format (such as XML, TXT), form a unified legal regulations text data set, provide data source for subsequent processing.
[0077] Step S1 technical effect:
[0078] Realize the automation and real-time collection of legal regulations data, avoid the lag and error of manual collection, the data coverage range can be flexibly expanded, meet the knowledge graph construction needs of multiple types of normative documents, lay a data foundation for subsequent accurate processing.
[0079] Step S2: regular slicing and structured conversion, implementation details include:
[0080] Step S21: article segmentation: use regular expression (?=the [one two three four five six seven eight nine ten hundred thousand million \d]+ article) to segment the text data obtained in S1. This expression is based on positive look-ahead, matches "X article" (X can be Chinese numerals or Arabic numerals) as the segmentation point, splits the text into article unit sequence {T1, T2,..., Tn}, where Ti is a single article unit.
[0081] Step S22: structure verification: for each article unit Ti, check whether it contains "article number (such as 'twelfth article')" "article content", if there is a title (such as "(definition)") it will be checked at the same time; if the content is missing or the number is not continuous (such as "tenth article" followed by "twelfth article"), mark it as abnormal data, output verification log (including abnormal position, abnormal type), for manual repair.
[0082] Step S23: Structured conversion: convert the passed Ti into structured article objects with a unified field structure, including id (article number, standardized to Arabic numerals, such as "Article 12" converted to 12), title (article title, empty string if none), content (article text), forming a sequence of structured article objects. Example: the original text "Article 12 (Definition) This law refers to 'personal information' as follows:..." is converted to {id: 12, title: "Definition", content: "This law refers to 'personal information' as follows:..."}.
[0083] Step S2 working principle:
[0084] Based on the inherent structural characteristics of the legal regulations text "as a unit of 'Article X'", the regular expression is used to achieve accurate segmentation; then the structural element verification is used to ensure the integrity of the article unit, and finally the field standardization conversion is used to convert the unstructured text into machine-readable structured data, providing a unified data format for subsequent semantic processing and vectorization.
[0085] Step S2 technical effect:
[0086] 1. The accuracy of article segmentation is above 99%, avoiding missing or errors caused by text format differences;
[0087] 2. The structure verification mechanism reduces the interference of abnormal data on subsequent processes and reduces data noise;
[0088] 3. The structured conversion realizes the standardization of article data, facilitating subsequent cross-step data reuse and unified processing.
[0089] Step S3: Full-text structure recognition and semantic processing, implementation details include:
[0090] Step S31: Segment outline path generation: use Qwen2.5-32B pre-trained language model to recognize the structure of the full-text D obtained in S1, output the directory structure set Outline={(H1,p1),(H2,p2),...,(Hn,pn)}, where Hi is the directory title (such as "Chapter 1 General Provisions"), pi is the paragraph index of the title in the text. For each article segment di, trace back to the directory title set to which it belongs, and get the segment outline path: SegmentOutline(di)={Hj|pj≤i,Hj∈Outline}.
[0091] Step S32: Segment summary generation: Based on the Qwen2.5-32B model, use the fixed prompt word template prompt_summary (content is "Please summarize the core semantics of the following regulation fragments, control the number of words within 50: {di text}"), generate a segment summary Si for each regulation fragment di, that is:
[0092] Si = LLM(di, prompt_summary).
[0093] Step S33: Segment triple construction:
[0094] Key entity extraction: Based on the TF-IDF algorithm, extract the key entities (i.e. the set of key words) in the regulation fragment, the calculation formula is:
[0095] TF-IDF(t, di, D) = TF(t, di) x IDF(t, D);
[0096] TF(t, di) = f(t, di) / ∑kf(k, di);
[0097] IDF(t, D) = log[N / (1 + |{di∈D:t∈di}|)].
[0098] Where t represents a word, di represents the current regulation fragment, D represents the corpus, containing all regulation fragments, TF(t, di) represents the word frequency, i.e. the frequency of word t appearing in the current regulation fragment di, f(t, di) is the number of times word t appears in the current regulation fragment di, ∑kf(k, di) is the sum of the number of times all words appear in the current regulation fragment di, N represents the total number of all regulation fragments, |{di∈D:t∈di}| represents the number of fragments containing word t.
[0099] From this, the TF-IDF value of each noun can be calculated, sorted in descending order of TF-IDF value, and the top k high-weight nouns are selected to form the entity set: .
[0100] Basic triple generation: Take the document title T as the starting entity and the key entity ti as the target entity, use the prompt word template Rprompt (content is "Please describe the relationship between 'T' and '{ti}' in the regulation '{T}', output format is'relationship: {specific relationship description}'"), call the Qwen2.5-32B model to generate the relationship r, and form the basic triple (T, r, ti), forming the segment triple set TripleSet(di), where: .
[0101] Enhanced Triple Generation: If the relation description generated by a single Rprompt is incomplete (e.g., only containing "contains" but lacking "definition" or "scope of application"), multiple prompt words {R1, R2, R3} (R1: "describes the definition relationship between the two", R2: "describes the scope of application relationship between the two", R3: "describes the constraint relationship between the two") are used in conjunction with the model to generate an enhanced triple set EnhancedTripleSet(di).
[0102] in: .
[0103] Step S34: Full-text metadata extraction: Using the metadata prompt template MetaPrompt (containing sub-templates such as "Scope", "Nature", "Issuing Authority", "Implementation Date", etc.), call the Qwen2.5-32B model to extract structured metadata Metadata(D)=[{name:"Scope",value:LLM(D,MetaPrompt_Scope)},{name:"Nature",value:LLM(D,MetaPrompt_Nature)},...].
[0104] Step S35: Full-text triple extraction: Use the full-text prompt template FullTriplePrompt (content is "Please extract all global relations between entities in the regulation "{D heading}", output format is '(entity1, relation, entity2)', each triple occupies one line") to call the Qwen2.5-32B model to generate the full-text triple set FullTripleSet(D).
[0105] Working principle of step S3:
[0106] By leveraging the structural recognition and semantic understanding capabilities of pre-trained language models, semantic mining of regulatory texts is conducted from two dimensions: "segmentation" and "full text". In the segmentation dimension, hierarchical associations are established through outline paths, core semantics are extracted from summaries, and local entity relationships are captured through triples. In the full text dimension, overall attributes are described through metadata, and global entity relationships are captured through full text triples, forming a multi-granular and multi-level semantic data system.
[0107] Step S3 technical effect:
[0108] 1. The segmented outline path establishes a connection between legal provisions and the global structure, avoiding semantic isolation of segments;
[0109] 2. Segmented summarization condenses the core information of each segment, reducing data redundancy in subsequent vectorization;
[0110] 3. Based on TF-IDF and multi-cue words, triples are constructed to improve the accuracy of entity extraction and the richness of relationship description;
[0111] 4. The full-text metadata and triples provide global attribute and relationship support for the graph, enhancing the integrity of the graph.
[0112] Step S4: Composite vectorization processing, implementation details include:
[0113] Step S41: Content vector generation: Use the m3e-base vector model to vectorize the text content of the clause segment di, to obtain the content vector Vec_di = m3e(di), with a vector dimension of 768.
[0114] Step S42: Context vector generation: Concatenate the segment outline path SegmentOutline(di) and the segment summary Si (format: "outline path: {SegmentOutline(di)}; summary: {Si}") to obtain the context description text Context_di; then vectorize Context_di through the m3e-base model to obtain the context vector Vec_context_di = m3e(Context_di).
[0115] Step S43: Vector fusion: Concatenate Vec_di and Vec_context_di to obtain the context-enhanced semantic vector FinalVec_di = Combine(Vec_di, Vec_context_di), with a fused vector dimension of 1536.
[0116] Step S4 working principle:
[0117] Breakthrough the limitations of existing technologies that only isolate vectorize the content of the segment, fuse "segment local semantics (content vector)" with "global structure + core summary semantics (context vector)", realize context-enhanced semantic vector, and make the vector not only represent the meaning of the segment itself, but also associate global information.
[0118] Step S4 technical effect:
[0119] The retrieval and association capabilities of the context-enhanced semantic vector are significantly improved, and in cross-chapter and cross-regulation retrieval scenarios, the recall rate is improved by 15-20% compared to isolated vectorization (reference subsequent performance test data), laying a foundation for precise semantic retrieval.
[0120] Step S5: Triple fusion processing, implementation details include:
[0121] Step S51: Triple merging: merge the full-text triple set FullTripleSet(D) with all the segmented triple sets TripleSet(di) (including enhanced triples), remove duplicate triples (based on the uniqueness of (e1, r, e2) judgment), and get the merged triple set MergedTripleSet = FullTripleSet(D) U U TripleSet(di).
[0122] Step S52: Relationship attribute enhancement: add context attributes to the relationship r of each triple, with the attribute structure r.ext = {"source": "fragment" / "full" (identify the triple from the segment or full text), "title": DocumentTitle (regulation title), "category": DocumentCategory (regulation category, such as "legal" "administrative regulations"), "metadata": Metadata(D) (full-text metadata)}, and finally form the fusion triple (e1, r, ext).
[0123] Step S5 working principle:
[0124] By merging the "local (segment)" and "global (full text)" entity relationships, the relationship redundancy is eliminated; then by adding context attributes, the triple is supplemented with source, belonging regulation, overall attributes and other information, enhancing the traceability and semantic richness of the triple.
[0125] Step S5 technical effect
[0126] 1. Triple merging avoids relationship duplication and reduces graph data volume;
[0127] 2. Relationship attribute enhancement enables the graph to have "relationship traceability" capability, allowing users to quickly locate the relationship belonging regulation and background information, improving the practicality of the graph.
[0128] Step S6: Data storage and index establishment, implementation details include:
[0129] Vector storage: store the context-enhanced semantic vector FinalVec_di into the vector database (such as Milvus), establish vector index, index structure is {id: di.id, vector: FinalVec_di}, support similarity search based on Euclidean distance.
[0130] Raw data storage: Store structured statute object sequences, segmented context outline paths, segmented summaries, and segmented triples in the ElasticSearch raw data index. The index structure is: { id: di.id, content: di, outline: OutlinePath_di, summary: Summary_di, triples: TripleSet(di)}. Meanwhile, establish a mapping relationship between di.id and the id in the vector database to achieve fast association between vector retrieval and raw data.
[0131] Step S6 working principle:
[0132] Dual storage architecture of "vector database + raw data index": Vector database is used for efficient semantic similarity retrieval, and raw data index is used for storing complete structured data. The two are associated through a unique ID to realize the collaborative process of "fast retrieval-accurate positioning of raw data".
[0133] Step S6 technical effect:
[0134] The retrieval efficiency of the vector database is 5-10 times higher than that of the traditional database. The structured storage of the raw data index facilitates fast data query and update. The dual storage architecture takes into account both retrieval speed and data integrity.
[0135] Step S7: Knowledge graph construction, implementation details include:
[0136] S71: Structured file generation: Convert fused triples (e1, r, e2, ext) into CSV format file triples.csv;
[0137] Where the file header is head, relation, tail, source, title, category, metadata, and each row of data corresponds to a fused triple. Example: "Personal Information Protection Law", "definition", "personal information", "full", "Personal Information Protection Law of the People's Republic of China", "law", "{scope of application: ……}".
[0138] S72: Graph database import: Use the LOADCSV statement of the Neo4j graph database to batch import the CSV file. The code executed during import is as follows:
[0139] LOAD CSV WITH HEADERS FROM 'file: / / / triples.csv' AS row
[0140] MERGE (h:Entity {name: row.head})
[0141] MERGE (t:Entity {name: row.tail})
[0142] MERGE (h)-[r:Relation {type: row.relation}]->(t)
[0143] SET r += {
[0144] source: row.source,
[0145] title: row.title,
[0146] category: row.category,
[0147] metadata: row.metadata;}
[0148] After the import is completed, a legal regulation knowledge graph is formed with Entity as the node and Relation as the edge.
[0149] Step S7 working principle:
[0150] Convert the fused triplets into a structured format supported by the graph database, implement node deduplication and relation merging through the MERGE statement, avoid duplicate nodes or redundant relations in the graph, and finally build a knowledge graph with clear entity association and complete attributes.
[0151] Step S7 technical effect:
[0152] 1. Node deduplication and relation merging ensure the uniqueness of graph data and reduce data redundancy.
[0153] 2. The graph structure storage and query capability of the Neo4j graph database provides efficient support for subsequent multi-hop path queries, and the query speed is 3-5 times faster than that of the relational database.
[0154] Step S8: Intelligent recall and structured answer generation, implementation details:
[0155] Step S81: Entity recognition: Use the named entity recognition model (based on the BERT pre-training model fine-tuning) to perform entity recognition on the user query Q (such as "What is the definition of personal information in the Personal Information Protection Law?"), and extract the entity noun set Entities(Q)={e1,e2,...,ek} (example: "Personal Information Protection Law" "personal information").
[0156] Step S82: Semantic expansion: vectorize each entity ei by m3e-base model, get Vec_ei=m3e(ei); perform similarity search (Top-5) in Milvus vector database, get the semantic expansion entity set Similar(ei) of each ei (for example, the expansion entities of "personal information" may be "personal sensitive information", "personal information subject", etc.).
[0157] Step S83: Candidate entity pair generation: perform Cartesian product operation on all Similar(ei) to generate candidate entity pair set:
[0158] Pairs=CartesianProduct(Similar(e1),Similar(e2),...,Similar(ek)) (for example, "(Personal Information Protection Law, Personal Information)" "(Personal Information Protection Law, Personal Sensitive Information)" and so on).
[0159] Step S84: Multi-hop path query: for each candidate entity pair (ei, ej), perform 1-hop and 2-hop path query in Neo4j graph, use Cypher statement, use the following code:
[0160] cypher
[0161] MATCH p=(n1:Entity)-[*1..2]-(n2:Entity)
[0162] WHERE n1.name="{ei}" AND n2.name="{ej}"
[0163] RETURN DISTINCT p
[0164] Through the above query, the connection path between the entity pairs is obtained.
[0165] Step S85: Result fusion and deduplication: merge all the connection paths obtained by querying, remove the duplicate paths based on the uniqueness of the triple (head, relation, tail), and get the final path result.
[0166] Step S86: semantic polishing and reconstruction: convert the path result into a text description (e.g. "(Personal Information Protection Law)-[definition]->(personal information)" is converted to "Personal Information Protection Law defines personal information"), call Qwen2.5-32B model, use polishing cues (content is "Please arrange the following regulation relationship description into natural, fluent structured answer, point out the core information: {path text}"), generate structured answer (example: "Answer: According to the Personal Information Protection Law of the People's Republic of China, the core information is as follows: 1. Relationship: the law defines personal information; 2. Source: full-text dimension; 3. Applicable scope: applicable to personal information processing activities……").
[0167] Step S8 working principle:
[0168] Through the process of "entity recognition-semantic extension-candidate pair generation-multi-hop query-result fusion-polishing reconstruction", the user's natural language query is converted into an entity query that the graph can understand, and then the query coverage is expanded through semantic extension, complex entity relationships are captured through multi-hop query, and finally a user-friendly answer is generated through natural language polishing.
[0169] Step S8 technical effect:
[0170] 1. Combine semantic extension with Cartesian product to significantly improve query coverage and avoid "missed detection";
[0171] 2. Multi-hop path query captures complex relationships to meet the "cross-clause, cross-level" query requirements in the legal field;
[0172] 3. Result fusion deduplication and semantic polishing balance the accuracy and readability of the results, reducing user understanding costs;
[0173] 4. Overall adapt to the characteristics of legal regulation query scenarios to improve the "practicality" and "reliability" of the query.
[0174] Embodiment two, the second embodiment of the present application, which is different from the previous embodiment, combines the characteristics of legal and regulatory texts "high frequency revision, frequent addition", and provides a complete technical implementation scheme for dynamic updating, realizing efficient and real-time updating of knowledge graph, which includes:
[0175] Working principle of embodiment two:
[0176] 1. Change detection principle: Based on CDC technology, real-time monitoring of database transaction logs (such as MySQL binlog, PostgreSQL wal), when the legal text occurs INSERT / UPDATE, CDC component captures the change data and pushes it to the processing module; the fingerprint comparison mechanism generates a unique identifier through "article number + SHA-256 hash value", if the hash value changes, it is determined as a change, double mechanism ensures no missed detection, false detection.
[0177] 2. Incremental processing principle: Using the "uniqueness of article number" of legal text, accurately positioning the change range to a single article unit Ti, only executing S2-S5 processing flow for article unit Ti — the structured data, vector, triple of unchanged article unit are not processed repeatedly, greatly reducing the calculation amount (such as 100,000 regulations are updated by 100, the calculation amount is reduced by 99.9%).
[0178] 3. Incremental storage principle: Vector database uses "incremental indexing" technology, only establishes local index for new / modified vector, does not rebuild full index (full index construction requires several hours, incremental index only needs minutes);
[0179] Graph database realizes "update if exists, create if not exists" through MERGE statement, avoiding graph structure damage caused by deleting original nodes / relationships;
[0180] The original data index performs local update based on document ID, without reindexing all documents, reducing I / O resource consumption.
[0181] Technical effects of dynamic update mechanism in embodiment two:
[0182] 1. Significantly improve update efficiency and reduce resource consumption:
[0183] Compared with full update (4.5 hours for 100,000 regulations), incremental update of 100 revised regulations only takes 3.8 hours, reducing time cost by about 18%; at the same time, CPU occupancy rate decreases from 85% of full update to 40% of incremental update, memory occupancy rate decreases from 70% to 35%, avoiding waste of computing resources.
[0184] 2. Meet the timeliness requirements of regulations and avoid information lag:
[0185] The average update delay of a single new regulation is 27 minutes (≤30 minutes preset standard), ensuring that the knowledge graph is updated within 1 hour after the official release of the regulation, solving the problem of "full update lag leading to user query to old regulations" in existing technology (such as after the revision of a certain administrative regulation, existing technology needs 24 hours to update, this invention can complete it in 27 minutes).
[0186] 3. Ensure query real-time and optimize user experience:
[0187] The average recall latency for complex queries is 2.8 seconds (≤3 seconds preset standard). Even during the update process, vector retrieval and graph query can maintain low latency, allowing users to obtain the latest legal information without waiting for the update to complete, meeting the needs of interactive question-and-answer scenarios (such as lawyers querying revised legal provisions in real time).
[0188] 4. Ensure consistency of spectral data and avoid structural damage:
[0189] Incremental updates are performed by matching IDs with the MERGE statement, avoiding the loss of graph nodes / relationships caused by full deletion and reconstruction. At the same time, contextual attributes (such as "source:fragment_updated") mark the source of changes, making it easier to trace the data update history and improve the reliability of the graph.
[0190] Example 3, the third embodiment of the present invention, differs from the previous embodiment in that it verifies the effectiveness of the core technologies of "composite vectorization" and "multi-hop graph query" in the present invention, as well as the overall performance of the knowledge graph recall system. A comparative test experiment is designed to test the performance of vector retrieval and graph recall, focusing on the two key indicators: the recall rate of vector retrieval and the accuracy rate of graph recall. Specifically, the experiment includes:
[0191] Vector retrieval recall test:
[0192] Test implementation details:
[0193] 1. Test dataset: 200 real user legal consultation questions were selected (such as "How to protect your rights when personal information is leaked?" "What is the priority of the validity of administrative regulations and local regulations?"). Each question corresponds to 1-3 correct legal provisions (a total of 320 correct provisions), covering 6 types of regulations including the Constitution, laws, and administrative regulations.
[0194] 2. Testing process:
[0195] Using the m3e-base model in step S4 of this invention, the 200 questions are vectorized to obtain question vectors;
[0196] Based on the vector database (Milvus), similarity retrieval is performed on each question vector using four retrieval strategies: Top-1, Top-3, Top-5, and Top-10, to match the most relevant legal provision fragments.
[0197] Count the number of correct legal provision fragments in the search results under each strategy, calculate the recall rate (Recall rate = (Number of correct legal provision fragments in Top-K / Total number of correct legal provision fragments) × 100%), and record the average search time.
[0198] 3, Table 1 is a vector retrieval recall rate test data table, and the vector retrieval recall rate test results are shown in the following table 1:
[0199] Table 1
[0200]
[0201] According to the data in Table 1, it can be obtained that the "composite vectorization" technology of the application can significantly improve the recall rate of vector retrieval (Top-10 reaches 98%), and the retrieval time is low (≤2.2s).
[0202] The working principle of the vector retrieval recall rate test is as follows:
[0203] The "context enhanced semantic vector (FinalVec_di)" generated by the step S4 of the application simultaneously fuses the local semantics (Vec_di) of the statute fragment and the global context information (Vec_context_di), compared with the prior art "isolated vector based on fragment content", the semantic dimension represented is more complete, and the semantic association between the statute and the question can be more accurately reflected;
[0204] During the test, the similarity calculation between the question vector and the statute vector is based on the Euclidean distance (measuring the straight line distance between two points in the vector space, the smaller the distance, the more similar the semantics), the most relevant results are selected through the Top-K strategy, and then compared with the correct fragments manually marked to verify the effectiveness of the vector representation and the accuracy of the retrieval algorithm.
[0205] Technical effects of the vector retrieval recall rate test
[0206] 1. High recall rate verifies the effectiveness of the core technology: with the increase of the Top-K value, the recall rate increases from 86% to 98%, and the recall rate reaches 96% when Top-5, which shows that the "composite vectorization" technology can effectively capture the semantic association between the question and the statute, and can cover most of the correct results even when the K value is small, solving the problem of "incomplete semantic representation of isolated vector leading to low recall rate" in the prior art;
[0207] 2. Low time consumption meets the real-time demand: the average retrieval time under the four strategies is less than 2.5s, and the time consumption of the Top-1 strategy is only 1.2s, which is much lower than the preset response threshold of 3s, verifying the high-efficiency retrieval capability of the vector database (Milvus) and ensuring the real-time interactive experience of the user query;
[0208] 3. Strong result stability: the average number of recall statutes of 200 questions increases linearly with the Top-K value without abnormal fluctuations, which shows that the vector generation and retrieval process of the application has high stability and can adapt to different types of legal consultation questions.
[0209] Map recall accuracy test:
[0210] Test implementation details:
[0211] 1. Test data set: 100 complex legal consultation questions (such as "What administrative regulations does a worker need to meet to apply for compensation for work-related injuries?" "What is the difference between the standards for recognizing corruption in the supervision regulations and judicial interpretations?" ), each question corresponds to 1-5 correct map paths (280 correct paths) annotated by humans, and the path type covers 1-hop (direct relationship) and 2-hop (indirect relationship).
[0212] 2. Test process:
[0213] The "multi-hop map query" strategy of the present application is used to perform 1-hop query, 2-hop query and 1+2-hop combined query respectively;
[0214] The number of correct paths consistent with the manually annotated correct paths in the returned paths under each query strategy is counted, the question and answer accuracy is calculated (question and answer accuracy=(correct answer number / total question number) x 100%), and the average retrieval time and average returned path number are recorded;
[0215] 3. Table 2 is the test result table of map recall accuracy, and the test data of map recall accuracy is shown in Table 2:
[0216] Table 2
[0217]
[0218] According to Table 2, the "multi-hop map query" strategy can effectively improve the question and answer accuracy of complex problems (combined query reaches 92%), and the time consumption is controlled within 3.1s.
[0219] Working principle of map recall accuracy test:
[0220] The "fused triple" generated by step S5 of the present application contains complete context attributes (source, title, category, metadata), and the Neo4j knowledge graph constructed in step S7 realizes the structured storage of entities and relationships, supporting efficient multi-hop path query;
[0221] During the test, 1-hop query captures the direct relationship between entities (such as "work-related injury compensation-applicable-work-related injury insurance regulations"), 2-hop query captures indirect relationship (such as "work-related injury compensation-need to meet-administrative regulations-include-work-related injury insurance regulations"), and combined query integrates the two path types; by comparing the returned path with the correct path annotated by humans, the integrity of the map structure and the effectiveness of the multi-hop query strategy are verified.
[0222] Technical effect of map recall accuracy test:
[0223] 1. Multi-hop query improves the accuracy of complex problems: The accuracy of 2-hop query (88%) is improved by 10% compared with 1-hop query (78%), and the accuracy of combined 1+2-hop query is further increased to 92%, which shows that the "multi-hop graph query" strategy of the present application can effectively capture the indirect relationship between entities and solve the defect of the prior art that "only supports 1-hop query and cannot answer complex association problems";
[0224] 2. The number of paths and the accuracy are balanced and reasonable: The average number of returned paths of the combined query is 5.3, which avoids both "too few paths leading to information loss" and "too many paths leading to redundancy", ensuring that users can quickly obtain core information;
[0225] 3. Time consumption meets practical standards: Even for combined 1+2-hop query, the average time consumption is only 3.1s, close to the preset threshold of 3s, which verifies the efficiency of multi-hop query of Neo4j graph database and meets the real-time demand of interactive question and answer.
[0226] The above is only a preferred embodiment of the present application, and the protection scope of the present application is not limited to the above-mentioned embodiments. Any technical solution falling within the scope of the present application is within the protection scope of the present application. It should be noted that for ordinary skilled persons in the art, some improvements and refinements without departing from the principles of the present application are also considered to be within the protection scope of the present application.
Claims
1. A method for dynamically updating and retrieving legal and regulatory knowledge graphs, characterized in that, include: Step S1: Collect legal and regulatory data from the database in real time to obtain legal and regulatory text data; Step S2: Perform regular expression segmentation on the legal text data, identify the legal provisions structure and divide it into multiple legal provisions units, perform structured transformation on each legal provisions unit, and generate a sequence of structured legal provisions objects. Step S3: Perform full-text structure recognition and semantic processing on the legal text data to generate segment-level semantic data and full-text semantic data; wherein, the segment-level semantic data includes: the outline path of the preceding text of each legal provision segment, the segment summary and the segment triplet corresponding to each segment; the full-text semantic data includes: full-text metadata and full-text triplet. Step S4: Perform composite vectorization on the structured legal provision object, the segmented above text outline, and the segmented summary to generate a context-enhanced semantic vector; Step S5: Merge the full-text triples with each segment triple and enhance the relational attribute information to generate a fused triple; Step S6: Store the context-enhanced semantic vector into the vector database, and store the structured legal provision object sequence and the segmented semantic data into the original data index to establish a correspondence. Step S7: Import the fused triples into a graph database to construct a knowledge graph; Step S8: Based on the knowledge graph, respond to user queries, perform entity recognition, semantic expansion, multi-hop graph query and result fusion, and output a structured answer.
2. The method for constructing and recalling dynamically updated legal and regulatory knowledge graphs according to claim 1, characterized in that, The regularized fragmentation process in step S2 specifically includes: Step S21: Use regular expression pattern matching based on the structure of legal provisions to segment the legal text data to obtain a sequence of legal provision units containing multiple legal provision units; Step S22: Verify the structural integrity of each legal element and output a verification log; Step S23: Convert the verified legal provision unit into a legal provision object with a unified field structure. Multiple legal provision objects form the structured legal provision object sequence. The field structure includes at least the legal provision number, legal provision title, and legal provision text.
3. The method for constructing and recalling dynamically updated legal and regulatory knowledge graphs according to claim 1, characterized in that, The full-text structure recognition and semantic processing process in step S3 specifically includes: Step S31: Use a pre-trained language model to identify the full-text directory structure and generate the outline path of the preceding text of each legal provision segment. Step S32, the pre-trained language model generates the segmented summary representing the core semantics of each legal provision segment; Step S33: Extract key entities from each of the legal provisions based on statistical features, and construct segmented triples starting from the document topic; Step S34: Extract the full-text metadata describing the overall attributes of the regulation from the full-text dimension; Step S35: Extract the full-text triples of global relationships between entities from the full-text dimension.
4. The method for constructing and recalling dynamically updated legal and regulatory knowledge graphs according to claim 3, characterized in that, The construction of the segmented triplet includes: The word weights are calculated based on the TF-IDF algorithm, and the key entities are extracted from the legal provision segments. Using the document title as the starting entity and the extracted key entity as the target entity, relational predicates are generated by injecting relational cue words into the pre-trained language model, thereby forming the segmented triples; When the generation effect of a single relation prompt word is not good, multiple relation prompt words are used in conjunction with the pre-trained language model to obtain an enhanced set of triples with richer relation descriptions.
5. The method for constructing and recalling dynamically updated legal and regulatory knowledge graphs according to claim 1, characterized in that, The composite vectorization in step S4 includes: Step S41: Perform a first vectorization on the text content of the legal provision segment to obtain a content vector; Step S42: Concatenate the segmented outline path with the segmented summary to obtain the context description text, and perform a second vectorization on the concatenated context description text to obtain the context vector. Step S43: Concatenate the content vector and the context vector to generate the context-enhanced semantic vector that combines local semantics and global contextual information.
6. The method for constructing and recalling dynamically updated legal and regulatory knowledge graphs according to claim 1, characterized in that, The triplet fusion in step S5 includes: Step S51: Merge the full-text triples with each of the segment triples; Step S52: Add contextual attribute information to each triple relationship. The contextual attributes include source, title, category, and metadata.
7. The method for constructing and recalling dynamically updated legal and regulatory knowledge graphs according to claim 1, characterized in that, Step S7 specifically includes: Step S71: Convert the fused triples into structured data files that can be imported in batches from the graph database; Step S72: Load the structured data file and perform node deduplication based on node primary key and relationship merging based on relationship uniqueness during the import process to construct the knowledge graph.
8. The method for constructing and recalling dynamically updated legal and regulatory knowledge graphs according to claim 1, characterized in that, Step S8 specifically includes: Step S81: Identify the set of entity nouns from the user query; Step S82: Vectorize each entity in the entity noun set and perform similarity retrieval in the vector database to obtain a semantic extended entity set for each entity; Step S83: Perform a Cartesian product operation on all the obtained semantic extended entity sets to generate a candidate entity pair set; Step S84: For each entity pair in the candidate entity pair set, perform a multi-hop path query in the knowledge graph to obtain the connection path; Step S85: Merge all the connection paths obtained from the queries and remove duplicates based on the triplet features to obtain the path results; Step S86: Semantic refinement and natural language reconstruction are performed on the path results to generate an easily understandable structured answer.
9. The method for constructing and recalling dynamically updated legal and regulatory knowledge graphs according to claim 1, characterized in that, It also includes a dynamic update mechanism, which includes: When new or revised texts are detected in the legal and regulatory database, the processing flow from step S2 to step S5 is executed only on the changed parts; The processed incremental vector data and incremental graph data are updated to the vector database and the graph database respectively to achieve incremental updates of the knowledge graph and avoid full reconstruction. Ensure that the incremental update is completed within a preset time and that the response delay to user queries is below a preset threshold.
10. The method for constructing and recalling dynamically updated legal and regulatory knowledge graphs according to claim 9, characterized in that: The performance metrics of the dynamic update mechanism include: The average update delay for a single newly added regulation is no more than 30 minutes. The average recall time for a single complex query is no more than 3 seconds.
Citation Information
Cited By
An archival knowledge graph credible question and answer method and system
CN122332534A
An archival knowledge graph credible question and answer method and system
CN122332534B