Memory method for supporting hybrid retrieval and dynamic update in large law model application
By combining sparse and dense retrieval techniques with secondary retrieval of legal provisions, the shortcomings of memory management in the large legal model are solved, achieving adaptive optimization and efficient memory retrieval, thereby improving the efficiency and accuracy of legal services.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- EAST CHINA NORMAL UNIV
- Filing Date
- 2026-02-09
- Publication Date
- 2026-05-12
Smart Images

Figure CN122019724A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of natural language processing and large model applications, and in particular to a memory method that supports hybrid retrieval and dynamic updates in the application of a legal large model. Background Technology
[0002] In recent years, with the rapid development of deep learning technology, Large Language Models (LLMs) have made groundbreaking progress in the field of Natural Language Processing (NLP). These models, through large-scale pre-training and fine-tuning, have demonstrated powerful language understanding and generation capabilities and have been successfully applied in various vertical fields such as education, healthcare, and finance. In the legal field, LLMs have shown great potential in applications such as intelligent legal consultation, legal text retrieval, case analysis, and contract review, providing new technical pathways for the intelligentization and automation of legal services. However, due to the highly specialized, logically rigorous, and normative nature of legal texts, existing LLMs face significant technical challenges in legal application scenarios. Solving legal problems requires not only accurate language expression but also adherence to the compliance of the legal reasoning process and the legality of the conclusions, which places stringent demands on the reasoning ability and knowledge accuracy of LLMs. Especially in memory management, how to construct an efficient, accurate, and dynamically updated memory system has become a key technical challenge in the application of large legal models.
[0003] Existing large-scale legal models have the following problems and shortcomings in memory management: 1. Passive memory update mechanism: The existing system only triggers updates when new memories are added, lacking the ability to dynamically update the memory structure based on user input. It cannot adaptively optimize according to actual needs and usage patterns, causing the memory structure to deviate from the application scenario, affecting the system's practicality and accuracy.
[0004] 2. Insufficient memory association: Existing systems lack effective management of memory associations. During retrieval, only directly related memories are returned. The search results cannot be expanded by utilizing associations, and semantic and logical connections are not fully utilized, making it difficult to form a complete knowledge network.
[0005] 3. Limited search methods: Most existing systems use a single search method. Sparse search, such as BM25, performs well in terms of exact matching but lacks semantic understanding. Dense search can capture semantic similarity but has low sensitivity to exact keyword matching, making it difficult to simultaneously meet the dual requirements of accuracy and semantic understanding in the legal field.
[0006] 4. Limited memory retrieval strategy: Most existing systems perform a single retrieval, failing to fully utilize memory metadata. In legal applications, secondary retrieval based on legal provisions is not performed, making it difficult to achieve targeted optimization and fully utilize the structured information in memory. Summary of the Invention
[0007] This invention aims to overcome the shortcomings of existing technologies by proposing a memory-based retrieval method for large-scale legal model applications that supports hybrid retrieval and dynamic updates. This method introduces a hybrid retrieval mechanism combining sparse and dense retrieval, and effectively improves the recall and precision of memory retrieval through secondary retrieval of legal provisions and a memory evolution mechanism. This allows the memory system to adaptively optimize based on actual usage scenarios. The method can efficiently support application scenarios such as legal consultation, case analysis, and legal education, improving the efficiency and accuracy of legal services.
[0008] To achieve the above objectives, the present invention provides the following technical solution: A memory method supporting hybrid retrieval and dynamic updates in a large-scale legal model application employs a hybrid retrieval technique combining sparse and dense retrieval. The method includes the following steps: S1: Question about obtaining user input; S2: Perform a mixed search based on user queries, using a combination of secondary search of legal provisions fields (existing or need to be added?) and regular memory database search to obtain relevant memory information; The hybrid retrieval specifically includes the following steps: S201: Based on the user's input question, extract keywords and relevant legal information, and use a large language model or keyword extraction tool to extract key legal terms, concepts, and related legal provision numbers, legal names, etc. from the user's question; S202: Perform a secondary search based on the legal provisions field. In the legal provisions memory bank, use a semantic encoding model to encode the user's question to the system and the content of the legal provisions field extracted in S201 into word vectors based on the legal provisions field of each remembered legal provision. Perform dense retrieval by calculating cosine similarity to obtain the retrieval results based on the legal provisions field. S203: Use word vectors and keywords in a conventional memory to perform dense and sparse searches in parallel, and obtain dense search results and sparse search results respectively; S204: Dynamically adjust the weight parameters of sparse and dense retrieval, normalize the two retrieval results and merge them to obtain conventional mixed retrieval results; S205: Dynamically adjust the weights of the search results based on the legal provisions field and the regular mixed search results, and perform deduplication, merging and sorting of the two parts of the search results, retaining the top-K results, where K is the preset number of search results; S206: Based on the top-K memories, further retrieve adjacent memories for each memory based on the relationships between memories; S207: Deduplicatize and merge the Top-K memories and their adjacent memories as the final result.
[0009] S3: Based on the current user input and mixed search results, perform memory evolution, determine whether the user input matches the search results, update existing memories or create new memories based on the matching results, and update the link relationships between memories; The memory evolution specifically includes the following steps: S301: Obtain the current user input content and search results; S302: Use a large language model to determine whether the input content matches the search results. Construct matching judgment prompts, call the large language model to analyze the semantic association and logical relevance between the user input and the memorized content, and determine whether they match based on the judgment results of the large language model. S303: If a match is found, update the corresponding memory in the search results, including updating the memory content, keywords, context description, and category tags; S304: If there is no match, use a large language model to extract keywords, generate contextual descriptions, determine classification labels, create new memory objects, and add them to the memory bank based on the input content; S305: Update the link relationship between the memory and the neighboring memory. For the updated memory, recalculate the correlation degree and update the link. For the newly added memory, find the existing memory that is semantically similar or logically related and establish the link relationship.
[0010] S4: Filter and select the mixed search results, including deduplication, relevance filtering, quality assessment and ranking optimization, to obtain the final memory search results; The filtering and screening include: Duplicate memory entries are removed based on the unique identifier of each memory; the relevance score of each memory to the user query is calculated, and memories with relevance scores below a preset threshold are filtered out, taking into account semantic similarity and keyword matching; the quality and completeness of memories are evaluated using a large language model, and high-quality memories are prioritized for retention based on the evaluation results of the large language model; a weighted ranking algorithm is used to calculate a comprehensive score based on the relevance score and memory quality score evaluated by the large language model, taking into account factors such as the timeliness and retrieval frequency of memories, and the memories are ranked from high to low.
[0011] Furthermore, each memory entry in the memory bank contains a legal provision field attribute, used to store the legal provision number, the name of the law to which it belongs, and the original text of the legal provision content. The legal provision field is defined as follows: when a memory is created or updated, if the memory content involves legal provisions, the legal provision information is extracted from the memory content and stored in the legal provision field. The legal provision memory bank is a subset formed by filtering a unified memory bank, with the filtering condition being that the legal provision field is not empty, and is used to support specialized retrieval based on the legal provision field.
[0012] Furthermore, the dense retrieval and sparse retrieval described in step S203 include: Dense retrieval: The query text and memory content are encoded into vectors using a semantic encoding model, and a dense retrieval score is obtained by calculating the cosine similarity. Sparse retrieval: The BM25 algorithm is used to segment the query text and the memory content, and the BM25 score is calculated based on term frequency and inverse document frequency.
[0013] Furthermore, the dynamic adjustment of weight parameters for sparse and dense retrieval in step S204 includes: The weight parameters α for sparse and dense retrieval are dynamically adjusted based on query features, where 0≤α≤1, α is the weight for sparse retrieval, and (1-α) is the weight for dense retrieval. After normalizing the BM25 score and semantic similarity score respectively, the combined score is calculated as follows: Mixed score = α × Normalized BM25 score + (1-α) × Normalized semantic similarity score.
[0014] Furthermore, the method for adjusting the weight parameter α includes: Calculate the proportion of exact match keywords in the query. If the proportion of exact match keywords exceeds a preset threshold, increase the sparse retrieval weight and improve the α value. Use a large language model or semantic analysis tool to evaluate the semantic complexity of the query. If the semantic complexity score exceeds a preset threshold, increase the dense retrieval weight and decrease the α value.
[0015] Furthermore, the dynamic adjustment of the weights of the search results based on the legal provision fields and the conventional mixed search results described in step S205 includes: The query type is analyzed using a large language model and rule engine. If the query explicitly involves specific legal citations, the weight of the legal citation field search results is increased, with a weight set to 0.6-0.8. If the query involves case analysis or general legal consultation, the weight of the general mixed search results is increased, with a weight set to 0.6-0.8.
[0016] Furthermore, the adjacent memory retrieval in step S206 includes: For the Top-K memories retrieved in step S205, the corresponding adjacent memories are retrieved from the memory bank according to the associated memory identifier stored in the links attribute of the memory. If there are many adjacent memories, each memory is limited to a maximum of M adjacent memories, where M is a preset parameter, and adjacent memories with higher correlation are selected first.
[0017] Furthermore, step S302, determining whether the input content matches the search results, includes: The system combines user input and retrieved memory content into a prompt text. A large language model is used to analyze the semantic relevance, logical correlation, and information consistency between the user input and the memory content. The system determines whether the two match based on the results of the large language model.
[0018] Furthermore, step S303, updating the memory corresponding to the search results, includes: The system uses a large language model to analyze new user input, integrates it with existing memory content, and updates the memory content. Based on the updated memory content, keywords are extracted again and the keyword list is updated. The system uses a large language model to regenerate context descriptions and category labels. Metadata information such as the last access time and number of searches in the memory is updated. If the user input contains new legal provisions, the legal provisions field in the memory is updated.
[0019] Furthermore, step S304, which involves creating a new memory object and adding it to the memory bank, includes: The system analyzes user input using a large language model, extracts a keyword list, generates contextual descriptions, and determines category tags. If the input involves legal provisions, it extracts and stores the legal provision information in the legal provision field. It then creates new memory objects, including a unique identifier, content, keywords, context, tags, timestamp, legal provision field, and retrieval count attribute. The unique identifier is generated using a UUID, the initial retrieval count is set to 0, and the creation time is set to the current time. Finally, it adds the newly created memory objects to the memory bank and updates the retrieval index.
[0020] Furthermore, the link update in step S305, which updates the link relationship between the memory and the neighbor memory, includes: For the updated memory: use a semantic encoding model to calculate the semantic similarity between the updated memory and other memories in the memory bank, combine keyword overlap analysis to identify candidate associated memories, use a large language model to analyze semantic association and logical relevance, and decide whether to establish or update the link relationship based on the evaluation results of the large language model, and update the links attribute of the memory. For the newly added memory: use a semantic encoding model to calculate the semantic similarity between the new memory and the existing memory, select memories with similarity exceeding a preset threshold as candidate neighbors, use a large language model to analyze semantic association and logical relevance, decide whether to establish a link relationship based on the evaluation results of the large language model, add the neighbor memory identifiers determined by the large language model to the links attribute of the new memory, and update the links attribute of the neighbor memories to establish a bidirectional link relationship. Optimize link relationships: Use a large language model to analyze the association between memories. Based on the judgment results of the large language model, remove links with low association and ensure that links are established for memories with high association.
[0021] Compared with existing technologies, this invention systematically integrates hybrid retrieval technology into the application of large legal models, and performs targeted optimization around the unique needs of legal text retrieval, thereby improving the application effect and reliability of large language models in the legal field. By combining sparse and dense retrieval techniques, a hybrid retrieval system is implemented to achieve secondary retrieval of legal provisions and a memory evolution mechanism, thereby improving the recall and precision of memory retrieval in the application of large-scale legal models. The hybrid retrieval technology dynamically adjusts the weights of sparse retrieval (BM25) and dense retrieval (semantic vector retrieval), combining the advantages of both methods to simultaneously meet the dual requirements of accurate keyword matching and semantic understanding in the legal field. The secondary retrieval technology of legal provisions fully utilizes the metadata information of the memory to perform targeted retrieval based on legal provisions, improving the retrieval accuracy of queries related to legal provisions. The memory association network technology establishes and maintains the relationships between memories, expanding the retrieval results by utilizing adjacent memories during retrieval, forming a complete knowledge network. The dynamic memory evolution mechanism automatically determines whether to update existing memories or create new memories based on user query results and actual usage, establishing and maintaining the relationships between memories. This enables the memory system to perform structured storage and management of memory content, adaptively optimizing according to actual application scenarios, and promptly reflecting changes in knowledge and user needs. This effectively supports application scenarios such as legal consultation, case analysis, and legal education, significantly improving the efficiency and accuracy of legal services. Attached Figure Description
[0022] Figure 1 This is a flowchart of the present invention; Figure 2 This is a flowchart of the memory retrieval process of the present invention; Figure 3 This is a flowchart illustrating the memory evolution process of the present invention. Detailed Implementation
[0023] The present invention will be further described below with reference to the accompanying drawings and embodiments. Taking a legal large-scale model application scenario as an example, including legal consultation, case analysis, and legal provision query, it is assumed that the system already has initial memory data sources such as legal question-and-answer data and case data, and that the vector database and large language model have been deployed. Of course, this embodiment can also be implemented without these assumptions. The former can be implemented even without the legal question-and-answer data and case data, and the latter vector database and large model can be used in the cloud via interface calls. It is not necessary to deploy it yourself.
[0024] A memory method supporting hybrid retrieval and dynamic updates in a large-scale legal model application includes the following steps: S1: Obtain the user's original query request, including natural language text such as legal questions, case consultations, and legal provisions queries; S2: Perform a mixed search based on the user's query, including: S201: Extract keywords and relevant legal provisions from the questions; S202: Perform secondary retrieval based on legal provisions fields: In the legal provisions memory bank, the content of the query and each remembered legal provisions field is converted into vectors through a semantic coding model, and the cosine similarity is calculated to perform dense retrieval and obtain retrieval results based on legal provisions fields; The legal provision field is an attribute field of the memory, used to store legal provision information associated with the memory, including the legal provision number, the name of the law to which it belongs, and the original text of the legal provision. When the memory is created or updated, if legal provisions are involved, the corresponding legal provision information is extracted and written into this field.
[0025] Each memory entry includes the following attributes: id (unique identifier, in UUID format), content (memory content text), keywords (keyword list), context (context description), tags (category tag list), links (linked memory identifier list), timestamp (creation timestamp), lastAccessed (last access time), retrievalCount (number of retrievals), and legalArticles (an array of legal article fields, including the legal article number, the name of the relevant law, and the original text of the legal article).
[0026] S203: Perform dense search and sparse search in parallel in the conventional memory to obtain dense search results and sparse search results respectively; Dense retrieval specifically involves: combining user questions with extracted keywords to form query text, which is then encoded into a query vector using a semantic coding model; encoding the content, keywords, and contextual information of each memory entry in the memory bank into a memory vector; and calculating the cosine similarity between the query vector and each memory vector to obtain a dense retrieval score.
[0027] Sparse retrieval specifically involves: using the BM25 algorithm to retrieve user questions and keywords; performing word segmentation and stop word processing on the query text and memory content; and calculating the BM25 score based on term frequency and inverse document frequency.
[0028] S204: Set dynamic weights for sparse and dense searches, and normalize the scores of the two types of searches before weighted merging to obtain conventional mixed search results; The dynamic weight merging includes: dynamically adjusting the weight parameter α based on query features (0≤α≤1, where α is the sparse retrieval weight and 1-α is the dense retrieval weight); normalizing the BM25 score and semantic similarity score respectively; and calculating the mixed retrieval score using the formula: Mixed Score = α × Normalized BM25 Score + (1-α) × Normalized Semantic Similarity Score. The adjustment method for the weight parameter α includes: calculating the proportion of precisely matching keywords in the query and increasing the sparse retrieval weight when it exceeds a preset threshold; evaluating the semantic complexity of the query and increasing the dense retrieval weight when it exceeds a threshold; and adaptively adjusting based on historical search results and user feedback.
[0029] S205: Dynamically adjust the weight and deduplicate the results of legal provisions field retrieval and regular mixed retrieval, and retain the top-K results after sorting, where K is a preset number; Dynamic weight adjustment includes: using large language models or rule engines to identify query types and determine the relative weights of legal provision field search results and regular mixed search results; when the query involves specific legal provision citations, increase the weight of legal provision field search results, with a suggested range of 0.6-0.8; when the query is a case analysis or general consultation, increase the weight of regular mixed search results, with a suggested range of 0.6-0.8.
[0030] S206: Based on the aforementioned association relationships among the Top-K memories, further retrieve the adjacent memories of each memory; The adjacent memory retrieval includes: retrieving adjacent memories from the memory bank based on the associated memory identifiers stored in the links attribute of the Top-K memories; adjacent memories refer to other memories that are semantically or logically related to the current memory; when there are a large number of adjacent memories, the retrieval of each memory can be limited to no more than M adjacent memories (M is a preset parameter), and those with higher relevance are given priority.
[0031] S207: Deduplicatize and merge the Top-K memories and their adjacent memories to form the final return result; S3: Perform memory evolution based on the current user input and the mixed retrieval results. The memory evolution includes: S301: Obtain user input and search results; S302: Call the large language model to determine the matching of input content and search results: The matching judgment includes: constructing matching judgment prompts, submitting user input and retrieved memory content to the large language model; the large language model analyzes semantic relevance, logical relevance and information consistency, and determines whether a match is made accordingly; Specifically, a large language model is invoked by constructing a structured matching suggestion word, which contains the following parts: Role Definition: Clearly define the role of the large language model in this task, such as "you are a professional content analysis assistant" or "you are a legal analysis expert".
[0032] Task instructions: Clearly instruct the model to make matching judgments, such as "Please determine whether the following two parts match or are highly related in semantics and logic".
[0033] Input content format: Provide two text fragments to be analyzed in a fixed template format (such as "Content 1: {Current user input content}" and "Content 2: {Retrieved memory content}").
[0034] Output requirements: The output of the model should be a clear judgment result (such as "match" or "not match") and a brief reason.
[0035] Here is a complete example of a prompt word: "You are a legal analysis expert. Please help me determine whether the following two parts match semantically and logically. Content 1: {The specific question or statement entered by the user}, Content 2: {The specific content retrieved from the database}. Please only output 'match' or 'do not match', along with a brief reason." Based on the constructed prompt words, the large language model is invoked to perform in-depth analysis on 'content 1' (user input) and 'content 2' (memorized content), evaluate the semantic relevance and logical correlation between the two, and finally determine whether the two match based on the judgment results output by the large language model.
[0036] S303: If a match is found, update the corresponding memory in the search results, including the memory content, keywords, context description, and category tags; The updated memory in the search results includes: updated memory content, keywords, context description, category tags and metadata (last access time, number of searches, etc.).
[0037] S304: If there is no match, the large language model extracts keywords, generates contextual descriptions and determines classification labels based on the input content, creates new memory objects and writes them into the memory bank; The creation of new memories includes: content analysis and metadata extraction by a large language model (generating keywords, context descriptions, and category tags; if legal provisions are involved, they are extracted and stored in the legal provision field); creation of memory objects (containing attributes such as unique identifier, content, keywords, context, tags, timestamp, legal provision field, and number of searches; the unique identifier is generated using UUID); writing to the memory bank and updating the search index.
[0038] S305: Update the link relationship between the memory and the neighbor memory: recalculate the relevance of the updated memory and revise the link; retrieve existing memories that are semantically similar or logically related to the newly added memory and establish a link relationship; The process of updating the links between memories and neighboring memories includes: for updated memories, recalculating their association with other memories in the database (combining semantic similarity and keyword overlap), and updating the links attribute; for new memories, retrieving existing memories that are semantically similar or logically related, and establishing bidirectional links; continuously optimizing the links, removing low-value links, and ensuring the establishment and retention of high-value links.
[0039] S4: Filter and screen the mixed search results, including deduplication, relevance filtering, quality assessment and ranking optimization, to obtain the final memory search results.
[0040] The filtering and screening include: deduplication, relevance filtering (i.e., calculating relevance scores by combining semantic similarity and keyword matching), quality assessment (i.e., examining content completeness, keyword accuracy, and contextual clarity), and ranking optimization (i.e., weighted ranking based on factors such as relevance, quality score, timeliness, and retrieval frequency).
[0041] The legal provision field in step S2-2 is an attribute field of the memory, used to store legal provision information associated with the memory, including the legal provision number, the name of the law to which it belongs, and the original text of the legal provision. When the memory is created or updated, if legal provisions are involved, the corresponding legal provision information is extracted and written into this field.
[0042] Each memory entry includes the following attributes: id (unique identifier, in UUID format), content (memory content text), keywords (keyword list), context (context description), tags (category tag list), links (linked memory identifier list), timestamp (creation timestamp), lastAccessed (last access time), retrievalCount (number of retrievals), and legalArticles (an array of legal article fields, including the legal article number, the name of the relevant law, and the original text of the legal article). Example
[0043] This embodiment uses the query "How is property divided after divorce?" as an example to illustrate the implementation process of the present invention with reference to the accompanying drawings. Assuming the user has previously inquired about "prenuptial agreements," the memory system can access this historical information and provide a more accurate and personalized answer.
[0044] See Figure 1 The memory retrieval and update process in the application of the legal big data model includes the following steps: S1001: Receive user query request. In this embodiment, the query request is "What happens to property division after divorce?". Through the association retrieval mechanism of the memory system, the user's previous consultation history can be retrieved to provide a more personalized answer.
[0045] S1002: Perform a mixed search on the user's query; S1003: Perform memory evolution based on the current user input and the mixed search results; S1004: Filter and screen the mixed search results, including deduplication, relevance filtering, quality assessment and ranking optimization, to obtain a highly relevant and high-quality candidate memory set; S1005: Output the final result, returning the filtered and selected memory retrieval results to the question-and-answer system or subsequent processing module. In this embodiment, the retrieval results returned by the memory system include memories related to the user's previous inquiries about "prenuptial agreements" and memories of legal provisions related to property division.
[0046] See Figure 2 The hybrid retrieval process in step S1002 includes: S2001: Problem of obtaining user input.
[0047] S2002: Extract keywords and related legal information. Semantic analysis of user questions is performed using a large language model to extract key legal terms, concepts, and potentially related legal provisions. In this embodiment, keywords such as "divorce," "property division," and "marital property" can be extracted, along with relevant legal provisions from the Marriage and Family section of the Civil Code and the Marriage Law.
[0048] S2003: Perform secondary retrieval based on the legal provisions field. Based on the extracted keywords and legal provisions information, a secondary retrieval is performed in the memory bank based on the `legalArticles` field of each memory entry. A semantic encoding model is used to encode the query text and the content of the legal provisions field into vector representations, and the cosine similarity is calculated and sorted. The Top-K1 memories with the highest similarity are returned (K1 is a preset parameter, usually 3-5). In this embodiment, the system retrieves memory entries containing information on property division clauses in the Marriage and Family section of the Civil Code, and retrieves memories related to the user's previous inquiry about "prenuptial agreements" through semantic similarity matching of the legal provisions field.
[0049] S2004: Dense and sparse searches are performed in parallel within a conventional memory. Dense search obtains query and memory vectors through semantic encoding and calculates cosine similarity to obtain a dense search score. Sparse search uses the BM25 algorithm to segment and stop words in the query and memory content before calculating the BM25 score.
[0050] S2005: Dynamically adjust the weights of sparse and dense retrieval and merge the results. Based on query features, set weights α (α is the weight for sparse retrieval, 1-α is the weight for dense retrieval), normalize the BM25 score and semantic similarity score, calculate the mixed score to complete weighted merging and sorting, and retain the top-K2 results (K2 is a preset parameter, usually 5-8). In this embodiment, set weight α=0.5 to balance the contributions of sparse and dense retrieval.
[0051] S2006: The weights of the legal provision field search results and the general mixed search results are adjusted and merged for ranking. The query type is identified using a large language model or rule engine: when the query involves specific legal provision citations, the weight of the legal provision field search results is increased; when the query is a case analysis or general consultation, the weight of the general mixed search results is increased. In this embodiment, the query is a general consultation type, so the weight of the general mixed search results is set to 0.7, and the weight of the legal provision field search results is set to 0.3. After deduplication of the two sets of results, a weighted score is calculated and the results are sorted, retaining the top-K results.
[0052] S2007: Retrieve adjacent memories. Based on the links relationship of the Top-K memories, further retrieve adjacent memories; when the number of adjacent memories is large, each memory can be limited to retrieving a maximum of M adjacent memories (M is a preset parameter), and those with higher relevance are selected first. In this embodiment, the system retrieves memories related to "prenuptial agreements" that the user has previously consulted through the memory association network, forming a more complete knowledge network.
[0053] S2008: Merge Output. The Top-K memories are deduplicated and merged with their adjacent memories to form the final search result set, which is then returned. In this embodiment, a memory set containing complete information such as legal provisions on property division, historical consultation records, and relevant cases is formed.
[0054] See Figure 3 The memory evolution process in step S1003 includes: S3001: Obtain user input and search results.
[0055] S3002: Determine if a match is found. A matching suggestion is constructed, and the user input and retrieved memory content are submitted to a large language model. Semantic relevance, logical correlation, and information consistency are analyzed to determine if a match is found. In this embodiment, the system retrieves a memory containing the general process of property division, with a semantic similarity of 0.75, keyword overlap of 0.70, and a comprehensive matching score of 0.73, exceeding the preset threshold of 0.7, and is therefore determined to be a match.
[0056] S3003: If a match is found, update the memory. Update the content, keywords, context description, category tags, etc. of the corresponding memory, and synchronously update the metadata, last access time, number of searches, etc. In this embodiment, the system updates the number of searches for memories related to property division, and strengthens the connection between these two memories based on the relevance of this query and historical consultations and prenuptial agreements.
[0057] S3004: If no match is found, a new memory is created. The large language model performs semantic parsing on the input, generating keywords, context descriptions, and category labels; if legal provisions are involved, they are extracted and written into the legal provision field; a new memory object is created and written to the memory bank, while the retrieval index is updated. If the query involves a new applicable legal scenario, the system will create a new memory object and link it with existing marital property-related memories.
[0058] S3005: Update link relationships. Recalculate the relevance of updated memories and revise links; retrieve existing memories with similar semantics or logical relevance for newly added memories and establish bidirectional link relationships to continuously optimize the memory network structure. In this embodiment, the system identifies that the memories involved in this query are related to memories in multiple areas such as prenuptial agreements, postnuptial property agreements, and property division procedures, and establishes or strengthens the association links between these memories, especially strengthening the association relationship between "property division" and "prenuptial agreement".
[0059] The above embodiments are only used to illustrate the technical solutions of the present invention and do not constitute a limitation on the present invention. All equivalent modifications or substitutions made based on the concept of the present invention should fall within the protection scope of the claims of the present invention.
Claims
1. A memory method supporting hybrid retrieval and dynamic updating in a large-scale legal model application, characterized in that, Includes the following steps: S1: Question about obtaining user input; S2: Perform a mixed search based on user queries, using a combination of secondary search of legal provisions and search of the conventional memory bank to obtain relevant memory information; S3: Based on the current user input and mixed search results, perform memory evolution, determine whether the user input matches the search results, update existing memories or create new memories based on the matching results, and update the link relationships between memories; S4: Filter and select the mixed search results, including deduplication, relevance filtering, quality assessment and ranking optimization, to obtain the final memory search results.
2. The memory method supporting hybrid retrieval and dynamic updating in a legal large-scale model application according to claim 1, characterized in that, The hybrid retrieval in step S2 specifically includes the following steps: S201: Based on the user's input question, extract keywords and relevant legal information, and use a large language model or keyword extraction tool to extract key legal terms, concepts, and related legal provision numbers and legal names; S202: Perform a secondary search based on the legal provisions field. In the legal provisions memory bank, use a semantic encoding model to encode the user's question to the system and the content of the legal provisions field into word vectors based on each remembered legal provisions field. Perform dense retrieval by calculating cosine similarity to obtain the retrieval results based on the legal provisions field. S203: Use word vectors and keywords in a conventional memory to perform dense and sparse searches in parallel, and obtain dense search results and sparse search results respectively; S204: Dynamically adjust the weight parameters of sparse and dense retrieval, normalize the two retrieval results and merge them to obtain conventional mixed retrieval results; S205: Dynamically adjust the weights of the search results based on the legal provisions field and the regular mixed search results, and perform deduplication, merging and sorting of the two parts of the search results, retaining the top-K results, where K is the preset number of search results; S206: Based on the top-K memories, further retrieve adjacent memories for each memory based on the relationships between memories; S207: Deduplicatize and merge the Top-K memories and their adjacent memories as the final result.
3. The memory method supporting hybrid retrieval and dynamic updating in a legal large-scale model application according to claim 1, characterized in that, The memory evolution in step S3 specifically includes the following steps: S301: Obtain the current user input content and search results; S302: Use a large language model to determine whether the input content matches the search results. Construct matching judgment prompts, call the large language model to analyze the semantic association and logical relevance between the user input and the memorized content, and determine whether they match based on the judgment results of the large language model. S303: If a match is found, update the corresponding memory in the search results, including updating the memory content, keywords, context description, and category tags; S304: If there is no match, use a large language model to extract keywords, generate contextual descriptions, determine classification labels, create new memory objects, and add them to the memory bank based on the input content; S305: Update the link relationship between the memory and the neighboring memory. For the updated memory, recalculate the correlation degree and update the link. For the newly added memory, find the existing memory that is semantically similar or logically related and establish the link relationship.
4. The memory method supporting hybrid retrieval and dynamic updating in a legal large-scale model application according to claim 1 or 2, characterized in that, Each memory entry in the conventional memory bank includes a legal provision field attribute, used to store the legal provision number, the name of the law to which it belongs, and the original text of the legal provision content. The legal provision field is defined as follows: when a memory is created or updated, if the memory content involves legal provisions, the legal provision information is extracted from the memory content and stored in the legal provision field. The legal provision memory bank is a subset formed by filtering a unified memory bank, with the filtering condition being that the legal provision field is not empty, and is used to support specialized retrieval based on the legal provision field.
5. The memory method supporting hybrid retrieval and dynamic updating in a legal large-scale model application according to claim 2, characterized in that, The dense search and sparse search in step S203 include: Dense retrieval: The query text and memory content are encoded into vectors using a semantic encoding model, and a dense retrieval score is obtained by calculating the cosine similarity. Sparse retrieval: The BM25 algorithm is used to segment the query text and the memory content, and the BM25 score is calculated based on term frequency and inverse document frequency.
6. The memory method supporting hybrid retrieval and dynamic updating in a legal large-scale model application according to claim 2, characterized in that, The dynamic adjustment of weight parameters for sparse and dense retrieval in step S204 includes: The weight parameters α for sparse and dense retrieval are dynamically adjusted based on query features, where 0≤α≤1, α is the weight for sparse retrieval, and (1-α) is the weight for dense retrieval. After normalizing the BM25 score and semantic similarity score respectively, the combined score is calculated as follows: Mixed score = α × Normalized BM25 score + (1-α) × Normalized semantic similarity score.
7. The memory method supporting hybrid retrieval and dynamic updating in a legal large-scale model application according to claim 6, characterized in that, The method for adjusting the weight parameter α includes: Calculate the proportion of exact match keywords in the query. If the proportion of exact match keywords exceeds a preset threshold, increase the sparse retrieval weight and improve the α value. Use a large language model or semantic analysis tool to evaluate the semantic complexity of the query. If the semantic complexity score exceeds a preset threshold, increase the dense retrieval weight and decrease the α value.
8. The memory method supporting hybrid retrieval and dynamic updating in the application of the legal big data model according to claim 2, characterized in that, Step S205, which involves dynamically adjusting the weights of the search results based on the legal provision fields and the conventional mixed search results, includes: The query type is analyzed using a large language model and rule engine. If the query explicitly involves specific legal citations, the weight of the legal citation field search results is increased, with a weight set to 0.6-0.
8. If the query involves case analysis or general legal consultation, the weight of the general mixed search results is increased, with a weight set to 0.6-0.
8.
9. The memory method supporting hybrid retrieval and dynamic updating in the application of the legal big data model according to claim 2, characterized in that, The adjacent memory retrieval in step S206 includes: For the Top-K memories retrieved in step S205, the corresponding adjacent memories are retrieved from the memory bank according to the associated memory identifier stored in the links attribute of the memory. If there are many adjacent memories, each memory is limited to a maximum of M adjacent memories, where M is a preset parameter, and adjacent memories with higher correlation are selected first.
10. The memory method supporting hybrid retrieval and dynamic updating in the application of the legal big data model according to claim 3, characterized in that, Step S302, determining whether the input content matches the search results, includes: The system combines user input and retrieved memory content into a prompt text. A large language model is used to analyze the semantic relevance, logical correlation, and information consistency between the user input and the memory content. The system determines whether the two match based on the results of the large language model.
11. The memory method supporting hybrid retrieval and dynamic updating in a legal large-scale model application according to claim 3, characterized in that, Step S303, updating the memory corresponding to the search results, includes: The system uses a large language model to analyze new user input, integrates it with existing memory content, and updates the memory content. Based on the updated memory content, keywords are extracted again and the keyword list is updated. The system uses a large language model to regenerate context descriptions and category labels. Metadata information such as the last access time and number of searches in the memory is updated. If the user input contains new legal provisions, the legal provisions field in the memory is updated.
12. The memory method supporting hybrid retrieval and dynamic updating in a legal large-scale model application according to claim 3, characterized in that, Step S304, which involves creating a new memory object and adding it to the memory bank, includes: The system analyzes user input using a large language model, extracts a keyword list, generates contextual descriptions, and determines category tags. If the input involves legal provisions, it extracts and stores the legal provision information in the legal provision field. It then creates new memory objects, including a unique identifier, content, keywords, context, tags, timestamp, legal provision field, and retrieval count attribute. The unique identifier is generated using a UUID, the initial retrieval count is set to 0, and the creation time is set to the current time. Finally, it adds the newly created memory objects to the memory bank and updates the retrieval index.
13. The memory method supporting hybrid retrieval and dynamic updating in the application of the legal big data model according to claim 3, characterized in that, The link relationship between the updated memory and the neighbor memory in step S305 includes: For the updated memory: use a semantic encoding model to calculate the semantic similarity between the updated memory and other memories in the memory bank, combine keyword overlap analysis to identify candidate associated memories, use a large language model to analyze semantic association and logical relevance, and decide whether to establish or update the link relationship based on the evaluation results of the large language model, and update the links attribute of the memory. For the newly added memory: use a semantic encoding model to calculate the semantic similarity between the new memory and the existing memory, select memories with similarity exceeding a preset threshold as candidate neighbors, use a large language model to analyze semantic association and logical relevance, decide whether to establish a link relationship based on the evaluation results of the large language model, add the neighbor memory identifiers determined by the large language model to the links attribute of the new memory, and update the links attribute of the neighbor memories to establish a bidirectional link relationship. Optimize link relationships: Use a large language model to analyze the association between memories. Based on the judgment results of the large language model, remove links with low association and ensure that links are established for memories with high association.
14. The memory method supporting hybrid retrieval and dynamic updating in the application of the legal big data model according to claim 1, characterized in that, The filtering and selection in step S4 include: Duplicate memory entries are removed based on the unique identifier of each memory; the relevance score of each memory to the user query is calculated, and memories with relevance scores below a preset threshold are filtered out, taking into account semantic similarity and keyword matching; the quality and completeness of memories are evaluated using a large language model, and high-quality memories are prioritized for retention based on the evaluation results of the large language model; a weighted ranking algorithm is used to calculate a comprehensive score based on the relevance score and memory quality score evaluated by the large language model, taking into account factors such as the timeliness and retrieval frequency of memories, and the memories are ranked from high to low.