Method, device and system for improving RAG retrieval capability and storage medium

By clustering and similarity matching of multi-source knowledge bases, and combining topic and subtopic clustering, the problem of low retrieval efficiency and homogeneous generated content in traditional RAG systems in multi-source knowledge base scenarios is solved, achieving efficient and accurate knowledge domain positioning and generation.

CN121092684APending Publication Date: 2025-12-09BEIJING JIZHI DIGITAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510976070.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-15
Publication Date
2025-12-09

AI Technical Summary

Technical Problem

Traditional RAG retrieval systems cannot intelligently identify the knowledge domain corresponding to the user's query in multi-source, multi-domain knowledge base scenarios, resulting in low retrieval efficiency, poor accuracy, homogenized generated content, and a lack of hierarchical semantic modeling capabilities.

Method used

By clustering multi-source knowledge bases using a predefined clustering model, cluster centers for each knowledge base are obtained. User queries are then matched with these centers based on similarity, and knowledge bases with the highest similarity are selected as the search scope. By combining topic and subtopic clustering, richer and more context-sensitive answers are generated.

Benefits of technology

It achieves efficient knowledge domain positioning, narrows the search scope, improves search accuracy and the diversity and completeness of generated content, and enhances the efficiency of RAG retrieval and the accuracy of the generated model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121092684A_ABST
    Figure CN121092684A_ABST
Patent Text Reader

Abstract

The invention discloses a method, device and system for improving RAG retrieval capability and a storage medium. The method for improving the RAG retrieval capability in the embodiment of the invention comprises the following steps: clustering each knowledge base in a multi-source knowledge base through a predetermined clustering model to obtain a clustering center corresponding to each knowledge base; performing similarity matching on the user query and the clustering center corresponding to each knowledge base, so as to select a plurality of similar knowledge bases which have higher similarity with the user query from the multi-source knowledge base; and taking the plurality of similar knowledge bases as a retrieval range corresponding to user query. In this way, by conducting clustering sensing routing in the multi-source knowledge base, efficient knowledge field positioning can be achieved, and the retrieval range can be narrowed.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of artificial intelligence, in particular to a method for improving retrieval capability of RAG, a device for improving retrieval capability of RAG, a system for improving retrieval capability of RAG and a computer readable storage medium. BACKGROUND

[0002] A traditional retrieval augmented generation (RAG) system is composed of an external knowledge retriever and a language generation model. Related technologies usually directly recall documents from a knowledge base based on vector similarity, and input them into a language generation model for processing. In the complex scenario of multi-source and multi-domain knowledge base, the traditional RAG retrieval strategy has significant bottlenecks, for example, the system cannot intelligently identify the knowledge domain corresponding to the user query. SUMMARY

[0003] The embodiments of the present application provide a method for improving retrieval capability of RAG, a device for improving retrieval capability of RAG, a system for improving retrieval capability of RAG and a computer readable storage medium to solve at least one of the above technical problems.

[0004] The method for improving retrieval capability of RAG according to the embodiments of the present application comprises:

[0005] Clustering each knowledge base in the multi-source knowledge base by a predetermined clustering model to obtain a clustering center corresponding to each knowledge base;

[0006] Matching the user query with the clustering center corresponding to each knowledge base for similarity to select a plurality of similar knowledge bases with high similarity to the user query from the multi-source knowledge base;

[0007] Taking the plurality of similar knowledge bases as the retrieval range corresponding to the user query.

[0008] In some embodiments, the clustering each knowledge base in the multi-source knowledge base by a predetermined clustering model to obtain a clustering center corresponding to each knowledge base comprises:

[0009] Blocking processing the documents of each knowledge base, and converting each document block into a corresponding document vector;

[0010] Clustering the document vectors of each knowledge base by the predetermined clustering model, and determining the clustering number based on the silhouette coefficient to determine the clustering center corresponding to each knowledge base;

[0011] The similarity matching of the user query with the cluster center corresponding to each of the knowledge bases is to select a plurality of similar knowledge bases with high similarity to the user query from the multi-source knowledge bases, comprising:

[0012] The user query is converted into a query vector;

[0013] The similarity between the query vector and the cluster center corresponding to each of the knowledge bases is calculated to select a plurality of similar knowledge bases with high similarity to the query vector from the multi-source knowledge bases.

[0014] In some embodiments, the method for improving the retrieval ability of RAG further comprises:

[0015] A plurality of document blocks with high similarity to the user query are retrieved from the plurality of similar knowledge bases as candidate document blocks;

[0016] Each of the candidate document blocks is subjected to vector normalization processing to obtain a corresponding candidate document vector;

[0017] The plurality of candidate document vectors are subjected to topic clustering and sub-topic clustering to determine a cluster fusion semantic vector;

[0018] The similarity between the query vector and the plurality of cluster fusion semantic vectors is calculated to select a plurality of current cluster fusion semantic vectors with high similarity to the query vector from the plurality of cluster fusion semantic vectors, and determine a plurality of current document blocks corresponding to the plurality of current cluster fusion semantic vectors.

[0019] In some embodiments, the topic clustering and sub-topic clustering of the plurality of candidate document vectors to determine a cluster fusion semantic vector comprises:

[0020] The plurality of candidate document vectors are subjected to topic clustering by the predetermined clustering model, and the number of clusters is determined based on the silhouette coefficient to determine a plurality of topic clusters;

[0021] A plurality of candidate document vectors with high similarity to the query vector are selected in each of the topic clusters as representative document vectors of the topic clusters;

[0022] The representative document vectors are subjected to sub-topic clustering by a hierarchical clustering model to obtain a plurality of sub-topic clusters;

[0023] The representative document vectors in each of the sub-topic clusters are averaged to determine a semantic center vector of each of the sub-topic clusters;

[0024] The cluster fusion semantic vector is determined according to the semantic center vector of each of the topic clusters and the semantic center vectors of the corresponding plurality of sub-topic clusters.

[0025] In some implementations, determining the clustering fusion semantic vector based on the semantic center vector of each topic cluster and the semantic center vectors of the corresponding plurality of sub-topic clusters includes:

[0026] The semantic center vector of each topic cluster is weighted and averaged with the semantic center vectors of the corresponding multiple sub-topic clusters to obtain the clustering fusion semantic vector.

[0027] In some embodiments, the method for improving RAG retrieval capabilities further includes:

[0028] The user query and multiple current document blocks are input into a predetermined language model;

[0029] The predetermined language model generates a corresponding answer based on the user query and multiple current document blocks.

[0030] In some implementations, the predetermined clustering model is a K-means clustering model or an HDBSCAN clustering model.

[0031] The apparatus for improving RAG retrieval capabilities according to embodiments of this application includes:

[0032] The clustering module is used to cluster each knowledge base in the multi-source knowledge base using a predetermined clustering model to obtain the cluster center corresponding to each knowledge base.

[0033] The matching module is used to perform similarity matching between the user query and the cluster center corresponding to each of the knowledge bases, so as to select multiple similar knowledge bases with the highest similarity to the user query from the multi-source knowledge bases;

[0034] The query module is used to use multiple similar knowledge bases as the retrieval scope corresponding to the user's query.

[0035] The system for improving RAG retrieval capabilities according to embodiments of this application includes one or more processors and a memory. The memory stores a computer program, and when the computer program is executed by the processor, it implements the method for improving RAG retrieval capabilities according to any of the above embodiments.

[0036] The computer-readable storage medium of the present application embodiments stores a computer program thereon, which, when executed by a processor, implements the method for improving RAG retrieval capabilities according to any of the above embodiments.

[0037] The method for improving RAG retrieval capability, the device for improving RAG retrieval capability, the system for improving RAG retrieval capability and the computer readable storage medium of the embodiments of the present application first cluster each knowledge base in the multi-source knowledge base through a predetermined clustering model to obtain a clustering center corresponding to each knowledge base; then perform similarity matching between a user query and the clustering center corresponding to each knowledge base to select a plurality of similar knowledge bases with high similarity to the user query from the multi-source knowledge base; and finally take the plurality of similar knowledge bases as a retrieval range corresponding to the user query. In this way, through clustering and awareness routing in the multi-source knowledge base, efficient knowledge field positioning and narrowing of the retrieval range can be realized.

[0038] Additional aspects and advantages of the embodiments of the present application will be in part apparent and in part pointed out hereinafter. BRIEF DESCRIPTION OF DRAWINGS

[0039] The above and / or additional aspects and advantages of the present application will become apparent and be readily appreciated from the following description, including the drawings, in which:

[0040] Figure 1 is a flowchart of the method for improving RAG retrieval capability of some embodiments of the present application;

[0041] Figure 2 is a schematic diagram of the overall working process of the method for improving RAG retrieval capability of some embodiments of the present application;

[0042] Figure 3 is a flowchart of the method for improving RAG retrieval capability of some embodiments of the present application;

[0043] Figure 4 is a flowchart of the method for improving RAG retrieval capability of some embodiments of the present application;

[0044] Figure 5 is a flowchart of the method for improving RAG retrieval capability of some embodiments of the present application;

[0045] Figure 6 is a flowchart of the method for improving RAG retrieval capability of some embodiments of the present application;

[0046] Figure 7 is a module schematic diagram of the device for improving RAG retrieval capability of some embodiments of the present application;

[0047] Figure 8 is a module schematic diagram of the system for improving RAG retrieval capability of some embodiments of the present application;

[0048] Figure 9Fig. 1 is a schematic diagram of the connection state of the computer-readable storage medium and the processor of some embodiments of the present application.

[0049] Legend of reference signs:

[0050] The device 100 for improving the retrieval capability of RAG, the clustering module 10, the matching module 20, the query module 30, the system 200 for improving the retrieval capability of RAG, the processor 210, the memory 220, the computer-readable storage medium 300, the computer program 310, and the processor 320. DETAILED DESCRIPTION

[0051] The embodiments of the present application are further described below with reference to the accompanying drawings. The same or similar reference signs are used throughout the drawings to represent the same or similar elements or elements having the same or similar functions. In addition, the embodiments of the present application described below with reference to the accompanying drawings are exemplary and are only used to explain the embodiments of the present application, and cannot be understood as a limitation on the present application.

[0052] It is found through research that the current retrieval-augmented generation (RAG) process in multi-source knowledge base retrieval is facing the following key problems:

[0053] (1) In multi-source knowledge bases, it is difficult to efficiently determine the field to which the query is applicable, resulting in "blind" queries, which seriously affect the retrieval efficiency and accuracy;

[0054] (2) Single vector similarity ranking can easily cause homogenization of recall content, ignoring semantic diversity;

[0055] (3) The current RAG process fails to deeply combine clustering structure for hierarchical semantic modeling, and cannot balance the depth and breadth of retrieval.

[0056] The RAG scheme in the related art first obtains the top-K document fragments most relevant to the user query through vectorization retrieval, combines a rerank model for similarity ranking, and then combines a large language model for content generation. This scheme has the following disadvantages:

[0057] First, the semantic homogenization of the retrieval results and the single content of the generation: In RAG, top-K similar documents are usually selected, and these documents are often highly similar in semantics, resulting in redundant and repetitive information content received by the language generation model, single results, no depth, and easy mixing of irrelevant documents in multi-source knowledge bases.

[0058] Second, unable to intelligently identify the knowledge field corresponding to the query: After receiving the query, the RAG system performs full-text vector recall on all accessed knowledge bases by default. There is a lack of intelligent matching or routing mechanism from "query semantics to knowledge field".

[0059] Third, lack of hierarchical modeling capability (granularity bottleneck): Global recall is powerless to capture hierarchical semantics.

[0060] Therefore, the embodiments of the present application provide a method for improving the retrieval capability of RAG, a device for improving the retrieval capability of RAG, a system for improving the retrieval capability of RAG, and a computer readable storage medium, which combine "intelligent knowledge base routing + cluster diversified sampling + hierarchical model fusion" to achieve efficient, accurate, and diverse generation enhancement.

[0061] Please refer to Figure 1 and Figure 2 The method for improving the retrieval capability of RAG of the embodiments of the present application comprises:

[0062] 010: clustering each knowledge base in the multi-source knowledge base by a predetermined clustering model to obtain a clustering center corresponding to each knowledge base;

[0063] 020: similarity matching the user query with the clustering center corresponding to each knowledge base to select a plurality of similar knowledge bases with high similarity to the user query from the multi-source knowledge base;

[0064] 030: taking the plurality of similar knowledge bases as the retrieval range corresponding to the user query.

[0065] The method for improving the retrieval capability of RAG of the embodiments of the present application first clusters each knowledge base in the multi-source knowledge base by a predetermined clustering model to obtain a clustering center corresponding to each knowledge base; then similarity matches the user query with the clustering center corresponding to each knowledge base to select a plurality of similar knowledge bases with high similarity to the user query from the multi-source knowledge base; and finally takes the plurality of similar knowledge bases as the retrieval range corresponding to the user query. In this way, efficient knowledge field positioning and narrowing of the retrieval range can be achieved by clustering and routing in the multi-source knowledge base.

[0066] Specifically, RAG is a hybrid artificial intelligence technology framework combining information retrieval and text generation, aiming to improve the accuracy, timeliness, and professionalism of the generation model by dynamically introducing external knowledge sources. RAG achieves knowledge enhancement through the following two-stage process:

[0067] In the retrieval stage (Retrieval), relevant content is retrieved from structured / unstructured knowledge bases (such as document libraries, databases, web pages, etc.) according to the user query. Vector similarity search, keyword matching, or hybrid retrieval techniques are used to quickly locate knowledge fragments related to the query semantics.

[0068] In the generation stage, the retrieved knowledge snippets are spliced with the original query as a context to input a generation model. The generation model generates a more accurate and professional answer based on the retrieved content, avoiding the "hallucination" problem.

[0069] The method for improving the RAG retrieval capability of the embodiments of the present application first clusters each knowledge base in the multi-source knowledge base through a predetermined clustering model to obtain a clustering center corresponding to each knowledge base. This process can be implemented by a multi-source knowledge base clustering routing awareness module.

[0070] The predetermined clustering model can be a K-means clustering model or an HDBSCAN clustering model.

[0071] The K-means clustering model is a distance-based hard clustering algorithm that divides data into K clusters, so that each sample point belongs to the nearest cluster center (mean point). The final result is to maximize the similarity within the group and minimize the difference between groups. The K-means clustering model has the advantages of simplicity, efficiency, strong interpretability, and fast convergence speed.

[0072] The HDBSCAN clustering model is a density-based hierarchical clustering algorithm that automatically identifies clusters of any shape and filters noise points by constructing a density hierarchy of data points without pre-specifying the number of clusters. The HDBSCAN clustering model has the advantages of automatic cluster number determination, handling of clusters of any shape, and strong robustness.

[0073] In actual applications, appropriate clustering models can be selected according to specific circumstances. For example, if the data is regularly distributed and needs to be quickly clustered, the K-means clustering model can be preferred. If the data density is uneven or the cluster shape is complex, the HDBSCAN clustering model can be preferred.

[0074] The embodiments of the present application take the K-means clustering model as an example for illustration. Each knowledge base in the multi-source knowledge base is clustered by the K-means clustering model to obtain a K-means clustering center corresponding to each knowledge base and store it.

[0075] Then, the user query is matched with the clustering center corresponding to each knowledge base in terms of similarity to select a plurality of similar knowledge bases with high similarity to the user query from the multi-source knowledge bases. That is, the user query is matched with the K-means clustering center corresponding to each knowledge base in terms of similarity. When the user query is matched with the K-means clustering center corresponding to each knowledge base in terms of similarity, a plurality of similarity scores (the higher the similarity, the higher the score) can be obtained, and the highest score is selected as the score of the knowledge base. Thus, the score corresponding to each knowledge base can be obtained, and the Top-K knowledge bases with the highest similarity are selected from the multi-source knowledge bases according to the scores of the knowledge bases, so as to narrow the search range and improve the search efficiency and accuracy.

[0076] Finally, the plurality of similar knowledge bases are taken as the search range corresponding to the user query. That is, the Top-K knowledge bases with the highest similarity are taken as the search range corresponding to the user query. In subsequent search, the user query is searched in the Top-K knowledge bases with the highest similarity. In this way, the clustering-aware routing in the multi-source knowledge bases can realize efficient knowledge field positioning and narrow the search range.

[0077] Please refer to Figure 3 In some embodiments, each knowledge base in the multi-source knowledge bases is clustered by a predetermined clustering model to obtain a clustering center corresponding to each knowledge base (i.e., 010), including:

[0078] 011: Each document of the knowledge base is processed by block, and each document block is converted into a corresponding document vector;

[0079] 012: The document vectors of each knowledge base are clustered by a predetermined clustering model, and the number of clusters is determined based on the silhouette coefficient to determine the clustering center corresponding to each knowledge base;

[0080] The user query is matched with the clustering center corresponding to each knowledge base in terms of similarity to select a plurality of similar knowledge bases with high similarity to the user query from the multi-source knowledge bases (i.e., 020), including:

[0081] 021: The user query is converted into a query vector;

[0082] 022: The similarity between the query vector and the clustering center corresponding to each knowledge base is calculated to select a plurality of similar knowledge bases with high similarity to the query vector from the multi-source knowledge bases.

[0083] Specifically, first, the documents of each knowledge base are indexed, the documents of the knowledge base are chunked, and then a pre-trained Embedding model is used to vectorize each document block to obtain the corresponding document vector. In some examples, when the documents of the knowledge base are chunked, the documents of the knowledge base can be divided into fixed-length document blocks, such as 512 characters / block, according to semantic integrity. The pre-trained Embedding model can be BERT, Sentence-BERT model, etc.

[0084] After obtaining the document vector, the document vector of each knowledge base can be subjected to K-means clustering, the optimal clustering K value is determined using the silhouette coefficient, the K-means clustering center corresponding to each knowledge base is determined and stored. In some examples, the document vector of each knowledge base can be subjected to unsupervised K-means clustering: the vector space is divided using the K-means algorithm, the optimal clustering K value is dynamically determined through the silhouette coefficient, and the balance between intra-cluster compactness and inter-cluster separation is ensured; the K clustering centers of each knowledge base and the corresponding document block distribution information are stored to form a hierarchical semantic index structure.

[0085] When a user query is received, to perform similarity matching between the user query and the clustering center, the user query can be converted into a query vector q using a pre-trained Embedding model. The similarity (which can be cosine similarity in particular) between the query vector q and the K-means clustering center corresponding to each knowledge base is calculated, and then a plurality of similarity scores (the higher the similarity, the higher the score) are obtained, and the highest score is selected as the score of the knowledge base. Thus, the score corresponding to each knowledge base can be obtained, and the knowledge bases are sorted according to the scores corresponding to the knowledge bases, and the Top-K knowledge bases most similar to the user query are selected from the multi-source knowledge bases as the retrieval range corresponding to the user query.

[0086] Referring to Figure 4 In some embodiments, the method for improving the retrieval capability of RAG further comprises:

[0087] 040: retrieving a plurality of document blocks with high similarity to the user query from the plurality of similar knowledge bases as candidate document blocks;

[0088] 050: performing vector normalization processing on each candidate document block to obtain a corresponding candidate document vector;

[0089] 060: subjecting the plurality of candidate document vectors to topic clustering and subtopic clustering to determine a clustering fusion semantic vector;

[0090] 070: calculate similarity between the query vector and the plurality of cluster fusion semantic vectors to select a plurality of current cluster fusion semantic vectors with high similarity to the query vector from the plurality of cluster fusion semantic vectors, and determine a plurality of current document blocks corresponding to the plurality of current cluster fusion semantic vectors.

[0091] Specifically, after obtaining the Top-K most similar knowledge bases, the Top-3K document blocks can be retrieved as candidate document blocks by combining the user query and the Top-K most similar knowledge bases according to semantic similarity. That is, the number of candidate document blocks is 3*Top-K. Of course, in other examples, the number of candidate document blocks can also be 2*Top-K, 4*Top-K, 5*Top-K, etc., which is not limited here.

[0092] Then, the vector normalization processing is performed on each candidate document block to obtain the corresponding candidate document vector. Specifically, the candidate document block can be first converted into a candidate document vector using a pre-trained Embedding model, and then L2 normalization (unitization) is performed to make the norm 1. In this way, the vector scale can be unified to ensure the consistency of the vector scale of the K-means clustering and the cosine similarity used subsequently.

[0093] After that, the plurality of candidate document vectors are sequentially subjected to topic clustering and subtopic clustering to determine the cluster fusion semantic vectors.

[0094] Finally, the similarity (which can be cosine similarity) between the query vector and the plurality of cluster fusion semantic vectors is calculated to select the Top-M current cluster fusion semantic vectors with the highest similarity to the query vector from the plurality of cluster fusion semantic vectors, and find the Top-M current document blocks corresponding to the Top-M current cluster fusion semantic vectors, i.e., the document blocks to which the prototypes of the Top-M current cluster fusion semantic vectors belong.

[0095] The present application embodiment can improve the semantic richness of the recall result through the diversity clustering retrieval strategy, and in addition, the introduction of the topic clustering and subtopic clustering fusion mechanism can enhance the semantic integrity and context relevance of the generated result.

[0096] Please refer to Figure 5 In some embodiments, the topic clustering and subtopic clustering are performed on the plurality of candidate document vectors to determine the cluster fusion semantic vectors (i.e., 060), which comprises:

[0097] 061: performing topic clustering on the plurality of candidate document vectors by using a predetermined clustering model, and determining the number of clusters based on the silhouette coefficient to determine a plurality of topic clusters;

[0098] 062: Selecting multiple candidate document vectors with high similarity to the query vector as representative document vectors of each topic cluster;

[0099] 063: Performing sub-topic clustering on the representative document vectors by using a hierarchical clustering model to obtain multiple sub-topic clusters;

[0100] 064: Calculating the semantic center vector of each sub-topic cluster by averaging the representative document vectors in the sub-topic cluster;

[0101] 065: Determining the cluster fusion semantic vector based on the semantic center vector of each topic cluster and the semantic center vectors of the corresponding multiple sub-topic clusters.

[0102] Specifically, in the embodiments of the present application, the topic clustering and sub-topic clustering of the multiple candidate document vectors to determine the cluster fusion semantic vector can include the following processes:

[0103] Candidate document topic clustering: using a K-means clustering model to perform K-means clustering on the multiple candidate document vectors, combining the silhouette coefficient to determine the optimal clustering k value, and generating K topic clusters. In this way, the candidate documents can be clustered into different subspaces according to semantics.

[0104] Selecting representative documents within the cluster: selecting the Top-K candidate document vectors with the highest similarity to the query vector q as the representative document vectors of the topic cluster. The purpose of this operation is to sample from multiple semantic clusters to ensure that the content input to the language generation model has extensive topic coverage and diversity.

[0105] Performing secondary clustering on the selected documents within the cluster: further using an agglomerative clustering model to perform secondary sub-cluster division in each coarse-grained cluster (i.e., topic cluster). The purpose of this operation is to construct a semantic hierarchy to capture the fine-grained differences within the main cluster, which helps to construct a clearer topic sub-tree.

[0106] Obtaining secondary clustering sub-cluster content: calculating the semantic center vector of each sub-topic cluster by averaging the document vectors in the sub-topic cluster.

[0107] Merging topic clustering content and secondary clustering results: merging the primary topic cluster center and the corresponding sub-cluster center to obtain the cluster fusion semantic vector. The purpose of this operation is to fuse the semantic trunk and details to construct a more complete semantic vector representation for more accurate final matching.

[0108] In the above technical solution, by introducing a hierarchical clustering and coarse-grained clustering model fusion mechanism, the semantic completeness and context relevance of the generated results can be enhanced.

[0109] In some embodiments, the cluster fusion semantic vector is determined according to the semantic center vector of each topic cluster and the semantic center vectors of the corresponding plurality of sub-topic clusters, comprising:

[0110] The semantic center vector of each topic cluster and the semantic center vectors of the corresponding plurality of sub-topic clusters are weighted and averaged to obtain the cluster fusion semantic vector.

[0111] Specifically, weights can be respectively assigned to the semantic center vector of each topic cluster and the semantic center vectors of the corresponding plurality of sub-topic clusters, wherein the sum of the weights is 1. Then, the semantic center vector of each topic cluster and the semantic center vectors of the corresponding plurality of sub-topic clusters are weighted and averaged using the above-mentioned weights to obtain the cluster fusion semantic vector. In this way, the semantic stem and details are fused to construct a more complete semantic vector representation for more accurate final matching.

[0112] Referring to Figure 6 In some embodiments, the method for improving the retrieval capability of RAG further comprises:

[0113] 080: inputting the user query and the plurality of current document blocks into a predetermined language model;

[0114] 090: generating a corresponding response based on the user query and the plurality of current document blocks through the predetermined language model.

[0115] Specifically, the user query and the retrieval context content (i.e. the content of the aforementioned plurality of current document blocks) can be spliced into a prompt word (Prompt) and input into the predetermined language model to generate a response through the predetermined language model.

[0116] The predetermined language model, i.e. the language generation model, can adopt a large language model (Large Language Model, LLM). LLM is an artificial intelligence model based on deep learning, which learns massive text data to understand and generate human language. The core is to capture the complex structure, semantics and context relationship of language, so as to exhibit strong ability in various natural language processing tasks. LLM has strong language understanding and generation ability, efficient knowledge transfer and generalization characteristics, accurate and efficient processing tasks, and supports complex reasoning and creative output.

[0117] In one example, the predetermined language model is a DeepSeek-V3 model. Through the DeepSeek-V3 model combined with the Prompt and the Top-M current document blocks, a corresponding response can be generated.

[0118] In the embodiments of the present application, the user query and a plurality of current document blocks are input into a predetermined language model, the predetermined language model can obtain high-quality input document blocks across topics and levels, thereby improving the diversity, logic and integrity of the output answers.

[0119] In summary, the method for improving the RAG retrieval capability in the embodiments of the present application has at least the following advantages:

[0120] (1) Knowledge base level cluster-aware routing mechanism: K-means semantic cluster center index is constructed for multi-source heterogeneous knowledge bases, intelligent selection is realized by matching the query vector with each knowledge base center, the search range is significantly reduced, and the domain positioning accuracy is improved.

[0121] (2) Cluster-driven diversity document sampling mechanism: the most relevant representative document to the user query is selected in each cluster, the language generation model is avoided from inputting repeated content, and the knowledge coverage is improved.

[0122] (3) Hierarchical clustering and prototype fusion mechanism: sub-cluster clustering is performed on the basis of primary clustering, sub-cluster semantic centers are generated and fused with the main cluster semantic center, thereby realizing the semantic hierarchy from "topic to sub-topic" in the semantic space, and improving the completeness and context consistency of generation.

[0123] Please refer to Figure 7 The device 100 for improving the RAG retrieval capability in the embodiments of the present application includes a clustering module 10, a matching module 20 and a query module 30. The clustering module 10 is configured to cluster each knowledge base in the multi-source knowledge base by a predetermined clustering model to obtain a cluster center corresponding to each knowledge base. The matching module 20 is configured to perform similarity matching between the user query and the cluster center corresponding to each knowledge base, so as to select a plurality of similar knowledge bases with high similarity to the user query from the multi-source knowledge base. The query module 30 is configured to take the plurality of similar knowledge bases as the search range corresponding to the user query.

[0124] In some embodiments, the clustering module 10 is specifically configured to: perform block processing on the documents of each knowledge base, and convert each document block into a corresponding document vector; cluster the document vectors of each knowledge base by a predetermined clustering model, and determine the cluster number based on the silhouette coefficient to determine the cluster center corresponding to each knowledge base. The matching module 20 is specifically configured to: convert the user query into a query vector; calculate the similarity between the query vector and the cluster center corresponding to each knowledge base, so as to select a plurality of similar knowledge bases with high similarity to the query vector from the multi-source knowledge base.

[0125] In some embodiments, the device 100 for improving RAG retrieval capability further comprises a processing module and a computing module. The query module 30 is further configured to retrieve a plurality of document blocks with high similarity to the user query from a plurality of similar knowledge bases as candidate document blocks. The processing module is configured to perform vector normalization on each candidate document block to obtain a corresponding candidate document vector. The clustering module 10 is further configured to perform topic clustering and subtopic clustering on the plurality of candidate document vectors to determine a cluster fusion semantic vector. The computing module is configured to calculate the similarity between the query vector and the plurality of cluster fusion semantic vectors to select a plurality of current cluster fusion semantic vectors with high similarity to the query vector from the plurality of cluster fusion semantic vectors, and determine a plurality of current document blocks corresponding to the plurality of current cluster fusion semantic vectors.

[0126] In some embodiments, the clustering module 10 is further configured to: select a plurality of candidate document vectors with high similarity to the query vector in each topic cluster as a representative document vector of the topic cluster; perform subtopic clustering on the representative document vectors by a hierarchical clustering model to obtain a plurality of subtopic clusters; determine a semantic center vector of each subtopic cluster by averaging the representative document vectors in the subtopic cluster; and determine the cluster fusion semantic vector according to the semantic center vector of each topic cluster and the semantic center vectors of the corresponding plurality of subtopic clusters.

[0127] In some embodiments, the clustering module 10 is further configured to: perform weighted averaging on the semantic center vector of each topic cluster and the semantic center vectors of the corresponding plurality of subtopic clusters to obtain the cluster fusion semantic vector.

[0128] In some embodiments, the device 100 for improving RAG retrieval capability further comprises an input module and a generating module. The input module is configured to input the user query and the plurality of current document blocks into a predetermined language model. The generating module is configured to generate a corresponding answer based on the user query and the plurality of current document blocks by the predetermined language model.

[0129] In some embodiments, the predetermined clustering model is a K-means clustering model or an HDBSCAN clustering model.

[0130] It should be noted that the above-mentioned embodiments of the method for improving RAG retrieval capability are also applicable to the device 100 for improving RAG retrieval capability of the embodiments of the present application, and will not be described here.

[0131] Please refer to Figure 8 The system 200 for improving RAG retrieval capability of the embodiments of the present application comprises one or more processors 210 and a memory 220, and the memory 220 stores a computer program. When the computer program is executed by the processor 210, the method for improving RAG retrieval capability of any of the above-mentioned embodiments is implemented.

[0132] For example, the computer program is executed by the processor 210, and a method for improving the RAG retrieval capability is implemented as follows:

[0133] 010: clustering each knowledge base in the multi-source knowledge base by a predetermined clustering model to obtain a clustering center corresponding to each knowledge base;

[0134] 020: similarity matching the user query with the clustering center corresponding to each knowledge base to select a plurality of similar knowledge bases with high similarity to the user query from the multi-source knowledge base;

[0135] 030: taking the plurality of similar knowledge bases as the retrieval range corresponding to the user query.

[0136] For example, the computer program is executed by the processor 210, and a method for improving the RAG retrieval capability is implemented as follows:

[0137] 011: block processing the documents of each knowledge base, and converting each document block into a corresponding document vector;

[0138] 012: clustering the document vectors of each knowledge base by a predetermined clustering model, and determining the clustering number based on the silhouette coefficient to determine the clustering center corresponding to each knowledge base;

[0139] 021: converting the user query into a query vector;

[0140] 022: calculating the similarity between the query vector and the clustering center corresponding to each knowledge base to select a plurality of similar knowledge bases with high similarity to the query vector from the multi-source knowledge base.

[0141] It should be noted that the above-mentioned method for improving the RAG retrieval capability is also applicable to the system 200 for improving the RAG retrieval capability of the embodiments of the present application, and will not be described here.

[0142] Referring to Figure 9 The computer readable storage medium 300 of the embodiments of the present application has a computer program 310 stored thereon. The program is executed by the processor 320, and the method for improving the RAG retrieval capability of any of the above-mentioned embodiments is implemented.

[0143] For example, the program is executed by the processor 320, and a method for improving the RAG retrieval capability is implemented as follows:

[0144] 010: clustering each knowledge base in the multi-source knowledge base by a predetermined clustering model to obtain a clustering center corresponding to each knowledge base;

[0145] 020: matching the user query with the cluster centers corresponding to each knowledge base to select a plurality of similar knowledge bases with high similarity to the user query from the multi-source knowledge bases;

[0146] 030: taking the plurality of similar knowledge bases as the search range corresponding to the user query.

[0147] For another example, when the program is executed by the processor 320, the method for improving the RAG search capability is implemented as follows:

[0148] 011: performing block processing on the documents of each knowledge base, and converting each document block into a corresponding document vector;

[0149] 012: clustering the document vectors of each knowledge base by a predetermined clustering model, and determining the number of clusters based on the silhouette coefficient to determine the cluster center corresponding to each knowledge base;

[0150] 021: converting the user query into a query vector;

[0151] 022: calculating the similarity between the query vector and the cluster center corresponding to each knowledge base to select a plurality of similar knowledge bases with high similarity to the query vector from the multi-source knowledge bases.

[0152] It should be noted that the above-mentioned method for improving the RAG search capability is also applicable to the computer-readable storage medium 300 of the embodiments of the present application, and will not be described here.

[0153] In summary, the method for improving the RAG search capability, the device 100 for improving the RAG search capability, the system 200 for improving the RAG search capability, and the computer-readable storage medium 300 of the embodiments of the present application first cluster each knowledge base in the multi-source knowledge base by a predetermined clustering model to obtain the cluster center corresponding to each knowledge base; then, match the user query with the cluster center corresponding to each knowledge base to select a plurality of similar knowledge bases with high similarity to the user query from the multi-source knowledge bases; finally, take the plurality of similar knowledge bases as the search range corresponding to the user query. In this way, by clustering and routing in the multi-source knowledge base, efficient knowledge field positioning and narrowing of the search range can be achieved.

[0154] In the description of the specification, the description of the terms "one embodiment", "some embodiments", "an example", "a specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present application. In the specification, the illustrative description of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any suitable manner in one or more embodiments or examples. In addition, the person skilled in the art can combine and combine the different embodiments or examples described in the specification and the features of the different embodiments or examples, without contradiction.

[0155] Any process or method descriptions or descriptions of the flow diagrams in the specification can be understood as representing code modules, segments, or portions of code which include one or more executable instructions for performing specific logic functions or steps in the process, and the various embodiments of the application include additional or different modules, segments, or portions of code when implemented in software or firmware in combination with the hardware. The various embodiments of the application can also include hardware logic that is implemented in a logic device, including a programmable logic device or another device that is configured to operate based on instructions in accordance with the logic device's operational mode.

[0156] The logic and / or steps represented in the flow diagrams or otherwise described herein, for example, can be embodied in computer executable code that can be implemented by one or more machine using instructions that are part of the operational data such that the instructions are operated on by the operational data or that operate on the operational data. As such, one embodiment of the application can be embodied in a number of different forms, all of which have been contemplated to be within the scope of the applicable patent princi¬ ples described herein. For example, the embodiments can also be imple¬ mented as a system, method, apparatus or device that is specifically configured to perform the operations described or otherwise be operable to perform the operations described. Additionally, the embodiments can be implemented using an operating system that can be any of the well-known operating systems permitted for use in the art. Further, the embodiments of the application can be implemented on a computer having one or more central processing units (CPU), memory storage devices, digital storage devices, network connections, one or more input devices, and one or more output devices.

[0157] It should be understood that parts of the present application can be realized in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be realized in software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if realized in hardware, and as in another embodiment, any of the following technologies known in the art or their combinations can be used: discrete logic circuit with logic gates for implementing logic functions on data signals, application specific integrated circuit with appropriate combinational logic gates, programmable gate array (PGA), field programmable gate array (FPGA), etc.

[0158] Those skilled in the art of the present technology can understand that all or part of the steps carried out by the above-mentioned embodiment methods can be completed by programs instructing relevant hardware, and the programs can be stored in a computer readable storage medium. When the program is executed, it includes one of the steps of the method embodiment or a combination thereof. In addition, each functional unit in each embodiment of the present application can be integrated in one processing module, or each unit can be physically present separately, or two or more units can be integrated in one module. The above-mentioned integrated module can be realized in the form of hardware or in the form of a software function module. The integrated module, if realized in the form of a software function module and sold or used as an independent product, can also be stored in a computer readable storage medium. The above-mentioned storage medium can be a read-only memory, a magnetic disk or an optical disk, etc.

[0159] Although the embodiments of the present application have been shown and described above, it should be understood that the above-mentioned embodiments are exemplary and cannot be understood as limiting the present application. Those skilled in the art can make changes, modifications, replacements and variations to the above-mentioned embodiments within the scope of the present application, and the scope of the present application is defined by the claims and their equivalents.

Claims

1. A method for improving RAG retrieval capabilities, characterized in that, include: Each knowledge base in the multi-source knowledge base is clustered using a predefined clustering model to obtain the cluster center corresponding to each knowledge base. The user query is matched with the cluster center corresponding to each of the knowledge bases to select multiple similar knowledge bases with the highest similarity to the user query from the multi-source knowledge bases. The multiple similar knowledge bases are used as the search scope corresponding to the user query.

2. The method for improving RAG retrieval capabilities according to claim 1, characterized in that, The step of clustering each knowledge base in the multi-source knowledge base using a predetermined clustering model to obtain the cluster center corresponding to each knowledge base includes: The documents of each knowledge base are divided into blocks, and each document block is converted into a corresponding document vector; The document vectors of each knowledge base are clustered using the predetermined clustering model, and the number of clusters is determined based on the silhouette coefficient, so as to determine the cluster center corresponding to each knowledge base; The step of matching the user query with the cluster center corresponding to each of the knowledge bases to select multiple similar knowledge bases with the highest similarity to the user query from the multi-source knowledge bases includes: Transform the user query into a query vector; Calculate the similarity between the query vector and the cluster center corresponding to each knowledge base, so as to select multiple similar knowledge bases with the highest similarity to the query vector from the multi-source knowledge base.

3. The method for improving RAG retrieval capabilities according to claim 2, characterized in that, The methods for improving RAG retrieval capabilities also include: Retrieve multiple document blocks with the highest similarity to the user query from multiple similar knowledge bases, and use them as candidate document blocks; Each candidate document block is subjected to vector normalization to obtain the corresponding candidate document vector; Multiple candidate document vectors are subjected to topic clustering and subtopic clustering to determine clustered fusion semantic vectors; Calculate the similarity between the query vector and multiple clustering fusion semantic vectors, select multiple current clustering fusion semantic vectors with the highest similarity to the query vector from the multiple clustering fusion semantic vectors, and determine multiple current document blocks corresponding to the multiple current clustering fusion semantic vectors.

4. The method for improving RAG retrieval capabilities according to claim 3, characterized in that, The step of performing topic clustering and subtopic clustering on multiple candidate document vectors to determine clustered fused semantic vectors includes: Multiple candidate document vectors are clustered by topic using the predetermined clustering model, and the number of clusters is determined based on the silhouette coefficient to identify multiple topic clusters. In each topic cluster, select several candidate document vectors that have the highest similarity to the query vector as the representative document vector of the topic cluster; The representative document vectors are clustered into subtopics using a hierarchical clustering model to obtain multiple subtopic clusters. The semantic center vector of each subtopic cluster is determined by averaging the representative document vectors in each subtopic cluster. The clustering fusion semantic vector is determined based on the semantic center vector of each topic cluster and the semantic center vectors of the corresponding multiple sub-topic clusters.

5. The method for improving RAG retrieval capabilities according to claim 4, characterized in that, The step of determining the clustering fusion semantic vector based on the semantic center vector of each topic cluster and the semantic center vectors of the corresponding multiple sub-topic clusters includes: The semantic center vector of each topic cluster is weighted and averaged with the semantic center vectors of the corresponding multiple sub-topic clusters to obtain the clustering fusion semantic vector.

6. The method for improving RAG retrieval capabilities according to claim 3, characterized in that, The methods for improving RAG retrieval capabilities also include: The user query and multiple current document blocks are input into a predetermined language model; The predetermined language model generates a corresponding answer based on the user query and multiple current document blocks.

7. The method for improving RAG retrieval capabilities according to any one of claims 1-6, characterized in that, The predetermined clustering model is either the K-means clustering model or the HDBSCAN clustering model.

8. An apparatus for enhancing RAG retrieval capabilities, characterized in that, include: The clustering module is used to cluster each knowledge base in the multi-source knowledge base using a predetermined clustering model to obtain the cluster center corresponding to each knowledge base. The matching module is used to perform similarity matching between the user query and the cluster center corresponding to each of the knowledge bases, so as to select multiple similar knowledge bases with the highest similarity to the user query from the multi-source knowledge bases; The query module is used to use multiple similar knowledge bases as the retrieval scope corresponding to the user's query.

9. A system for improving RAG retrieval capabilities, characterized in that, The system for improving RAG retrieval capabilities includes one or more processors and a memory, the memory storing a computer program that, when executed by the processor, implements the method for improving RAG retrieval capabilities as described in any one of claims 1-7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by a processor, it implements the method for improving RAG retrieval capabilities as described in any one of claims 1-7.