Rag mixed search method and device
Patent Information
- Application Number
- CN202511580922.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-31
- Publication Date
- 2026-08-28
- Estimated Expiration
- 2045-10-31
AI Technical Summary
然而,现有RAG技术在专业领域应用中面临三个关键挑战:第一,传统检索方法采用固定权重融合策略,无法根据查询内容自动调整关键词检索和语义检索的权重比例,导致对专业术语和混合语言查询的适配性差;第二,检索结果重排序时仅考虑单一维度相似度,缺乏对文档结构、位置权重等多维特征的联合评估;第三,通用检索模型难以适应不同领域特性,特别是在专利文献等专业场景中,无法有效识别技术术语的重要性和领域特定的语义关联模式
[0042]1、采用可以动态调整的向量检索权重和关键词检索权重分别进行向量检索和关键词检索,避免了静态权重策略导致的查询适配性问题,通过动态的向量检索权重和关键词检索权重提高查询文本的检索精度;
Smart Images

Figure CN121501944B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of information retrieval technology, and in particular to a RAG hybrid retrieval method and apparatus. Background Technology
[0002] Retrieval-Augmented Generation (RAG) technology represents a significant breakthrough in natural language processing. It combines traditional information retrieval with modern generative AI to construct a novel "retrieval-augmentation-generation" architecture. This architecture effectively addresses the hallucination problem inherent in pure generative models while overcoming the limitations of traditional retrieval systems that lack semantic understanding. Currently, RAG technology has been successfully applied in various scenarios, including intelligent customer service, knowledge-based question answering, and document summarization. However, existing RAG technologies face three key challenges in professional domain applications: First, traditional retrieval methods employ fixed-weight fusion strategies, failing to automatically adjust the weight ratio of keyword retrieval and semantic retrieval based on the query content, resulting in poor adaptability to queries involving specialized terminology and mixed languages. Second, when re-ranking search results, only a single dimension of similarity is considered, lacking a joint evaluation of multi-dimensional features such as document structure and positional weights. Third, general-purpose retrieval models struggle to adapt to different domain characteristics, particularly in specialized scenarios such as patent documents, failing to effectively identify the importance of technical terms and domain-specific semantic association patterns. These limitations directly impact the quality and reliability of the final generated content. Summary of the Invention
[0003] To address the above problems, this invention provides a RAG hybrid retrieval method, comprising the following steps:
[0004] 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;
[0005] 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;
[0006] The first and second candidate document sets are merged to obtain a fused document set.
[0007] 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.
[0008] Optionally, vector retrieval weights and keyword retrieval weights are calculated based on the query text and terminology database, specifically including:
[0009] Perform word segmentation on the query text to obtain all words, and then retrieve the total number of words.
[0010] 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.
[0011] 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.
[0012] Optionally, a vector search is performed on the document library based on the query text and vector search weights to obtain a first candidate document set, specifically including:
[0013] 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;
[0014] Input the query text into the final language embedding model to obtain the query vector;
[0015] Each document in the document library is input into the final language embedding model to obtain the document vector of each document;
[0016] 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.
[0017] Optionally, a keyword search is performed on the document database based on the query text and keyword retrieval weights to obtain a second candidate document set, specifically including:
[0018] 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;
[0019] 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.
[0020] 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.
[0021] Optionally, the first candidate document set and the second candidate document set are merged to obtain a fused document set, specifically including:
[0022] 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.
[0023] Optionally, the comprehensive feature scores of each document in the fused document set are calculated, filtered, and sorted to obtain the final document sequence, specifically including:
[0024] Obtain the BM25 score and cosine similarity of each document in the fused document set;
[0025] The keyword matching degree of each document is calculated based on its BM25 score.
[0026] The semantic similarity of each document is calculated based on the cosine similarity of each document.
[0027] Feature extraction of salient information is performed on each document to obtain the document structure feature value of each document;
[0028] 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;
[0029] 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.
[0030] 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.
[0031] 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.
[0032] Optionally, the calculation process for the comprehensive feature score of the i-th document specifically includes:
[0033] 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.
[0034] The present invention also provides a RAG hybrid retrieval device for implementing the aforementioned RAG hybrid retrieval method, the device comprising:
[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 accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying 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 retrieve 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. 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.
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 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.
7. A RAG hybrid retrieval device for implementing the RAG hybrid retrieval method as described in any one of claims 1 to 6, 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.
8. 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 6.
9. 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 6.
Citation Information
Patent Citations
Data reordering retrieval method and system based on RAG
CN120086307A
File arrangement system and method capable of realizing multilingual conversion
CN120278119A