RAG mixed retrieval method and device
By dynamically adjusting vector and keyword retrieval weights, combined with multi-dimensional feature scoring and domain-specific parameter adjustment, the problems of query adaptability and semantic recognition of RAG technology in professional fields have been solved, achieving efficient retrieval and generation results.
Patent Information
- Application Number
- CN202511580922.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-31
- Publication Date
- 2026-02-10
AI Technical Summary
Existing RAG technology faces challenges in professional applications, including poor query adaptability due to fixed-weight fusion strategies, insufficient single-dimensional similarity evaluation, and insufficient adaptability of general models, which affect the quality and reliability of generated content.
By employing dynamically adjusted vector retrieval weights and keyword retrieval weights, combined with a multi-dimensional feature scoring strategy, including keyword matching degree, semantic similarity, document structure features, and positional weights, and adjusting parameters through a domain dictionary and a pre-trained model, we can achieve accurate recognition of professional terms and domain-specific semantic patterns.
It improves the retrieval accuracy of query texts and the relevance of response texts, overcomes the limitations of a single scoring dimension, and enhances semantic understanding capabilities and the reliability of generated content in professional fields.
Smart Images

Figure CN121501944A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of information retrieval, in particular to a RAG hybrid retrieval method and device. BACKGROUND
[0002] Retrieval-Augmented Generation (RAG) technology is an important breakthrough in the field of natural language processing. It combines traditional information retrieval with modern generative AI to build a new architecture of "retrieval-augmentation-generation". This architecture effectively solves the problem of hallucination in pure generative models, and overcomes the limitations of traditional retrieval systems lacking semantic understanding ability. Currently, RAG technology has been successfully applied to intelligent customer service, knowledge question answering, document summarization and other scenarios. However, the existing RAG technology faces three key challenges in professional field applications: first, the traditional retrieval method uses a fixed weight fusion strategy, which cannot automatically adjust the weight ratio of keyword retrieval and semantic retrieval according to the query content, resulting in poor adaptability to professional terms and mixed language queries; second, only single-dimensional similarity is considered when reordering the retrieval results, lacking joint evaluation of multi-dimensional features such as document structure and position weight; third, general retrieval models are difficult to adapt to different domain characteristics, especially in professional scenarios such as patent literature, they cannot effectively identify the importance of technical terms and domain-specific semantic association patterns. These limitations directly affect the quality and reliability of the final generated content. SUMMARY
[0003] To solve the above problems, the present application provides a RAG hybrid retrieval method, comprising the steps of:
[0004] obtaining vector retrieval weight and keyword retrieval weight according to the query text and the term library;
[0005] obtaining a document library, performing vector retrieval on the document library according to the query text and the vector retrieval weight to obtain a first candidate document set, and performing keyword retrieval on the document library according to the query text and the keyword retrieval weight to obtain a second candidate document set;
[0006] merging the first candidate document set and the second candidate document set to obtain a fusion document set;
[0007] performing comprehensive feature score calculation, filtering and sorting on each document in the fusion document set to obtain a final document sequence, inputting the final document sequence into a large language model to obtain an answer text.
[0008] Optionally, the vector retrieval weight and the keyword retrieval weight are calculated according to the query text and the term library, specifically comprising:
[0009] performing word segmentation on the query text to obtain all words, and obtaining a total number of words;
[0010] matching each word with each term in the term library, and taking the number of words matched as the number of terms;
[0011] taking the ratio of the number of terms to the total number of words as the term density, calculating the vector retrieval weight a according to the term density, and taking 1-a as the keyword retrieval weight.
[0012] Optionally, performing vector retrieval on the document library according to the query text and the vector retrieval weight to obtain a first candidate document set, specifically comprising:
[0013] obtaining an initial language embedding model, and adjusting parameters of the initial language embedding model according to the vector retrieval weight to obtain a final language embedding model;
[0014] inputting the query text into the final language embedding model to obtain a query vector;
[0015] inputting each document in the document library into the final language embedding model to obtain a document vector of each document;
[0016] calculating the cosine similarity between the query vector and each document vector, and taking each document with a cosine similarity greater than a first preset value as the first candidate document set.
[0017] Optionally, performing keyword retrieval on the document library according to the query text and the keyword retrieval weight to obtain a second candidate document set, specifically comprising:
[0018] obtaining an initial language recognition model, and adjusting parameters of the initial language recognition model according to the keyword retrieval weight to obtain a final language recognition model;
[0019] obtaining a synonym expansion library and each keyword in the query text, expanding each keyword according to the synonym expansion library, taking the synonyms of each keyword as new keywords, obtaining all expanded keywords, and taking the all expanded keywords as a keyword set;
[0020] inputting the keyword set and each document in the document library into the final language recognition model, and calculating the BM25 score between the keyword set and each document according to the BM25 algorithm, and taking each document with a BM25 score greater than a second preset value as the second candidate document set.
[0021] Optionally, performing merging processing on the first candidate document set and the second candidate document set to obtain a fusion document set, specifically comprising:
[0022] obtaining each document existing in both the first candidate document set and the second candidate document set as a fusion document set.
[0023] Optionally, the calculation, screening and sorting of the comprehensive feature score of each document in the fusion document set are performed to obtain a final document sequence, specifically including:
[0024] obtaining the BM25 score and the cosine similarity of each document in the fusion document set;
[0025] obtaining the keyword matching degree of each document according to the BM25 score of each document;
[0026] obtaining the semantic similarity of each document according to the cosine similarity of each document;
[0027] performing feature extraction on the significant information of each document to obtain the document structure feature value of each document;
[0028] obtaining all query words in the query text, and calculating the position weight of each document according to the position of each query word appearing in each document;
[0029] obtaining a domain dictionary, taking the number of query words belonging to the domain dictionary appearing in each document as the domain word quantity of each document, obtaining the total number of query words of the query text, and taking the ratio of the domain word quantity of each document to the total number of query words as an adjustment parameter of each document;
[0030] obtaining the comprehensive feature score of each document according to the keyword matching degree, the semantic similarity, the document structure feature value, the position weight and the adjustment parameter of each document;
[0031] retaining each document with a comprehensive feature score greater than a third preset value, and sequentially sorting the retained each document according to the comprehensive feature score from large to small to obtain a final document sequence.
[0032] Optionally, the calculation process of the comprehensive feature score of the i-th document specifically includes:
[0033] multiplying the first weight parameter, the second weight parameter, the third weight parameter and the fourth weight parameter with the keyword matching degree, the semantic similarity, the document structure feature value and the position weight of the i-th document respectively to obtain four multiplication results, adding the four multiplication results to obtain an addition result, and multiplying the addition result with the adjustment parameter of the i-th document to obtain the comprehensive feature score of the i-th document.
[0034] The application further provides an RAG hybrid retrieval device for implementing the RAG hybrid retrieval method, and the device comprises:
[0035] The weight calculation module is used to obtain the query text and terminology database, and calculate the vector retrieval weight and keyword retrieval weight based on the query text and terminology database;
[0036] The candidate document acquisition module is used to acquire a document library, perform vector retrieval on the document library based on the query text and vector retrieval weights to obtain a first candidate document set, and perform keyword retrieval on the document library based on the query text and keyword retrieval weights to obtain a second candidate document set.
[0037] The document fusion module is used to merge the first candidate document set and the second candidate document set to obtain a fused document set;
[0038] The response text output module is used to calculate, filter, and sort the comprehensive feature scores of each document in the fused document set to obtain the final document sequence. The final document sequence is then input into the large language model to obtain the response text.
[0039] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the RAG hybrid retrieval method.
[0040] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the aforementioned RAG hybrid retrieval method.
[0041] The present invention has the following beneficial effects:
[0042] 1. Vector retrieval weights and keyword retrieval weights that can be dynamically adjusted are used for vector retrieval and keyword retrieval respectively, avoiding the query adaptability problem caused by static weight strategies. The retrieval accuracy of the query text is improved by using dynamic vector retrieval weights and keyword retrieval weights.
[0043] 2. For professional domain scenarios, adjustment parameters are obtained based on the query terms of the query text and the domain dictionary. The value of the comprehensive feature score is adjusted by adjusting the parameters to achieve accurate recognition of technical terms and domain-specific semantic patterns.
[0044] 3. A comprehensive feature score for documents is calculated based on keyword matching degree, semantic similarity, document structure feature value, position weight, and adjustment parameters. The final document sequence is selected based on the comprehensive feature score and input into the large language model to obtain the response text. This overcomes the limitations of a single scoring dimension in professional domain retrieval and improves the relevance between the response text and the query text through multi-dimensional feature joint evaluation. Attached Figure Description
[0045] To more clearly illustrate the technical solutions in the embodiments or related technologies of this application, the drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0046] Figure 1 This is a flowchart of a method according to an embodiment of the present invention;
[0047] Figure 2 This is a structural diagram of the device according to an embodiment of the present invention. Detailed Implementation
[0048] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the embodiments of this application. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0049] Reference Figure 1 This invention provides a RAG hybrid retrieval method, comprising the following steps:
[0050] Obtain the query text and terminology database, and calculate the vector retrieval weight and keyword retrieval weight based on the query text and terminology database;
[0051] In some embodiments, vector retrieval weights and keyword retrieval weights are calculated based on the query text and terminology database, specifically including:
[0052] Perform word segmentation on the query text to obtain all words, and then obtain the total number of words.
[0053] Each word is matched with each term in the terminology database, and the number of words that are matched with terms is taken as the term count.
[0054] The ratio of the number of terms to the total number of words is used as the term density. The vector retrieval weight α is calculated based on the term density, and 1-α is used as the keyword retrieval weight.
[0055] In some embodiments, by analyzing features such as the density of technical terms and the frequency of capitalized words in the query text, the feature values are normalized using the sigmoid function to generate vector retrieval weight α and keyword retrieval weight 1-α. The weight ratio of keyword retrieval and semantic vector retrieval is adjusted in real time to solve the adaptability problem of traditional fixed weight strategies.
[0056] The vector retrieval weight α∈(0.3,0.7) is calculated using the following formula:
[0057] α = 0.3 + 0.4 / (1+e^(-5*(term_density-0.5)))
[0058] The term density calculation module, upon receiving the user's query text, first performs word segmentation on the query text and counts the number of terms that match the terminology database, denoted as match_terms. It also records the total number of words in the query text, total_words. The term density term_density is defined as term_density = match_terms / total_words.
[0059] Obtain the document library, perform vector retrieval on the document library based on the query text and vector retrieval weights to obtain the first candidate document set; perform keyword retrieval on the document library based on the query text and keyword retrieval weights to obtain the second candidate document set;
[0060] In some embodiments, vector retrieval is performed on the document library based on the query text and vector retrieval weights to obtain a first candidate document set, specifically including:
[0061] Obtain the initial language embedding model, and adjust the parameters of the initial language embedding model according to the vector retrieval weights to obtain the final language embedding model;
[0062] Input the query text into the final language embedding model to obtain the query vector;
[0063] Each document in the document library is input into the final language embedding model to obtain the document vector of each document;
[0064] The cosine similarity between the query vector and each document vector is calculated, and documents with a cosine similarity greater than a first preset value are selected as the first candidate document set.
[0065] In some embodiments, the language embedding model may employ the Sentence-BERT embedding model, and query vectors and document vectors may be obtained based on the Sentence-BERT embedding model.
[0066] In some embodiments, keyword retrieval is performed on the document library based on the query text and keyword retrieval weights to obtain a second candidate document set, specifically including:
[0067] Obtain the initial language recognition model, and adjust the parameters of the initial language recognition model according to the keyword retrieval weight to obtain the final language recognition model;
[0068] Obtain the thesaurus and keywords from the query text. Expand each keyword based on the thesaurus, use the synonyms of each keyword as new keywords, obtain all the expanded keywords, and use all the expanded keywords as a keyword set.
[0069] In some embodiments, high-frequency domain terms are extracted from professional corpora, and similarity calculations are performed with pre-trained language models (such as BERT) through rule template matching to identify possible synonymous expressions of the term in the context, including but not limited to full names, abbreviations, common aliases, synonyms, spelling variations, etc. The identified term expansion results are incorporated into a term mapping table in a many-to-one manner to form a structured synonym expansion library for keyword replacement and expansion during retrieval.
[0070] During the retrieval execution phase, the keyword expansion module receives the query terms input by the user, matches them with all equivalent terms in the expansion database through a table lookup method, and generates an expanded query set. Then, the expanded query set is input into the full-text index module for parallel retrieval to improve recall and term coverage, thereby enhancing the retrieval system's adaptability to domain semantics.
[0071] The keyword set and each document in the document library are input into the final language recognition model. The BM25 score between the keyword set and each document is calculated according to the BM25 algorithm. Documents with a BM25 score greater than the second preset value are selected as the second candidate document set.
[0072] In some embodiments, keyword retrieval is based on a domain-optimized inverted index using the BM25 algorithm. Compared to traditional keyword retrieval methods, this method adds a domain term synonym expansion library to optimize retrieval performance.
[0073] The first and second candidate document sets are merged to obtain a fused document set.
[0074] In some embodiments, the first candidate document set and the second candidate document set are merged to obtain a fused document set, specifically including:
[0075] Retrieve all documents that exist simultaneously in the first candidate document set and the second candidate document set, and use these documents as the fused document set.
[0076] In some embodiments, after vector retrieval and keyword retrieval are completed, the system obtains a first candidate document set D_v and a second candidate document set D_k, respectively. The two sets are then merged using a candidate merging module. Document ID-level deduplication and merging are performed on the two sets. If the same document appears in both D_v and D_k, its corresponding vector similarity and BM25 score are merged to form a fused document set. This fused document set ensures that important documents under different retrieval paths are uniformly sorted, improving document recall completeness and ranking comparability.
[0077] Considering the differences in numerical scales between different scoring sources (such as BM25 scores and cosine similarity), the system introduces a standardization process to ensure the additivity of multi-source features during the re-ranking stage, as follows:
[0078] For each rating type, min-max normalization is performed, mapping it to the [0,1] interval. For a certain score x, the normalization formula is as follows: x_norm = (x - x_min) / (x_max - x_min). Here, x_min and x_max represent the minimum and maximum values of that rating category in the current retrieval batch, respectively. For some rating values with a fixed range (e.g., cosine similarity ∈ [–1,1]), fixed interval normalization can be directly applied. Merging document sets ensures that important documents from different retrieval paths are processed in a unified order, improving document recall completeness and ranking comparability.
[0079] The comprehensive feature scores of each document in the fused document set are calculated, filtered, and sorted to obtain the final document sequence. The final document sequence is then input into the large language model to obtain the response text.
[0080] In some embodiments, comprehensive feature scores are calculated, filtered, and sorted for each document in the fused document set to obtain a final document sequence, specifically including:
[0081] Obtain the BM25 score and cosine similarity of each document in the fused document set;
[0082] The keyword matching degree of each document is calculated based on its BM25 score.
[0083] In some embodiments, the keyword matching degree K is based on the matching of the expanded query set with the keywords in the document, and is weighted by the BM25 score to reflect the frequency and importance of the query terms in the document.
[0084] The semantic similarity of each document is calculated based on the cosine similarity of each document.
[0085] In some embodiments, semantic similarity S uses the Sentence-BERT model to calculate the cosine similarity between the query vector and the document vector, capturing semantic relevance and enhancing the ability to identify synonymous or semantically similar expressions.
[0086] Feature extraction of salient information is performed on each document to obtain the document structure feature value of each document;
[0087] In some embodiments, the document structure feature value D analyzes the document content through structured analysis, including elements such as headings, bolded paragraph text, and keyword tags, to identify the location and weight of significant information within the document. For example, headings and bolded words have higher weights, reflecting their theme and key information;
[0088] Retrieve all query terms in the query text, and calculate the position weight of each document based on the position of each query term in each document;
[0089] In some embodiments, the position weight P assigns different weights to the position information of the query terms in the document, giving priority to the content of the first and last paragraphs of the document, as they usually contain summary or summary information, which improves the understanding of the semantic structure of the document. The specific position weight is calculated by weighting the paragraph number and the word frequency.
[0090] Obtain the domain dictionary, and use the number of times the query terms appearing in each document belong to the domain dictionary as the domain term count for each document. Obtain the total number of query terms in the query text, and use the ratio of the domain term count to the total number of query terms in each document as the adjustment parameter for each document.
[0091] In some embodiments, addressing the issue of insufficient adaptability of general retrieval models in specialized fields (such as patent retrieval), this invention designs an intelligent adjustment mechanism integrating a domain dictionary and a pre-trained domain classification model. This mechanism enables accurate identification and dynamic adaptation of technical terms and domain-specific semantic patterns, comprehensively improving the professional semantic understanding capabilities and retrieval performance of the RAG hybrid retrieval system. The domain dictionary construction and management are based on a large amount of high-quality corpus and expert annotations within the domain. The system initially and automatically extracts a domain terminology database, covering core technical terms, industry-specific terms, and their synonym extensions, supporting multi-level and multi-granular terminology representation. To achieve dynamic maintenance and efficient access, the terminology database is configured and stored in a dedicated domain dictionary database. The database design supports terminology version control, batch updates, and multi-dimensional indexing, improving retrieval and expansion efficiency. A comprehensive domain dictionary management API has been developed, supporting the addition, deletion, modification, and query of terms, synonym extension updates, and query invocation operations, ensuring real-time access and flexible interaction of the dictionary by the retrieval system and upstream and downstream modules. Through this database and interface system, the domain dictionary has transformed from a static resource to a dynamic service, greatly improving its adaptability and scalability, and providing a stable and efficient foundation for the semantic recognition and adjustment of the subsequent domain adaptive module.
[0092] The domain classification model employs a pre-trained deep neural network based on Transformer, fine-tuned with domain-annotated data, and possesses the ability to automatically identify the professional domain and sub-domains to which the text belongs. The model outputs semantic labels and confidence scores, providing a basis for subsequent semantic adjustments; the domain adjustment of the re-ranking results is based on the output of the classification model, performing domain-adaptation weighted corrections on the initial re-ranking results.
[0093] Specific strategies include weighting documents with a high density of core domain terms, suppressing noise content from outside the domain, and adjusting the sorting priority of documents with strong domain characteristics to ensure that the results list better meets the search expectations of professional users. The interpretability scoring report generation system automatically generates detailed domain adaptability scoring reports, including the domain relevance, term matching, and semantic association strength indicators of each document, providing users with a transparent explanation of the search results and supporting dynamic optimization of search strategies and responses to user-customized needs.
[0094] The comprehensive feature score of each document is calculated based on the keyword matching degree, semantic similarity, document structure feature value, position weight and adjustment parameters.
[0095] In some embodiments, the calculation process of the comprehensive feature score of the i-th document specifically includes:
[0096] The first, second, third, and fourth weight parameters are multiplied by the keyword matching degree, semantic similarity, document structure feature value, and position weight of the i-th document, respectively, to obtain four multiplication results. The four multiplication results are added together to obtain a summation result. The summation result is then multiplied by the adjustment parameter of the i-th document to obtain the comprehensive feature score of the i-th document.
[0097] In some embodiments:
[0098] The comprehensive feature score of the i-th document i The expression is:
[0099] Score i =R i (r1×K i +r2×S i +r3×D i +r4×P i )
[0100] Among them, K i S represents the keyword matching degree of the i-th document. i D represents the semantic similarity of the i-th document. i P represents the document structure feature value of the i-th document. i R represents the positional weight of the i-th document. i Let r1, r2, r3, and r4 represent the first, second, third, and fourth weight parameters, respectively.
[0101] In some embodiments, the weight parameters are determined through a combination of offline training and online tuning to ensure good adaptability and generalization ability across different professional fields and query types. The re-ranking process is based on standardized feature scores to avoid the impact of differences in the units of different indicators, and supports batch parallel processing to improve retrieval efficiency.
[0102] Documents with a comprehensive feature score greater than the third preset value are retained. The retained documents are then sorted in descending order of their comprehensive feature scores to obtain the final document sequence.
[0103] In some embodiments, documents with the highest comprehensive feature scores are fed into a Large Language Model (LLM) to generate response text. To improve the relevance and controllability of the response, a contextual prompt template control mechanism is introduced. The top-N document fragments are selected to form the retrieval context, concatenated in descending order of confidence, and elements such as task instructions, domain qualifiers, and response format constraints are filled into a predefined Prompt template to improve the accuracy of the response text.
[0104] refer to Figure 2The present invention also provides a RAG hybrid retrieval device 20 for implementing the aforementioned RAG hybrid retrieval method, the device comprising:
[0105] The weight calculation module 21 is used to obtain the query text and terminology database, and calculate the vector retrieval weight and keyword retrieval weight based on the query text and terminology database.
[0106] The candidate document acquisition module 22 is used to acquire a document library, perform vector retrieval on the document library based on the query text and vector retrieval weights to obtain a first candidate document set, and perform keyword retrieval on the document library based on the query text and keyword retrieval weights to obtain a second candidate document set.
[0107] Document fusion module 23 is used to merge the first candidate document set and the second candidate document set to obtain a fused document set;
[0108] The response text output module 24 is used to calculate, filter, and sort the comprehensive feature scores of each document in the fused document set to obtain the final document sequence. The final document sequence is then input into the large language model to obtain the response text.
[0109] This application provides an electronic device, including a processor and a memory; the memory stores a computer program, wherein the computer program, when executed by the processor, implements the RAG hybrid retrieval method of any of the above schemes.
[0110] Specifically, the processor may include, for example, a general-purpose microprocessor, an instruction set processor and / or an associated chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor may also include onboard memory for caching purposes. The processor may be a single processing unit or multiple processing units for performing different actions of the method flow according to embodiments of this application.
[0111] Memory can be any medium capable of containing, storing, transmitting, propagating, or transmitting instructions. For example, memory can include, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, instruments, or propagation media. Specific examples of memory include: magnetic storage devices such as magnetic tape or hard disk drives (HDDs); optical storage devices such as optical discs (CD-ROMs); and also random access memory (RAM) or flash memory; and / or wired / wireless communication links.
[0112] This application also provides a computer-readable medium storing a computer program thereon, which, when executed by a processor, implements the RAG hybrid retrieval method of any of the above schemes. This computer-readable medium may be included in the device / apparatus / system described in the above embodiments; or it may exist independently and not assembled into the device / apparatus / system. The aforementioned computer-readable medium carries one or more programs, which, when executed, implement the method as described in the embodiments of this application.
[0113] According to embodiments of this application, a computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wired, optical fiber, radio frequency signals, etc., or any suitable combination thereof.
[0114] Those skilled in the art will understand that the features described in the various embodiments and / or claims of this application can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in this application. In particular, the features described in the various embodiments and / or claims of this application can be combined and / or combined in various ways without departing from the spirit and teachings of this application. All such combinations and / or combinations fall within the scope of this application. Therefore, the scope of this application should not be limited to the above embodiments, but should be defined not only by the appended claims, but also by their equivalents. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A RAG hybrid retrieval method, characterized in that, Including the following steps: Obtain the query text and terminology database, and calculate the vector retrieval weight and keyword retrieval weight based on the query text and terminology database; Obtain the document library, perform vector retrieval on the document library based on the query text and vector retrieval weights to obtain the first candidate document set; perform keyword retrieval on the document library based on the query text and keyword retrieval weights to obtain the second candidate document set; The first and second candidate document sets are merged to obtain a fused document set. The comprehensive feature scores of each document in the fused document set are calculated, filtered, and sorted to obtain the final document sequence. The final document sequence is then input into the large language model to obtain the response text.
2. The RAG hybrid retrieval method according to claim 1, characterized in that, Vector retrieval weights and keyword retrieval weights are calculated based on the query text and terminology database, specifically including: Perform word segmentation on the query text to obtain all words, and then retrieve the total number of words. Each word is matched with each term in the terminology database, and the number of words that match into terms is taken as the term count. The ratio of the number of terms to the total number of words is used as the term density. The vector retrieval weight α is calculated based on the term density, and 1-α is used as the keyword retrieval weight.
3. The RAG hybrid retrieval method according to claim 1, characterized in that, Based on the query text and vector retrieval weights, a vector retrieval is performed on the document database to obtain the first candidate document set, which specifically includes: Obtain the initial language embedding model, and adjust the parameters of the initial language embedding model according to the vector retrieval weights to obtain the final language embedding model; Input the query text into the final language embedding model to obtain the query vector; Each document in the document library is input into the final language embedding model to obtain the document vector of each document; The cosine similarity between the query vector and each document vector is calculated, and documents with a cosine similarity greater than a first preset value are selected as the first candidate document set.
4. The RAG hybrid retrieval method according to claim 1, characterized in that, Based on the query text and keyword retrieval weights, a keyword search is performed on the document database to obtain a second candidate document set, which specifically includes: Obtain the initial language recognition model, and adjust the parameters of the initial language recognition model according to the keyword retrieval weight to obtain the final language recognition model; Obtain the thesaurus and keywords from the query text. Expand each keyword based on the thesaurus, use the synonyms of each keyword as new keywords, obtain all the expanded keywords, and use all the expanded keywords as a keyword set. The keyword set and each document in the document library are input into the final language recognition model. The BM25 score between the keyword set and each document is calculated according to the BM25 algorithm. Documents with a BM25 score greater than the second preset value are selected as the second candidate document set.
5. The RAG hybrid retrieval method according to claim 1, characterized in that, The first and second candidate document sets are merged to obtain a fused document set, which specifically includes: Retrieve all documents that exist simultaneously in the first candidate document set and the second candidate document set, and use these documents as the fused document set.
6. The RAG hybrid retrieval method according to claim 1, characterized in that, The final document sequence is obtained by calculating, filtering, and sorting the comprehensive feature scores of each document in the fused document set, specifically including: Obtain the BM25 score and cosine similarity of each document in the fused document set; The keyword matching degree of each document is calculated based on its BM25 score. The semantic similarity of each document is calculated based on the cosine similarity of each document. Feature extraction of salient information is performed on each document to obtain the document structure feature value of each document; Retrieve all query terms in the query text, and calculate the position weight of each document based on the position of each query term in each document; Obtain the domain dictionary, and use the number of times the query terms appearing in each document belong to the domain dictionary as the domain term count for each document. Obtain the total number of query terms in the query text, and use the ratio of the domain term count to the total number of query terms in each document as the adjustment parameter for each document. The comprehensive feature score of each document is calculated based on the keyword matching degree, semantic similarity, document structure feature value, position weight and adjustment parameters. Documents with a comprehensive feature score greater than the third preset value are retained. The retained documents are then sorted in descending order of their comprehensive feature scores to obtain the final document sequence.
7. The RAG hybrid retrieval method according to claim 6, characterized in that, The calculation process for the comprehensive feature score of the i-th document specifically includes: The first, second, third, and fourth weight parameters are multiplied by the keyword matching degree, semantic similarity, document structure feature value, and position weight of the i-th document, respectively, to obtain four multiplication results. The four multiplication results are added together to obtain a summation result. The summation result is then multiplied by the adjustment parameter of the i-th document to obtain the comprehensive feature score of the i-th document.
8. A RAG hybrid retrieval device for implementing the RAG hybrid retrieval method as described in any one of claims 1 to 7, characterized in that, The device includes: The weight calculation module is used to obtain the query text and terminology database, and calculate the vector retrieval weight and keyword retrieval weight based on the query text and terminology database; The candidate document acquisition module is used to acquire a document library, perform vector retrieval on the document library based on the query text and vector retrieval weights to obtain a first candidate document set, and perform keyword retrieval on the document library based on the query text and keyword retrieval weights to obtain a second candidate document set. The document fusion module is used to merge the first candidate document set and the second candidate document set to obtain a fused document set; The response text output module is used to calculate, filter, and sort the comprehensive feature scores of each document in the fused document set to obtain the final document sequence. The final document sequence is then input into the large language model to obtain the response text.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the RAG hybrid retrieval method as described in any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the RAG hybrid retrieval method as described in any one of claims 1 to 7.
Citation Information
Cited By
Knowledge base retrieval sorting method and system based on multi-dimensional content quality score
CN121705419A
Building material semantic retrieval method based on vector database
CN122064791A