Similar case recommendation method based on dynamic clustering multi-scale heterogeneous information fusion
By combining large language models and dynamic clustering techniques with self-attention mechanisms and a dual-mode database architecture, the problems of high manual annotation costs and low retrieval efficiency in similar case retrieval are solved, achieving efficient and accurate similar case recommendation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-18
- Publication Date
- 2026-04-03
AI Technical Summary
Existing case retrieval technologies rely on manual annotation, which is costly. They also struggle to balance semantic representation depth with retrieval efficiency and have weak heterogeneous data processing capabilities, resulting in low retrieval efficiency and poor consistency.
We employ a large language model to assist in the extraction of points of contention and dynamic clustering techniques, construct a semantic representation model that includes a self-attention mechanism and a dimensionality reduction layer, and combine a dual-mode architecture of vector database and relational database to ensure data consistency through transaction interaction logic.
It achieves automated conversion of massive amounts of unstructured documents, accurately captures deep logical relationships, ensures millisecond-level retrieval speed and the integrity of structured document data, and improves retrieval accuracy and reliability.
Smart Images

Figure CN121786128A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the intersection of artificial intelligence and legal technology, specifically to a similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion. Background Technology
[0002] Currently, the digitalization of the judicial system is accelerating, leading to a surge in the number of civil judgments. To ensure consistent application of the law and avoid inconsistent judgments in similar cases, it is necessary to efficiently retrieve similar precedents from this massive volume of documents. This process requires not only matching textual information but also a deep understanding of legal relationships and points of contention. Precise case retrieval has become a core requirement for improving trial efficiency and building smart courts.
[0003] Existing case retrieval technologies mostly employ relational databases combined with full-text search schemes. The system stores case numbers, causes of action, and main text in a structured manner, and establishes an inverted index based on keywords. During retrieval, Boolean matching is performed based on keywords or legal provisions. Some schemes introduce general pre-trained language models to convert text into vectors, calculate similarity, and categorize and display the data according to preset rules.
[0004] However, existing technologies have shortcomings. First, data construction relies on manual annotation, which is costly and subject to subjective bias, unable to automatically adapt to new types of disputes, and lacks adaptive clustering capabilities. Second, it is difficult to balance semantic representation depth and retrieval efficiency; general models struggle to capture complex logical relationships within documents, easily leading to false detections; high-dimensional vectors incur high retrieval costs in traditional databases, making real-time response difficult. Third, single-storage architectures have weak capabilities in handling heterogeneous data; vector retrieval and structured information extraction are disconnected, lacking strong consistency transaction mechanisms, easily leading to data silos or index failures under high concurrency, affecting system reliability.
[0005] Therefore, this invention provides a similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion to address the shortcomings of existing technologies. Summary of the Invention
[0006] To address the shortcomings of existing technologies, this invention provides a similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion. This method solves the problems of high manual annotation costs, inaccurate deep semantic matching of long texts, and low efficiency and poor consistency in the retrieval of massive heterogeneous data in traditional case retrieval.
[0007] To achieve the above objectives, the present invention provides the following technical solution: a similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion, comprising: Step S1: Obtain the original data of civil judgment documents, clean the original data and filter out the judgments, use a large language model to extract the core points of contention in the text of the judgment reasoning, construct a vector of points of contention based on the core points of contention and perform cluster analysis to generate a structured dataset with similar case labels. Step S2: Construct a semantic representation model that includes an encoding layer, a self-attention layer, and a dimensionality reduction layer. Train the semantic representation model using the structured dataset to convert the judgment reason text into a low-dimensional semantic vector. Step S3: Construct a dual-mode database system that includes a vector database and a relational database. Use the case number as a unique association key to store the low-dimensional semantic vector and document structured information respectively, and ensure the data consistency of the dual-mode database system through transaction interaction logic. Step S4: Respond to the user's query request, extract the core text of the judgment reasoning in the query document, call the trained semantic representation model to generate a query vector, retrieve similar case numbers in the vector database, obtain complete document information in the relational database based on the similar case numbers, and return a recommendation list sorted by similarity.
[0008] By adopting the above technical solutions, the use of large language model-assisted extraction of disputed points and dynamic clustering techniques enables the automated transformation of massive amounts of unstructured documents into structured, labeled data, solving the problems of high cost and strong subjectivity of manual annotation. The semantic representation model, incorporating self-attention mechanisms and dimensionality reduction, can capture deep logical connections within long texts and generate low-dimensional, efficient semantic vectors. Furthermore, the dual-mode architecture combining vector and relational databases, along with strict transaction interaction logic, ensures both millisecond-level retrieval speeds for high-dimensional vectors and the integrity and consistency of structured document data. Therefore, a similar case recommendation effect that combines retrieval accuracy, response speed, and data reliability is achieved.
[0009] Preferably, the process of extracting the core points of contention from the judgment reasoning text using a large language model in step S1 includes: loading the locally deployed large language model and constructing structured prompts containing role assignments, task definitions, and output format requirements; inputting the cleaned judgment reasoning text into the large language model, requiring the large language model to identify and output the legal dispute facts and key issues in the document; the structured prompts restrict the large language model to only return the text content of the points of contention, and remove irrelevant decorative statements.
[0010] By adopting the above technical solutions and leveraging the semantic understanding capabilities of large language models, it is possible to accurately extract the core points of contention from complex legal texts, eliminate irrelevant and interfering information, and provide high-quality basic data for subsequent vectorization and clustering.
[0011] Preferably, the process of constructing a dispute focus vector based on the core dispute focus and performing cluster analysis in step S1 includes: constructing a hierarchical case system containing parent and child case focuses; counting the hit frequency of the core dispute focus of each data point in each child case focus; combining the hit frequencies according to the order of the child case focuses to generate a dispute focus statistical vector; using Euclidean distance as a metric, iteratively calculating the dispute focus statistical vector using the k-means clustering algorithm; selecting clusters with a data volume within each cluster that meets a preset threshold as valid case clusters; and mapping the cluster number to the case label.
[0012] By adopting the above technical solution, unstructured disputed texts are transformed into statistical vectors based on the cause of action system, and clustering algorithms are used to automatically discover potential similar case groups, thereby automatically constructing a legally significant similar case dataset in the absence of manually preset labels.
[0013] Preferably, the construction process of the semantic representation model in step S2 includes: setting an input layer for segmenting the judgment reason text into sentences and filtering out invalid short sentences; setting an encoding layer for loading a pre-trained sentence transformation model and encoding each sentence after segmentation into an initial high-dimensional vector; setting a self-attention layer for calculating the semantic association strength between sentences and fusing them to generate a document-level vector; and setting a dimensionality reduction layer for compressing the document-level vector to the target dimension through a multi-layer fully connected neural network and outputting the low-dimensional semantic vector.
[0014] By adopting the above technical solutions, a multi-layered semantic processing architecture was constructed, realizing a complete mapping from sentence-level encoding to document-level logical fusion and feature compression, effectively improving the model's ability to represent long legal documents.
[0015] Preferably, the process of generating a document-level vector through self-attention layer fusion includes: mapping the initial high-dimensional vector into a query vector, a key vector, and a value vector respectively using a linear projection matrix; calculating the semantic influence between the query vector and the key vector using dot product operation to generate an attention score; processing the attention score using a normalized exponential function to obtain attention weights with values ranging from zero to one; and performing weighted summation and average pooling operations on the value vector according to the attention weights to generate the document-level vector that incorporates document logic.
[0016] By adopting the above technical solution and using the self-attention mechanism to calculate the interdependencies between sentences, the model can focus on sentences that play a key role in the characterization of the case, rather than simply averaging all sentences, thereby generating semantic vectors that contain the logical structure of the discourse.
[0017] Preferably, the dimensionality reduction layer process includes: constructing a first fully connected network layer to map the document-level vector to an intermediate dimension, and sequentially performing layer normalization, linear rectified activation function processing, and random deactivation processing; constructing a second fully connected network layer to map the vector processed by the first fully connected network layer to the final 256-dimensional dimension, and again performing layer normalization, linear rectified activation function processing, and random deactivation processing to obtain the low-dimensional semantic vector.
[0018] By adopting the above technical solutions, the vector dimension is reduced while retaining key semantic features, which reduces the subsequent storage space occupation and improves the speed of retrieval calculation. At the same time, layer normalization and random deactivation effectively prevent gradient anomalies and overfitting problems during model training.
[0019] Preferably, the process of training the semantic representation model in step S2 includes: calculating the classification loss using the cross-entropy loss function; updating the model parameters using the AdamW optimizer and setting a weight decay coefficient to prevent overfitting; dynamically adjusting the learning rate using a cosine annealing hot restart strategy; introducing a normalized cumulative gain index as an evaluation criterion during training, calculating the ratio of the actual cumulative gain of the recommendation list to the ideal cumulative gain of the recommendation list, and saving the model parameter with the highest normalized cumulative gain index.
[0020] By adopting the above technical solution, we not only focus on the classification accuracy of the model, but also directly optimize the ranking quality of the recommendation list through the normalized loss cumulative gain index, ensuring that highly relevant cases are ranked higher in the recommendation results and improving the user's search experience.
[0021] Preferably, the process of constructing the dual-mode database system in step S3 includes: configuring the vector database, using a dynamic partitioning strategy to partition by cause of action, constructing an inverted file product quantization index, and setting cosine similarity as the metric type, with stored fields including the case number, the case category label, the cause of action, and the low-dimensional semantic vector; configuring the relational database, using a storage engine that supports transactions and row-level locking, setting the case number as a unique index field, and storing fields including the case name, the court of trial, party information, legal basis, and full-text structured data of the document.
[0022] By adopting the above technical solutions, the advantages of vector databases in high-dimensional feature retrieval and relational databases in structured information management are leveraged. Dynamic partitioning and quantized indexing further improve the query throughput of large-scale data.
[0023] Preferably, the process of ensuring data consistency of the dual-mode database system through transaction interaction logic in step S3 includes: when performing a write operation, firstly initiating a transaction in the relational database, writing and committing the document structured information; after confirming the successful commit of the relational database, calling the insertion interface of the vector database to write the low-dimensional semantic vector; monitoring the write status of the vector database, and if the write fails, immediately performing a transaction rollback operation in the relational database; periodically performing a consistency verification task, comparing the case number lists in the relational database and the vector database, and deleting orphan vectors that exist in the vector database but not in the relational database.
[0024] By adopting the above technical solutions, a strict cross-database write transaction mechanism and periodic verification mechanism were established, which effectively prevented orphan data and dirty data problems caused by unilateral write failure or data asynchrony, and ensured the long-term stability of the dual-mode database system.
[0025] Preferably, the process of responding to the user's input query request and returning the recommendation list in step S4 includes: receiving a Hypertext Transfer Protocol request containing the full text of the document; using regular expressions to extract the core text of the judgment reasoning in the full text of the document; calling the semantic representation model to generate a 256-dimensional semantic vector and performing L2 normalization on the semantic vector; calling the search interface of the vector database to scan multiple case clusters with the highest similarity and returning the top ten similar case numbers; constructing a structured query statement, retrieving the corresponding complete document information from the relational database according to the similar case number, sorting the complete document information in descending order according to the similarity score calculated by the vector database, and encapsulating it into JSON format for return.
[0026] By adopting the above technical solution, end-to-end automated processing from user request to result return is achieved. L2 normalization ensures the accuracy of cosine similarity calculation, and finally provides users with accurate case recommendations sorted by similarity in a standardized data format.
[0027] This invention provides a similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion. It has the following beneficial effects: 1. This invention introduces a large language model to extract the core points of contention in judicial reasoning. Combined with vectorized statistics and dynamic clustering algorithms based on a hierarchical case classification system, it can automatically mine groups of similar cases with legal commonalities from massive amounts of unstructured documents. This mechanism effectively solves the problems of high cost and subjective bias caused by the reliance on manual annotation in traditional methods, and improves the purity and scalability of training data.
[0028] 2. This invention constructs a multi-level semantic representation model that incorporates a self-attention mechanism and a dimensionality reduction layer. This model overcomes the limitations of traditional models that only focus on local keywords, effectively capturing logical connections between sentences and discourse-level semantic features. Simultaneously, through low-dimensional mapping and L2 normalization, it reduces vector storage space while ensuring the accuracy of cosine similarity calculation, achieving precise capture of complex case semantics.
[0029] 3. This invention employs a dual-mode architecture that combines vector and relational databases, coupled with a strict transaction interaction and rollback mechanism. This leverages the millisecond-level response advantage of vector retrieval while ensuring zero loss and strong consistency of structured document information. Furthermore, the introduction of the NDCG metric guides model optimization, further validating and improving the ranking quality of recommendation results and enhancing the user's search experience. Attached Figure Description
[0030] Figure 1 This is a flowchart illustrating the architecture of the similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion of the present invention. Figure 2 The figure shows the experimental results of the search recommendation for neighbor relationship disputes according to the present invention; Figure 3 The figure shows the experimental results of the search recommendation for financial loan contract disputes according to the present invention; Figure 4 The experimental results of the labor dispute retrieval recommendation for this invention are shown in the figure; Figure 5 The figure shows the experimental results of the search for inheritance disputes in this invention; Figure 6 The figure shows the experimental results of the search recommendation for property damage compensation disputes according to the present invention; Figure 7 The figure shows the experimental results of searching and recommending disputes concerning the insurer's right of subrogation in this invention. Detailed Implementation
[0031] The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0032] This embodiment proposes a dual-mode architecture system that integrates a pre-trained language model, a Milvus vector database, and a MySQL relational database. This system aims to solve the problems of inaccurate semantic matching, low retrieval efficiency, and high manual costs in traditional case retrieval.
[0033] Please see the appendix Figure 1 From an overall architecture perspective, the system achieves efficient case recommendation through the collaborative work of four layers: data layer, model layer, database layer, and application layer. The data layer employs an automated process of crawling, cleaning, and clustering to extract core semantic elements from massive amounts of raw documents and generate case labeling. The model layer, based on a pre-trained SBERT model, constructs a three-level semantic representation model encompassing encoding, self-attention, and dimensionality reduction, transforming text into low-dimensional semantic vectors. The database layer adopts a dual-mode design, using Milvus to store semantic vectors and MySQL to store structured data, ensuring data consistency by relying on the case number as a unique association key. The application layer, based on Flask, develops an end-to-end interface to achieve fully automated processing from user input to result output.
[0034] In terms of data processing, the system first uses web crawling technology to selectively crawl civil judgment documents since 2021 from publicly available databases such as the Wolverhampton Wanderers website. The crawled fields include case number, case name, court of trial, and full text of the document. The system rigorously filters for the 13 core causes of action in the "Provisions on Causes of Action in Civil Cases (2022 Edition)," retaining only the judgments to ensure the completeness of the reasoning. After cleaning, the system selects 86,385 valid data entries from 776,740 original data entries. Subsequently, the system calls the locally deployed DeepSeek large-scale model to process the judgment reasoning text through structured prompt, extracting the core points of contention. In the automatic case clustering stage, the system constructs a cause of action system including parent and child causes of action, generating a vector of points of contention by counting the frequency of each data entry's points of contention within its child causes of action. For example, if a data entry's point of contention involves compensation for property loss, the corresponding child cause of action dimension count is incremented by one. Based on these vectors, the k-means clustering algorithm was implemented using the sklearn library. Euclidean distance was set as the metric, and clusters with more than or equal to 10 data points within each cluster were selected as valid cases. Finally, 341 case labels were obtained, and training data was generated using a stratified sampling strategy.
[0035] In terms of semantic modeling, the system adopts a five-level architecture consisting of an input layer, an encoding layer, a self-attention layer, a dimensionality reduction layer, and a classification head. The input layer segments the judgment reasoning text into sentences and filters out invalid sentences. The encoding layer loads the m3e-base pre-trained SentenceTransformer model, encoding each sentence into a 768-dimensional vector with elements ranging from -1 to 1. The self-attention layer is responsible for semantic fusion between sentences. First, the 768-dimensional sentence vector is projected into query, key, and value vectors through a linear projection matrix. The semantic influence between sentences is calculated using dot product attention. After obtaining the attention weights through Softmax normalization, the value vector is weighted and summed and average pooled to generate a 768-dimensional vector that incorporates the discourse logic. To balance semantic accuracy and memory usage, the dimensionality reduction layer employs a two-layer fully connected network (MLP) for vector compression: the first layer is configured as Linear(768, 512) combined with LayerNorm, ReLU, and Dropout; the second layer is configured as Linear(512, 256) with the same components, ultimately outputting a 256-dimensional semantic vector. The specific parameter configurations for model training are shown in the table below. Table 1. Training parameter settings Regarding the dual-mode database storage module, the system employs a deep collaborative mechanism between the Milvus vector database and the MySQL relational database. The Milvus database uses a dynamic partitioning strategy, configuring partitions based on case type, and utilizes the IVF_PQ index type. The parameter n_list is set to 111 to align with the number of clusters, m is set to 128 for high compression, and metric_type is set to COSINE to adapt to semantic matching. The specific field design of Milvus is shown in the table below: Table 2. Milvus Field Design Meanwhile, the MySQL database uses the InnoDB engine to support transactions and row-level locking, ensuring data security. Its table structure includes 15 core fields, with the `anhao` field set as a unique index for the dual-database join key. The specific field design is shown in the table below: Table 3. MySQL Field Design Note: - indicates no special restrictions.
[0036] To ensure data consistency between the two databases, the system employs an interactive logic of MySQL write-first, followed by Milvus write-later, with rollback on failure: First, structured data is written to MySQL and the transaction is committed. Only after successful write is the Milvus insert interface called to write vectors. If the Milvus write fails, the MySQL transaction is immediately rolled back. Furthermore, the system performs a consistency check weekly, comparing case numbers in both databases, deleting orphan vectors, and replacing missing vectors.
[0037] In terms of the application service module, an end-to-end case recommendation interface was developed based on the Flask framework. Upon service startup, the model is automatically preloaded into memory and the database connection pool is initialized. The interface accepts HTTP POST requests in JSON format and performs strict parameter validation: the required parameter `document` must be at least 200 characters long, and the number of requests per IP address is limited to no more than 10 per minute. In terms of processing, the system first extracts the core text of the judgment reasoning using regular expressions, calls the model to generate a 256-dimensional semantic vector, and performs L2 normalization. Then, it calls the Milvussearch interface to perform vector retrieval, scanning the 5 closest clusters (nprobe=5) and returning the Top-10 similar case numbers. Using the returned case number list, the system constructs an SQL statement to query complete document information in MySQL, finally sorting the results in descending order of similarity score and returning them in JSON format. An example of the returned JSON format is shown in the table below: Table 4. Examples of JSON format returns This embodiment details the complete execution flow of a similar case recommendation method based on a dual-mode architecture. The method mainly includes four core stages: data layer construction and preprocessing, model layer semantic encoding and training optimization, database layer collaborative deployment and writing, and application layer online retrieval and recommendation.
[0038] In the data construction and preprocessing stage, the first step is to acquire and clean the raw data. The system uses web crawling technology to selectively crawl civil judgment documents, retaining judgments for the 13 core causes of action in the "Provisions on Causes of Action in Civil Cases (2022 Edition)," and filtering out invalid data to select valid samples. Subsequently, the system performs vectorization and automated clustering of disputed issues: it calls a large model combined with a structured Prompt to extract disputed issues, and counts the frequency of each data point's disputed issue within its sub-cause of action, referring to the cause of action system. For example, if a data point involves property damage compensation, the frequency of the corresponding property damage insurance contract dispute sub-cause of action is incremented by 1, thus generating a statistical vector (e.g., [1,2,0,0,1]) with the number of sub-causes as the dimension. Based on this statistical vector, the system uses the sklearn library to implement the k-means clustering algorithm, setting Euclidean distance as the metric, and after iterative optimization, selects 341 valid case clusters with ≥10 data points within each cluster. Finally, a stratified sampling strategy is implemented to generate training data. Sampling control is applied to each type of case (50-200 cases). After text extraction and label mapping, a structured training dataset containing case number, cause of action, reasoning for judgment, and case number is generated.
[0039] In the semantic model construction and training phase, the system adopts a five-level architecture consisting of an input layer, an encoding layer, a self-attention layer, a dimensionality reduction layer, and a classification head. First, the input text of the judgment reasoning is segmented into sentences and invalid short sentences are filtered out. The encoding layer loads a pre-trained SentenceTransformer model, encoding each sentence into a 768-dimensional initial vector. Then, the self-attention layer proceeds, its core logic being to map the 768-dimensional sentence vector into query, key, and value vectors respectively through linear projection; dot product attention is used to calculate the semantic influence between sentences, obtaining an attention score; the attention score is normalized using the Softmax function to obtain attention weights ranging from [0,1]; finally, the value vectors are weighted and summed according to the attention weights, followed by average pooling, to generate a 768-dimensional document-level vector that incorporates the discourse logic. The dimensionality reduction layer compresses the vector to 256 dimensions through two fully connected layers. During model training, CrossEntropyLoss is used as the loss function, AdamW optimizer (weight_decay=5e-3) and CosineAnnealingWarmRestarts learning rate scheduling strategy are used, and an early stopping mechanism is introduced.
[0040] To verify the accuracy of the model's recommendation list ranking and optimize model parameters, this embodiment introduces normalized loss cumulative gain during the training and validation phase. This is used as the core evaluation indicator. The calculation process for this indicator is as follows: First, calculate the cumulative gain of the loss ( The formula is: ; in, This refers to the relevance score of each result; The discount factor is used; the later the sorting position, the smaller the discount factor. Next, the cumulative gain due to the loss under ideal conditions is calculated. This refers to the score that would be obtained if the retrieved results were perfectly sorted from high to low relevance. The formula is: ; in, Represents the ideal ordering of the first The relevance score for each position is calculated. Finally, the normalized score is obtained by calculating the ratio of the actual DG to the ideal IDCG, using the formula: ; The system maximizes the validation set. The optimal model weights are determined by the value (e.g., in this embodiment, neighbor relationship disputes). This achieves a score of 0.9954, thus ensuring the sorting quality of the final recommendation list.
[0041] During the database layer deployment and data writing phase, the system is configured to work collaboratively with the Milvus vector database and the MySQL relational database. The Milvus side dynamically partitions data according to case type and builds an IVF_PQ index, configuring the metric type as cosine similarity. Vectors are split into sub-vectors and quantized to achieve high compression ratios. During data writing, strict transaction interaction logic is followed: first, a MySQL transaction is initiated, structured data is written to MySQL, and committed; if the MySQL commit is successful, the Milvus interface is called to write vector data; if the Milvus write fails, the MySQL transaction is immediately rolled back. In addition, the system periodically performs consistency checks, comparing case numbers in the two databases, removing orphan vectors from Milvus, and supplementing records where vectors exist in MySQL but are missing in Milvus.
[0042] In the online retrieval and recommendation logic stage at the application layer, the system processes user requests based on API interfaces. Upon receiving a request containing the full text of a document and optional cause of action, it first extracts the core text of the judgment reasoning using regular expressions. If extraction is successful, a pre-loaded model, validated and optimized by NDCG, is invoked to convert the text into a 256-dimensional semantic vector, and L2 normalization is performed. Next, the Milvus search interface is called, passing in the query vector and retrieval parameters, to perform an approximate search in the vector database, obtaining a list of the top-10 case numbers with the highest similarity and their corresponding similarity scores. Based on the returned case number list, the system constructs an SQL query statement to retrieve the corresponding case name, full text of the document, and other complete structured information from the MySQL database. Finally, the obtained structured data is sorted in descending order according to the semantic similarity scores calculated by Milvus, packaged into JSON format, and returned to the user, completing the accurate recommendation of similar cases.
[0043] This embodiment constructs a specific experimental environment and dataset to comprehensively verify the proposed dual-mode architecture-based similar case recommendation method, focusing on evaluating its actual performance in terms of accuracy, ranking quality, and retrieval efficiency. The experimental data is selected from the structured dataset constructed in the preceding steps. The total of 14,423 data points are randomly split into a training set and a validation set in a 7:3 ratio, with the training set containing 10,096 data points and the validation set containing 4,327 data points. The data distribution broadly covers the eight core parent causes of action in the "Provisions on Causes of Action in Civil Cases" (including disputes over property rights protection, ownership, usufruct, marriage, family and inheritance, tort liability, contract disputes, insurance disputes, and labor disputes) and 111 subcategories. The sample size for each category is controlled between 50 and 200 cases, and each data point includes four key fields: case number, cause of action, reasoning for judgment, and category label, ensuring the diversity and representativeness of the experimental data.
[0044] To ensure the objectivity and reproducibility of the experimental results, a standardized hardware and software testing environment was established in this embodiment. The server, serving as the core computing node, runs the Ubuntu 20.04 LTS operating system, equipped with an Intel Xeon Gold 6248 CPU and an NVIDIA Tesla V100 GPU (40GB of VRAM), configured with the CUDA 12.0 parallel computing environment and the PyTorch 2.1.0 deep learning framework, and pre-installed with necessary dependency libraries such as milvus-sdk-python and flask. The client uses a Windows 11 system, configured with an Intel Core i5 processor and a GTX 1650 graphics card, used to simulate real user request sending and result receiving. Specific hardware and software configuration parameters are shown in Tables 5 and 6 below: Table 5. Server Hardware and Software Configuration Table 6. Client Hardware and Software Configuration Regarding the evaluation system, this experiment introduces normalized loss cumulative gain (… As a core quantitative indicator, this indicator can comprehensively measure the relevance of similar documents in the recommendation list and the rationality of their ranking position. The calculation is based on the ratio of the discounted cumulative gain (DCG) to the ideal discounted cumulative gain (IDCG). Using the aforementioned calculation formula, the following steps are first performed: Next, calculate The final calculation .
[0045] To visually demonstrate the calculation logic of this indicator, this example uses a recommendation list containing 5 documents. Assume the system returns the actual document ranking and their true relevance scores (0-3 points) as shown in Table 7 below: Table 7. Examples of Document Sorting Based on the data in the table above, the actual DCG calculation process for sorting is as follows: The ideal order should be document A(3), document C(3), document B(2), document E(1), document D(0), and its IDCG calculation result is: The final conclusion is... Value This result indicates that the actual sorting is very close to the ideal sorting.
[0046] The experiment's execution process comprises three steps: document retrieval, automated relevance scoring, and indicator calculation. First, an HTTP POST request containing the full text of the document is sent via API, and the system returns a Top-10 list of similar documents. Subsequently, to address the cost issue of large-scale data annotation, this experiment innovatively introduces a Large Language Model (LLM) as an evaluation expert. Through a structured Prompt project, the LLM is required to quantitatively score the relevance between the queried and resulting documents based on three dimensions: case type consistency, overlap of core case facts, and similarity of legal application scenarios, ranging from 1 to 5. The specific Prompt design is shown in Table 8 below. Table 8. Prompt Design Based on the above scoring results, this experiment selected six typical case types for calculation. Value, and in combination with appendix Figure 2 To be continued Figure 7 A detailed analysis will be conducted. See attached document. Figure 2The results of the experiment on neighborly disputes shown are as follows: The value is as high as 0.9954, close to the ideal value of 1. Multiple scores of 5 (highly relevant) appear consecutively at the beginning of the relevance score list, indicating that the system's semantic capture of this type of case is extremely accurate. (See appendix) Figure 3 The experimental results of financial loan contract disputes are shown below. The score was 0.9439. Although the top few positions still had many highly relevant documents, the subsequent positions showed a distribution of low to medium scores, indicating a slight decrease in the ideality of the ranking. (See appendix.) Figure 4 The experimental results on labor disputes shown are as follows: The score is 0.9528, indicating that highly relevant documents appear consecutively starting from the second position, suggesting good overall ranking quality. (See appendix.) Figure 5 The results of the inheritance dispute experiment shown are as follows: The value is 0.9379, with continuous high-resolution clusters in the middle section, but some low-to-medium resolution interference at the beginning and end. (See appendix.) Figure 6 The experimental results of the property damage compensation dispute shown are as follows: The score was 0.923, with the top two scores only at 4, indicating a slight decrease in the clustering of highly relevant documents at the top, but effective retrieval was still possible. (See appendix.) Figure 7 The results of the experiment on the insurer's subrogation right dispute are shown below. The score was 0.8791, which is a relatively weak performance in the test group. The highly relevant documents are mainly concentrated in the middle section of the list, and the preceding documents are mostly 4-point documents, indicating that there is still room for optimization of the system's sorting of this complex case.
[0047] In summary, all test cases The values remained stable within the range of 0.87 to 1.0, fully verifying the effectiveness of this invention in legal document similarity retrieval scenarios. By introducing the Milvus vector database and a self-attention mechanism encoding model, the system not only achieved near-perfect ranking results for cases such as neighbor disputes, but also maintained high recommendation quality even for complex cases involving insurer subrogation claims. Experimental results show that this technical solution effectively solves the problems of high false negative rates and simplistic ranking logic in traditional retrieval methods, improving the accuracy and practicality of similar case recommendations, and meeting the needs of efficient semantic processing of large-scale documents in judicial practice.
Claims
1. A similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion, characterized in that, Includes the following steps: S1. Obtain the original data of civil judgment documents, clean the original data and filter out the judgments, use a large language model to extract the core points of contention in the text of the judgment reasoning, construct a vector of points of contention based on the core points of contention and perform cluster analysis to generate a structured dataset with similar case labels. S2. Construct a semantic representation model that includes an encoding layer, a self-attention layer, and a dimensionality reduction layer. Train the semantic representation model using the structured dataset to convert the judgment reason text into a low-dimensional semantic vector. S3. Construct a dual-mode database system that includes a vector database and a relational database, using the case number as a unique association key to store the low-dimensional semantic vector and document structured information respectively, and ensure the data consistency of the dual-mode database system through transaction interaction logic. S4. Responding to the user's query request, extract the core text of the judgment reasoning in the query document, call the trained semantic representation model to generate a query vector, retrieve similar case numbers in the vector database, obtain complete document information in the relational database based on the similar case numbers, and return a recommendation list sorted by similarity.
2. The similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion according to claim 1, characterized in that, The process of extracting the core points of contention from the text of the judge's reasoning using a large language model in step S1 includes: Load the locally deployed large language model and construct structured prompt words that include role assignment, task definition, and output format requirements; The cleaned text of the judgment reasoning is input into the large language model, which is required to identify and output the legal disputed facts and key issues in the document. The structured prompts restrict the large language model to return only the text content related to the point of contention, removing irrelevant descriptive statements.
3. The similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion according to claim 1, characterized in that, The process of constructing a dispute focus vector based on the core dispute focus and performing cluster analysis in step S1 includes: Construct a hierarchical cause of action system that includes parent and child causes of action, and count the frequency of occurrence of the core disputed point of each data point in each child cause of action; The hit frequencies are combined according to the order of the sub-cause factors to generate a statistical vector of the points of contention. Euclidean distance is selected as the metric, and the k-means clustering algorithm is used to iteratively calculate the statistical vector of the dispute focus. Clusters with data volume within a cluster that meets a preset threshold are selected as valid case clusters, and the cluster number is mapped to the case label.
4. The similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion according to claim 1, characterized in that, The process of constructing the semantic representation model in step S2 includes: An input layer is set up to process the text of the judgment reasoning into sentences and filter out invalid short sentences. Set up an encoding layer, load a pre-trained sentence transformation model, and encode each sentence after sentence segmentation into an initial high-dimensional vector; A self-attention layer is set up to calculate the semantic association strength between sentences and fuse them to generate a document-level vector. A dimensionality reduction layer is set up, and the document-level vector is compressed to the target dimension through a multi-layer fully connected neural network to output the low-dimensional semantic vector.
5. The similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion according to claim 4, characterized in that, The process of generating document-level vectors by self-attention layer fusion includes: The initial high-dimensional vector is mapped into a query vector, a key vector, and a value vector using a linear projection matrix; The semantic influence between the query vector and the key vector is calculated using dot product operations to generate an attention score. The attention score is processed using a normalized exponential function to obtain attention weights with values ranging from zero to one. The value vector is weighted and summed according to the attention weights, and then averaged to generate the document-level vector that incorporates the document logic.
6. The similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion according to claim 4, characterized in that, The processing steps of the dimensionality reduction layer include: The first fully connected network layer is constructed, the chapter-level vectors are mapped to the intermediate dimension, and then processed by layer normalization, linear rectified activation function and random deactivation in sequence; A second fully connected network layer is constructed to map the vector processed by the first fully connected network layer to the final 256 dimensions. The vector is then subjected to layer normalization, linear rectified activation function processing, and random deactivation processing to obtain the low-dimensional semantic vector.
7. The similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion according to claim 1, characterized in that, The process of training the semantic representation model in step S2 includes: The classification loss is calculated using the cross-entropy loss function; The AdamW optimizer is used to update the model parameters, and a weight decay coefficient is set to prevent overfitting. A cosine annealing hot restart strategy is used to dynamically adjust the learning rate; During training, a normalized cumulative loss gain index is introduced as an evaluation criterion. The ratio of the actual cumulative loss gain to the ideal cumulative loss gain of the recommended list is calculated, and the model parameter with the highest normalized cumulative loss gain index is saved.
8. The similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion according to claim 1, characterized in that, The process of constructing the dual-mode database system in step S3 includes: Configure the vector database, use a dynamic partitioning strategy to partition according to the cause of action, construct an inverted file product quantization index, and set cosine similarity as the metric type. The stored fields include the case number, the case label, the cause of action, and the low-dimensional semantic vector. Configure the relational database using a storage engine that supports transactions and row-level locking, set the case number as a unique index field, and store fields including case name, court of trial, party information, legal basis, and full-text structured data of the document.
9. The similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion according to claim 1, characterized in that, The process of ensuring data consistency in the dual-mode database system through transaction interaction logic in step S3 includes: When performing a write operation, the transaction of the relational database is started first, and the document structured information is written and committed. After confirming that the relational database submission was successful, the insertion interface of the vector database is called to write the low-dimensional semantic vector; Monitor the write status of the vector database; if the write fails, immediately execute the transaction rollback operation of the relational database. A consistency check task is performed periodically to compare the case number lists in the relational database and the vector database, and to delete orphan vectors that exist in the vector database but not in the relational database.
10. The similar case recommendation method based on dynamic clustering and multi-scale heterogeneous information fusion according to claim 1, characterized in that, The process of responding to the user's query request and returning the recommendation list in step S4 includes: Receive a Hypertext Transfer Protocol request containing the full text of a document, and use regular expressions to extract the core text of the judgment reasoning from the full text of the document; The semantic representation model is invoked to generate a 256-dimensional semantic vector, and L2 normalization is performed on the semantic vector. Call the search interface of the vector database to scan multiple case clusters with the highest similarity and return the top ten similar case numbers in terms of similarity. Construct a structured query statement, retrieve the corresponding complete document information from the relational database based on the similar case number, sort the complete document information in descending order according to the similarity score calculated by the vector database, and encapsulate it into JSON format and return it.