Retrieval report generation method and device based on local language model, equipment and medium
Through the search report generation method based on the local language model, combined with query intent enhancement, recursive search and multimodal data processing, the shortcomings of traditional search methods in complex queries are solved, and high-quality and structured search reports are generated, which improves user experience and system adaptability.
Patent Information
- Application Number
- CN202510531520.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-25
- Publication Date
- 2025-08-01
AI Technical Summary
Traditional information retrieval methods are difficult to provide high-quality, relevant and comprehensive results when facing complex and multi-level queries, and existing systems rely on a single data source, resulting in inaccurate or comprehensive answers.
A search report generation method based on the local language model is adopted to generate structured search reports through query intent enhancement, recursive search strategy, dynamic correlation filtering and user interaction, combined with local knowledge base and multimodal data processing.
It improves the depth, breadth and relevance of the search results, improves the flexibility of the system and user satisfaction, and ensures user data privacy.
Smart Images

Figure CN120407935A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of information retrieval, and particularly to a method, apparatus, device and medium for generating a retrieval report based on a local language model. Background Art
[0002] With the development of information technology, the scale of the Internet and local data is increasing day by day. How to efficiently and accurately find the knowledge required by users in a large amount of information has become a difficult problem. Traditional information retrieval methods mainly rely on keyword matching or simple text retrieval algorithms. Although these methods are effective in some specific scenarios, when faced with complex and multi-level queries, they often fail to provide complete, relevant, and high-quality results. At the same time, most existing retrieval systems rely on a single data source, such as only relying on a local knowledge base or only relying on an online search engine, and cannot provide sufficiently accurate or comprehensive answers. Summary of the Invention
[0003] In view of this, the purpose of the present invention is to provide a method, apparatus, device and medium for generating a retrieval report based on a local language model, aiming to significantly improve the quality, accuracy, comprehensiveness and relevance of the generated retrieval report by combining the reasoning ability of the local language model, the recursive search strategy, the dynamic filtering of relevance, and optional user interaction, and being able to handle complex, multi-level and diversified query requirements. At the same time, local processing is used to protect user data privacy, thereby enhancing the user experience. The specific solutions are as follows:
[0004] In a first aspect, the present application provides a method for generating a retrieval report based on a local language model, including:
[0005] Receiving query configuration information and a query statement sent by a client;
[0006] Constructing a first prompt word based on chain of thought, and using the local language model and the first prompt word to enhance the query intention of the query statement to determine an enhanced query;
[0007] Splitting the enhanced query based on a preset splitting rule to obtain a plurality of sub-queries, and determining a first embedding vector of the enhanced query and second embedding vectors of the respective sub-queries based on a text embedding model;
[0008] Calculating relevance scores based on the first embedding vector and the respective second embedding vectors, and screening the sub-queries according to the relevance scores to determine a sub-query screening result;
[0009] Based on the query configuration information and a preset recursive retrieval strategy, perform recursive web page retrieval on at least some of the sub-query screening results, so as to guide the exploration direction by calculating the relevance between the subsequently generated sub-queries and the enhanced query during the recursive web page retrieval process, and dynamically adjust the relevance threshold for screening subsequent sub-queries according to preset rules to determine the target recursive retrieval result;
[0010] Construct a target knowledge base based on the target recursive retrieval result, the local knowledge base, and the enhanced query, where the local knowledge base includes the processing capabilities for various formats of documents such as text, portable document format, and images;
[0011] Generate a target retrieval report corresponding to the query statement based on the local language model, the target knowledge base, the enhanced query, and the target recursive retrieval result.
[0012] Optionally, the constructing the first prompt word based on chain of thought and using the local language model and the first prompt word to enhance the query intent of the query statement to determine the enhanced query includes:
[0013] Combine a fixed prompt word containing a chain of thought instruction with the query statement to generate the first prompt word;
[0014] Parse the query statement through the local language model and the first prompt word to obtain a second query statement containing an inference process;
[0015] Process the second query statement using a preset parsing rule to extract the enhanced query.
[0016] Optionally, the screening the sub-queries according to the relevance scores to determine the sub-query screening result includes:
[0017] Sort the sub-queries based on the relevance scores;
[0018] Remove some sub-queries according to the sorting result and a preset screening rule to determine the sub-query screening result; the preset screening rule includes a rule for screening sub-queries with relevance scores lower than the target relevance threshold, and the target relevance threshold is a threshold that can be dynamically adjusted.
[0019] Optionally, before performing recursive web page retrieval on at least some of the sub-query screening results after determining the sub-query screening result, it further includes:
[0020] Based on the relevance scores corresponding to each sub-query, a Monte Carlo weighted random sampling method is used to select a preset number of sub-queries from the sub-query screening results, and the selected set of sub-queries is used as the target set of sub-queries for performing recursive web retrieval.
[0021] Optionally, after determining the sub-query screening results or the selected set of sub-queries, and before performing recursive web retrieval on at least some of the sub-queries in the sub-query screening results, it further includes:
[0022] Present at least some sub-query information to the client, where the information is selected from at least one of sub-query text, relevance score, and preliminary abstract;
[0023] Receive an interaction instruction from the client for the presented information, where the instruction is used to confirm retaining, removing a specific sub-query, or adjusting the retrieval priority of the sub-query;
[0024] Adjust the target set of sub-queries for performing recursive web retrieval or its retrieval order based on the interaction instruction.
[0025] Optionally, the performing recursive web retrieval on at least some of the sub-queries in the sub-query screening results based on the query configuration information and a preset recursive retrieval strategy includes:
[0026] When the query configuration information indicates that the network search function is enabled and the set target recursive depth is greater than or equal to 1, trigger recursive retrieval operations on the sub-queries in the target set of sub-queries in sequence;
[0027] In each recursive retrieval operation, obtain the web content related to the current sub-query and embed it as a third embedding vector, where the third embedding vector is used to construct the target recursive retrieval result.
[0028] Optionally, one recursive step in the recursive web retrieval includes:
[0029] Enhance the current sub-query using the language model to obtain the current enhanced sub-query;
[0030] Split the current enhanced sub-query based on the preset splitting rule to obtain candidate sub-queries at the next level;
[0031] Calculate the relevance score between the candidate sub-queries at the next level and the enhanced query or the current sub-query;
[0032] Based on a relevance threshold dynamically adjusted according to a preset rule, screen the candidate sub-queries at the next level to determine the sub-queries to be explored at the current level; the preset rule at least considers the current recursive depth or the number of sub-queries already generated in the current branch;
[0033] Perform web retrieval or further recursion on the selected subqueries to be explored;
[0034] Update the current recursion depth and determine whether the target recursion depth has been reached.
[0035] Optionally, constructing the target knowledge base based on the target recursive retrieval result, the local knowledge base, and the enhanced query includes:
[0036] Aggregate the web addresses, third embedding vectors, and recursive hierarchical structures in the target recursive retrieval result to form an initial network knowledge base;
[0037] When the query configuration information indicates that local documents are enabled, load the local documents, perform text extraction on documents in portable document format, perform optical character recognition on image files, or extract features using a multimodal embedding model to construct the local knowledge base;
[0038] Retrieve in the local knowledge base based on the enhanced query and merge the retrieval results with the initial network knowledge base to construct the target knowledge base.
[0039] Optionally, generating the target retrieval report corresponding to the query statement based on the local language model, the target knowledge base, the enhanced query, and the target recursive retrieval result includes:
[0040] Generate summary information based on the web retrieval results and local document retrieval results in the target knowledge base by the language model, and associate it with the directory structure nodes formed in the recursive retrieval process;
[0041] Generate a target retrieval report including text, links, and optional image references based on the language model, the preset report format, the enhanced query, the directory structure, and the summary and core entries in the target knowledge base;
[0042] Output the target retrieval report based on the preset output rules.
[0043] In a second aspect, the present application provides a retrieval report generation device based on a local language model, including:
[0044] A configured receiving module for receiving query configuration information and a query statement sent by a client;
[0045] A query enhancement module for constructing a first prompt word based on chain of thought and using the local language model and the first prompt word to enhance the query intent of the query statement to determine the enhanced query;
[0046] A vector determination module, configured to split the enhanced query based on a preset splitting rule to obtain multiple sub-queries, and determine a first embedding vector of the enhanced query and second embedding vectors of the sub-queries based on a text embedding model;
[0047] A sub-query screening module, configured to calculate correlation scores based on the first embedding vector and the second embedding vectors, and screen the sub-queries according to the correlation scores to determine a sub-query screening result;
[0048] A recursive retrieval module, configured to perform recursive web page retrieval on at least some of the sub-queries in the sub-query screening result based on the query configuration information and a preset recursive retrieval strategy, to guide the exploration direction by calculating the correlation between the subsequently generated sub-queries and the enhanced query during the recursive web page retrieval process, and dynamically adjust a correlation threshold for screening subsequent sub-queries according to a preset rule to determine a target recursive retrieval result;
[0049] A knowledge base construction module, configured to construct a target knowledge base based on the target recursive retrieval result, a local knowledge base, and the enhanced query, where the local knowledge base includes the processing capabilities for various format documents such as text, portable document format, images, etc.;
[0050] A retrieval report generation module, configured to generate a target retrieval report corresponding to the query statement based on the local language model, the target knowledge base, the enhanced query, and the target recursive retrieval result.
[0051] In a third aspect, the present application provides an electronic device, including:
[0052] A memory, configured to store a computer program;
[0053] A processor, configured to execute the computer program to implement the steps of the foregoing retrieval report generation method based on a local language model.
[0054] In a fourth aspect, the present application provides a computer-readable storage medium, configured to store a computer program, and when the computer program is executed by a processor, the steps of the foregoing retrieval report generation method based on a local language model are implemented.
[0055] As can be seen, in this application, the query configuration information and query statement sent by the client are received; the first prompt word is constructed based on chain of thought, and the local language model and the first prompt word are used to enhance the query intent of the query statement to determine the enhanced query; the enhanced query is split based on a preset splitting rule to obtain multiple sub-queries, and the first embedding vector of the enhanced query and the second embedding vectors of the respective sub-queries are determined based on the text embedding model; the correlation scores are calculated based on the first embedding vector and the second embedding vectors, and the sub-queries are screened according to the correlation scores to determine the sub-query screening result; based on the query configuration information and a preset recursive retrieval strategy, at least some of the sub-queries in the sub-query screening result are recursively retrieved from the web pages, so as to guide the exploration direction by calculating the correlation between the subsequently generated sub-queries and the enhanced query during the recursive web page retrieval process, and the correlation threshold for screening subsequent sub-queries is dynamically adjusted according to a preset rule to determine the target recursive retrieval result; a target knowledge base is constructed based on the target recursive retrieval result, the local knowledge base, and the enhanced query, where the local knowledge base includes the processing capabilities for various formats of documents such as text, portable document format, and images; a target retrieval report corresponding to the query statement is generated based on the local language model, the target knowledge base, the enhanced query, and the target recursive retrieval result. That is to say, this application finally generates a structured and comprehensive retrieval report by using the local language model through introducing query intent enhancement, correlation-based recursive sub-query screening, adaptive correlation threshold adjustment, multi-modal information processing, and constructing a combination of local and network knowledge bases. This method not only improves the depth, breadth, and relevance of the retrieval results, solves the deficiencies of traditional retrieval methods in dealing with complex queries, but also further enhances the flexibility, adaptability, and user satisfaction of the system through intelligent exploration strategies, user participation, and support for multiple data formats. At the same time, the emphasis on the local language model also provides an effective solution for users who are concerned about data privacy. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only the embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained according to the provided drawings without creative efforts.
[0057] Figure 1 It is a flowchart of a method for generating a retrieval report based on a local language model provided by this application;
[0058] Figure 2Schematic structural diagram of a retrieval report generation device provided by this application based on a local language model;
[0059] Figure 3 Structural diagram of an electronic device provided by this application. Detailed implementation manners
[0060] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0061] Facing complex and multi-level queries, traditional information retrieval methods are difficult to provide high-quality, relevant and comprehensive results. For this reason, this application provides a retrieval report generation solution based on a language model, which significantly improves the report quality and user experience by combining query enhancement, recursive exploration with relevance guidance, multi-modal knowledge base construction, and optional intelligent strategies for user interaction.
[0062] See Figure 1 As shown, an embodiment of the present invention discloses a retrieval report generation method based on a local language model, including:
[0063] Step S11: Receive query configuration information and a query statement sent by a client.
[0064] Specifically, before the execution of this embodiment, the local retrieval system first loads the preset query configuration information (reads parameters from the configuration file of a given template filled in by the user). The configuration information may include: whether to enable local document library search, whether to enable network search, the maximum depth of recursive search, the basic relevance threshold for filtering sub-queries, the selection of a text embedding model, the language model used for report generation, the number of local retrieval return results, whether to enable Monte Carlo sub-query sampling and the sampling number, whether to enable user interactive path planning, etc.
[0065] After the configuration is completed, the system receives the natural language query statement input by the client, for example: "Applications of quantum computing in medicine".
[0066] Step S12: Construct a first prompt word based on chain of thought, and use the local language model and the first prompt word to enhance the query intent of the query statement to determine the enhanced query.
[0067] Subsequently, the system constructs the first prompt based on chain of thought. This usually involves merging a pre-designed fixed prompt template containing guiding instructions with the query statement input by the user. For example, the fixed prompt template might contain instructions like: "You are a professional scientific research strategist. Please gradually analyze the deep meaning, potential related fields, and key aspects of the following user query, and then generate a more comprehensive, accurate, and enhanced query suitable for in-depth information retrieval. Please first show your analysis and thinking process, and finally output the final enhanced query on a separate line starting with 'Enhanced query:'. Combining this template with the user query 'Applications of quantum computing in medicine' forms the complete first prompt.
[0068] After that, the generated first prompt is sent to a specified local language model (e.g., the Qwen2.5 - 14B - Instruct model run through Ollama). The language model, according to the chain of thought instructions in the prompt, first conducts analysis and reasoning (this part of the output may be only for intermediate processes or debugging and is not necessarily part of the final result), and then generates an intention-enhanced query statement, that is, the second query statement.
[0069] Next, the system uses a preset parsing rule (e.g., regular expression: "Enhanced query: (.*)") to process the output of the language model (the second query statement) to filter out irrelevant content such as possible opening remarks and explanatory texts of the model, and accurately extract the final enhanced query. For the example query, the enhanced query might become: "Cutting-edge applications, technical challenges, and future development trends of quantum computing in medical imaging, drug development, genomics analysis, and personalized medicine".
[0070] Meanwhile, the system uses a configured text embedding model (such as the BGE - M3 model, Base General Embedding Model 3, a model for generating dense vector representations of text) to perform embedding calculation on this enhanced query to obtain its vector representation, denoted as the first embedding vector. This vector represents the user's core query intention and will be used for subsequent relevance comparison.
[0071] Step S13: Split the enhanced query based on a preset splitting rule to obtain multiple sub-queries, and determine the first embedding vector of the enhanced query and the second embedding vectors of each sub-query based on the text embedding model.
[0072] For more fine-grained exploration, the system splits the enhanced query based on preset splitting rules (e.g., splitting by punctuation marks and ensuring that the length of each sub-query does not exceed a preset value, such as 200 characters). For the example "Cutting-edge applications, technical challenges, and future development trends of quantum computing in medical imaging, drug development, genomics analysis, and personalized medicine", the following sub-queries may be split out:
[0073] Sub-query 1: "Cutting-edge applications of quantum computing in medical imaging";
[0074] Sub-query 2: "Cutting-edge applications of quantum computing in drug development";
[0075] Sub-query 3: "Cutting-edge applications of quantum computing in genomics analysis";
[0076] Sub-query 4: "Applications of quantum computing in personalized medicine";
[0077] Sub-query 5: "Technical challenges of quantum computing in the medical field";
[0078] Sub-query 6: "Future development trends of quantum computing in the medical field".
[0079] After that, the system uses a text embedding model to calculate the corresponding embedding vectors for each split sub-query, denoted as the second set of embedding vectors.
[0080] Step S14: Calculate the correlation scores based on the first embedding vector and each of the second embedding vectors, and screen the sub-queries according to the correlation scores to determine the sub-query screening result.
[0081] In this embodiment, the sub-queries are sorted based on the correlation scores; some sub-queries are removed according to the sorting result and preset screening rules to determine the sub-query screening result; the preset screening rules include rules for screening sub-queries with correlation scores lower than the target correlation threshold, and the target correlation threshold is a threshold that can be dynamically adjusted. Specifically, the correlation score between the second embedding vector of each sub-query and the first embedding vector of the enhanced query obtained in step S12 can be calculated by cosine similarity.
[0082] Based on the calculated correlation scores, the sub-queries are sorted. And according to the configured basic correlation threshold (and the target correlation threshold), the sub-queries with correlation scores lower than this threshold are removed. For example, if the correlation score is set to 0.5, and the correlation score of "Future development trends of quantum computing in the medical field" is only 0.45, then this sub-query may be initially screened out.
[0083] If Monte Carlo sampling is enabled in the query configuration information, after the above screening, the system will perform weighted random sampling. Based on the sub-queries retained after the above screening and their relevance scores, according to the configured sampling quantity (e.g., 3), with the relevance score as the weight, a specified number of sub-queries are randomly selected. For example, even if 5 sub-queries pass the threshold screening, if the sampling quantity is 3, the system will randomly select 3 of them according to their scores, and the sub-queries with higher scores have a higher probability of being selected. This is aimed at balancing the breadth (randomness introduces diversity) and depth (weight bias towards high relevance) of the search in the initial stage. The finally selected set of sub-queries will be used as the starting point for the next recursive search.
[0084] If user interaction is enabled in the query configuration information, after screening (or sampling), the system can present a list of sub-queries to be explored on the user interface, which may include sub-query text, relevance scores, or a preliminary summary quickly generated by the language model. The user can view this list and perform interactive operations: for example, check to confirm the branches they wish to explore in depth, uncheck the branches they are not interested in, or adjust the priority of certain branches (affecting the subsequent retrieval order). The system receives the user's feedback instructions and adjusts the final set of target sub-queries used to initiate the recursive retrieval and their processing order accordingly. This makes the search process more in line with the user's immediate judgment and needs.
[0085] After screening, and optional sampling and user interaction, the set of target sub-queries used to initiate the recursive web page retrieval is finally determined.
[0086] Step S15: Based on the query configuration information and the preset recursive retrieval strategy, perform recursive web page retrieval on at least some of the sub-query screening results, so as to guide the exploration direction by calculating the relevance between the subsequently generated sub-queries and the enhanced query during the recursive web page retrieval process, and dynamically adjust the relevance threshold for screening subsequent sub-queries according to the preset rules to determine the target recursive retrieval result.
[0087] When the query configuration information indicates that web search is enabled and the set maximum recursive depth is greater than or equal to 1, the system starts to sequentially trigger recursive retrieval operations on each sub-query in the set of target sub-queries (sorted by relevance score or in the order specified by the user).
[0088] Taking any sub-query in the set of target sub-queries as an example, such as "Cutting-edge applications of quantum computing in drug development" (assuming the current depth is 1):
[0089] 1. Current sub-query enhancement and splitting: Similar to steps S12 and S13, the system can optionally use the language model again to enhance the current sub-query "Frontier applications of quantum computing in drug R & D" (using chain-of-thought prompting words), and then split the enhanced result to generate candidate sub-queries at the next level (for example, "Mechanisms of quantum computing accelerating drug discovery", "Quantum computing simulating molecular interactions for drug design", etc.);
[0090] 2. Next-level sub-query relevance calculation: Calculate the embedding vectors of these next-level candidate sub-queries and calculate the relevance scores between them and the first embedding vector of the initially enhanced query ("Quantum computing in medical imaging, drug R & D..."). This step ensures that all explorations are centered around the user's initial core intention;
[0091] 3. Apply dynamically adjusted relevance thresholds: Instead of using a fixed relevance threshold, the system dynamically calculates the relevance threshold for filtering at the current level according to preset rules. For example, the rule could be: Current threshold = Base threshold - (Current depth * Decay factor), or when a branch generates too many sub-queries, temporarily increase the threshold for that branch. For example, at depth 1, the threshold might be 0.5; at depth 2, it might be adjusted to 0.45, allowing exploration of slightly more marginal but still potentially relevant concepts;
[0092] 4. Filter next-level sub-queries: Use the dynamically calculated current threshold to filter the next-level candidate sub-queries generated in step 2. Only sub-queries with a relevance score higher than the current dynamic threshold will be retained as the sub-queries actually to be explored at the current level;
[0093] 5. Web retrieval and content processing: For the filtered sub-queries to be explored (or if the previous steps 1-4 are not performed, directly for the current sub-query), the system calls a web search engine (such as Bing Search) to perform a search and obtain a list of relevant web addresses. Then, asynchronously download the content of these web pages. For the downloaded HTML (Hyper Text Mark-up Language) files, extract the plain text content after parsing;
[0094] 6. Content embedding and storage: Use a text embedding model to calculate the web page text content into embedding vectors (the third embedding vector). Organize the retrieved information (web address, local file path, text summary (or placeholder), third embedding vector, current depth, parent node information, etc.) and store it in a hierarchical data structure (for example, construct a table of contents (i.e., TOC, Table of Contents) tree, where each node represents an explored sub-query and its results);
[0095] 7. Recursive Judgment and Execution: Update the current recursive depth (e.g., the depth becomes 2), and determine whether the current depth is less than the configured maximum depth. If it is less, repeat steps 1-7 (or start directly from step 5, depending on the implementation strategy) for the sub-queries to be explored filtered out in step 4 for deeper recursive exploration. If the current depth has been reached, stop the downward recursion of this branch;
[0096] 8. Completion and Switching: When all relevant branches of an initial target sub-query have been explored (reaching the maximum depth or having no sub-queries meeting the relevance threshold), the system completes the recursive retrieval process for this initial sub-query. Then, process the next sub-query in the target sub-query set and repeat the above recursive process.
[0097] Until all sub-queries in the target sub-query set have completed their corresponding recursive retrieval processes, finally forming a target recursive retrieval result containing all relevant web page retrieval results, embedding vectors, and hierarchical structure information.
[0098] Step S16, construct a target knowledge base based on the target recursive retrieval result, the local knowledge base, and the enhanced query, where the local knowledge base includes the processing capabilities for various formats of documents such as text, Portable Document Format, and images.
[0099] The specific process of constructing the knowledge base is as follows:
[0100] 1) Aggregate network results: Organize the target recursive retrieval result obtained in step S15, and aggregate all retrieved web page addresses, the corresponding third embedding vectors, and the TOC hierarchical structure formed during the recursive process to constitute an initial network knowledge base;
[0101] 2) Load and process local documents: If the local document library is enabled in the configuration, the system traverses the files in the specified directory:
[0102] For.txt files, directly read the content;
[0103] For.pdf files, use the PyMuPDF library to try to extract the text content. If the extraction effect is not good, the file path can be recorded for subsequent processing (such as OCR or multi-modal models). Here, OCR stands for Optical Character Recognition, optical character recognition;
[0104] For image files such as.png,.jpg,.jpeg, use an OCR library (such as EasyOCR) to extract the text in the image, or, if a multi-modal embedding model is configured, directly calculate the embedding vector of the image;
[0105] 3) Build a local knowledge base: Build a local knowledge base from the processed local document content (text or feature vectors) and its metadata (file path, type, etc.);
[0106] 4) Integrate the knowledge base: Use the first embedded vector of the enhanced query to retrieve in the local knowledge base (e.g., return the most relevant local documents based on parameters). Merge these relevant local document results with the initial network knowledge base to finally build a target knowledge base that contains network information and local document information (which may contain multimodal content).
[0107] Step S17: Generate a target retrieval report corresponding to the query statement based on the local language model, the target knowledge base, the enhanced query, and the target recursive retrieval results.
[0108] The specific process of generating the report is as follows:
[0109] 1) Content summary: Use the local language model to generate summaries of the web page retrieval results (which can be fragments or full texts) associated with each level node (TOC node) in the target knowledge base and the retrieved local document content. Fill the generated summary information into the summary fields of the corresponding nodes in the TOC structure;
[0110] 2) Build RAG (Retrieval-Augmented Generation) prompts: Prepare a final prompt for generating the report. This prompt usually includes:
[0111] 1. The user's original query statement and the enhanced query;
[0112] 2. The table of contents string generated according to the TOC structure (including levels, sub-query texts, and the summaries just generated);
[0113] 3. The summaries of the most relevant documents retrieved from the local knowledge base ( number);
[0114] 4. The list of URLs of all relevant web pages aggregated as references;
[0115] 5. Clear instructions requiring the language model to generate a structured (e.g., in Markdown format), comprehensive, and citation-inclusive advanced research report based on all the above information. The report should have clear chapter divisions covering background, findings, challenges, future directions, etc.;
[0116] 3) Call the LLM (Large Language Model) to generate the report: Send the built RAG prompt to the specified local language model;
[0117] 4) Output and saving: Receive the final target retrieval report (in Markdown format) generated by the language model. According to the preset output rules (for example, save it to the directory), save the generated report file (*_output.md) and the possible intermediate data (such as downloaded web pages, TOC structure data, etc.) to the local. The report should include a clear table of contents, the content of each part, and the cited links.
[0118] In summary, in this embodiment, by combining the language model for query understanding and enhancement, using the embedding technology for relevance calculation, implementing relevance-guided recursive search with dynamic threshold adjustment, integrating network and local multimodal data sources, and introducing an optional intelligent sampling and user interaction mechanism, a high-quality, structured, and comprehensive retrieval report is finally generated, effectively solving the problem of complex information retrieval and providing a flexible, efficient, and privacy-conscious solution.
[0119] See Figure 2 As shown, the embodiment of the present application also correspondingly discloses a retrieval report generation device based on a local language model, including:
[0120] A configured receiving module 11, configured to receive query configuration information and a query statement sent by a client;
[0121] A query enhancement module 12, configured to construct a first prompt word based on chain of thought, and use the local language model and the first prompt word to enhance the query intent of the query statement to determine an enhanced query;
[0122] A vector determination module 13, configured to split the enhanced query based on a preset splitting rule to obtain multiple sub-queries, and determine a first embedding vector of the enhanced query and second embedding vectors of each of the sub-queries based on a text embedding model;
[0123] A sub-query screening module 14, configured to calculate relevance scores based on the first embedding vector and each of the second embedding vectors, and screen the sub-queries according to the relevance scores to determine a sub-query screening result;
[0124] A recursive retrieval module 15, configured to perform recursive web page retrieval on at least some of the sub-queries in the sub-query screening result based on the query configuration information and a preset recursive retrieval strategy, guide the exploration direction by calculating the relevance between the subsequently generated sub-queries and the enhanced query during the recursive web page retrieval process, and dynamically adjust the relevance threshold for screening subsequent sub-queries according to a preset rule to determine a target recursive retrieval result;
[0125] A knowledge base construction module 16, configured to construct a target knowledge base based on the target recursive retrieval result, the local knowledge base, and the enhanced query, where the local knowledge base includes the processing capabilities for various formats of documents such as text, portable document format, and images;
[0126] A retrieval report generation module 17, configured to generate a target retrieval report corresponding to the query statement based on the local language model, the target knowledge base, the enhanced query, and the target recursive retrieval result.
[0127] Among them, the more specific working processes of the above-mentioned various modules can refer to the corresponding content disclosed in the foregoing embodiments, and will not be elaborated herein.
[0128] As can be seen from the above, in this application, by introducing query intention enhancement, recursive sub-query screening based on relevance, adaptive relevance threshold adjustment, multi-modal information processing, and the construction of combining local and network knowledge bases, a structured and comprehensive retrieval report is finally generated using the local language model. This method not only improves the depth, breadth, and relevance of the retrieval results, solves the deficiencies of traditional retrieval methods in dealing with complex queries, but also further enhances the flexibility, adaptability, and user satisfaction of the system through intelligent exploration strategies, user participation, and support for multiple data formats. At the same time, the emphasis on the local language model also provides an effective solution for users who are concerned about data privacy.
[0129] Furthermore, the embodiment of the present application also discloses an electronic device, Figure 3 which is a structural diagram of an electronic device 20 shown according to an exemplary embodiment. The content in the figure should not be considered as any limitation to the scope of use of the present application.
[0130] Figure 3 This is a schematic structural diagram of an electronic device 20 provided by an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. Among them, the memory 22 is used to store a computer program, and the computer program is loaded and executed by the processor 21 to implement the relevant steps in the retrieval report generation method based on the local language model disclosed in any of the foregoing embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0131] In this embodiment, the power supply 23 is used to provide operating voltages for the various hardware devices on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and no specific limitation is imposed thereon here; the input / output interface 25 is used to obtain external input data or output data to the outside, and its specific interface type can be selected according to specific application requirements, and no specific limitation is made here.
[0132] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, a random access memory, a magnetic disk, an optical disc, etc., and the resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be transient storage or permanent storage.
[0133] Among them, the operating system 221 is used to manage and control the various hardware devices and the computer program 222 on the electronic device 20, and it can be Windows Server, Netware, Unix, Linux, etc. In addition to the computer program that can be used to complete the retrieval report generation method based on the local language model executed by the electronic device 20 disclosed in any of the foregoing embodiments, the computer program 222 can further include computer programs that can be used to complete other specific tasks.
[0134] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the retrieval report generation method based on the local language model disclosed above is implemented. For the specific steps of this method, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details will not be repeated here.
[0135] In this specification, the various embodiments are described in a progressive manner, and the key point of each embodiment is to illustrate the differences from other embodiments. The same or similar parts among the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method part.
[0136] Those skilled in the art can further realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed in this article can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of the examples have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0137] The steps of the methods or algorithms described in combination with the embodiments disclosed in this specification may be implemented directly by hardware, by software modules executed by a processor, or by a combination of both. The software modules may be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium well-known in the art.
[0138] Finally, it should also be noted that in this specification, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variation thereof is intended to cover a non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the phrase "comprising a..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element.
[0139] The technical solutions provided in this application have been introduced in detail above. Specific examples are used in this specification to illustrate the principle and implementation manner of this application. The description of the above embodiments is only used to help understand the method and its core idea of this application; at the same time, for those of ordinary skill in the art, according to the idea of this application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to this application.
Claims
1. A method for generating a retrieval report based on a local language model, characterized in that, It includes: Receiving query configuration information and a query statement sent by a client; Constructing a first prompt based on chain of thought, and using a local language model and the first prompt to enhance the query intent of the query statement to determine an enhanced query; Splitting the enhanced query based on a preset splitting rule to obtain multiple sub-queries, and determining a first embedding vector of the enhanced query and second embedding vectors of the respective sub-queries based on a text embedding model; Calculating relevance scores based on the first embedding vector and the respective second embedding vectors, and screening the sub-queries according to the relevance scores to determine a sub-query screening result; Based on the query configuration information and a preset recursive retrieval strategy, recursively retrieving web pages for at least some of the sub-queries in the sub-query screening result, guiding the exploration direction by calculating the relevance between the subsequently generated sub-queries and the enhanced query during the recursive web page retrieval process, and dynamically adjusting a relevance threshold for screening subsequent sub-queries according to a preset rule to determine a target recursive retrieval result; Constructing a target knowledge base based on the target recursive retrieval result, a local knowledge base, and the enhanced query, where the local knowledge base includes the processing capabilities for various format documents such as text, portable document format, images, etc.; Generating a target retrieval report corresponding to the query statement based on the local language model, the target knowledge base, the enhanced query, and the target recursive retrieval result.
2. The retrieval report generation method based on a local language model according to claim 1, wherein The constructing a first prompt based on chain of thought, and using a local language model and the first prompt to enhance the query intent of the query statement to determine an enhanced query includes: Combining a fixed prompt containing a chain of thought instruction with the query statement to generate the first prompt; Parsing the query statement through the local language model and the first prompt to obtain a second query statement containing an inference process; Processing the second query statement using a preset parsing rule to extract the enhanced query.
3. The retrieval report generation method based on a local language model according to claim 1, wherein The screening the sub-queries according to the relevance scores to determine a sub-query screening result includes: Sorting the sub-queries based on the relevance scores; Removing some sub-queries according to the sorting result and a preset screening rule to determine the sub-query screening result; the preset screening rule includes a rule for screening sub-queries with relevance scores lower than a target relevance threshold, and the target relevance threshold is a threshold that can be dynamically adjusted.
4. The retrieval report generation method based on a local language model according to claim 3, wherein Before recursively retrieving web pages for at least some of the sub-queries in the sub-query screening result after determining the sub-query screening result, it further includes: Based on the relevance scores corresponding to the respective sub-queries, using the Monte Carlo weighted random sampling method to select a preset number of sub-queries from the sub-query screening result, and using the selected set of sub-queries as a target set of sub-queries for performing recursive web page retrieval.
5. The retrieval report generation method based on a local language model according to claim 3 or 4, wherein Before recursively retrieving web pages for at least some of the sub-queries in the sub-query screening result after determining the sub-query screening result or the selected set of sub-queries, it further includes: Present at least part of the sub-query information to the client, where the information is selected from at least one of sub-query text, relevance score, and preliminary summary; Receive an interaction instruction from the client for the presented information, where the instruction is used to confirm retention, removal of a specific sub-query, or adjustment of the retrieval priority of the sub-query; Adjust the set of target sub-queries for performing recursive web retrieval or their retrieval order based on the interaction instruction.
6. The retrieval report generation method based on a local language model according to claim 1, wherein The recursive web retrieval of at least part of the sub-query filtering results based on the query configuration information and a preset recursive retrieval strategy includes: When the query configuration information indicates that the network search function is enabled and the set target recursive depth is greater than or equal to 1, trigger recursive retrieval operations for the sub-queries in the set of target sub-queries in sequence; In each recursive retrieval operation, obtain the web content related to the current sub-query and embed it as a third embedding vector, where the third embedding vector is used to construct the target recursive retrieval result.
7. The retrieval report generation method based on a local language model according to claim 1, wherein One recursive step in the recursive web retrieval includes: Enhance the current sub-query using the language model to obtain the current enhanced sub-query; Split the current enhanced sub-query based on the preset splitting rule to obtain candidate sub-queries at the next level; Calculate the relevance score between the candidate sub-queries at the next level and the enhanced query or the current sub-query; Filter the candidate sub-queries at the next level based on a relevance threshold dynamically adjusted according to a preset rule to determine the sub-queries to be explored at the current level; the preset rule at least considers the current recursive depth or the number of sub-queries already generated in the current branch; Perform web retrieval or further recursion on the filtered sub-queries to be explored; Update the current recursive depth and determine whether the target recursive depth has been reached.
8. The retrieval report generation method based on a local language model according to claim 1, wherein The construction of the target knowledge base based on the target recursive retrieval result, the local knowledge base, and the enhanced query includes: Aggregate the web addresses, third embedding vectors, and recursive hierarchical structures in the target recursive retrieval result to form an initial network knowledge base; When the query configuration information indicates that local documents are enabled, load local documents, perform text extraction on documents in portable document format, perform optical character recognition on image files, or extract features using a multimodal embedding model to construct the local knowledge base; Retrieve in the local knowledge base based on the enhanced query and merge the retrieval result with the initial network knowledge base to construct the target knowledge base.
9. The retrieval report generation method based on a local language model according to claim 1, wherein The generation of a target retrieval report corresponding to the query statement based on the local language model, the target knowledge base, the enhanced query, and the target recursive retrieval result includes: Generate summary information based on the language model for the web retrieval results and local document retrieval results in the target knowledge base and associate it with the directory structure nodes formed during the recursive retrieval process; Generate a target retrieval report including text, links, and optional image references based on the language model, a preset report format, the enhanced query, the directory structure, and the summary and core entries in the target knowledge base; Output the target retrieval report based on a preset output rule.
10. A retrieval report generation device based on a local language model, characterized in that, Includes: Configure a receiving module for receiving query configuration information and query statements sent by a client; A query enhancement module for constructing a first prompt word based on chain of thought and using a local language model and the first prompt word to enhance the query intent of the query statement to determine an enhanced query; A vector determination module for splitting the enhanced query based on a preset splitting rule to obtain multiple sub-queries, and determining a first embedding vector of the enhanced query and second embedding vectors of the sub-queries based on a text embedding model; A sub-query screening module for calculating correlation scores based on the first embedding vector and the second embedding vectors of the sub-queries, and screening the sub-queries according to the correlation scores to determine a sub-query screening result; A recursive retrieval module for recursively retrieving web pages for at least some of the sub-queries in the sub-query screening result based on the query configuration information and a preset recursive retrieval strategy, guiding the exploration direction by calculating the correlation between the subsequently generated sub-queries and the enhanced query during the recursive web page retrieval process, and dynamically adjusting the correlation threshold for screening subsequent sub-queries according to a preset rule to determine a target recursive retrieval result; A knowledge base construction module for constructing a target knowledge base based on the target recursive retrieval result, a local knowledge base, and the enhanced query, where the local knowledge base includes the processing capabilities for various format documents such as text, portable document format, images, etc.; A retrieval report generation module for generating a target retrieval report corresponding to the query statement based on the local language model, the target knowledge base, the enhanced query, and the target recursive retrieval result.
11. An electronic device, characterized in that, Comprising: A memory for storing a computer program; A processor for executing the computer program to implement the retrieval report generation method based on a local language model according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that, For storing a computer program, the computer program, when executed by a processor, implements the retrieval report generation method based on a local language model according to any one of claims 1 to 9.
Citation Information
Cited By
End-side RAG implementation method and system based on fusion architecture
CN121029322A