A knowledge base question answering method and system based on large language model intelligent agent

By building a large language model intelligent agent, the problem of insufficient language model knowledge in the intelligent legal question-answering system is solved, efficient and accurate legal question-answering is achieved, and the retrieval cost is reduced.

CN120492598BActive Publication Date: 2025-09-19CENT SOUTH UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510983688.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-17
Publication Date
2025-09-19
Estimated Expiration
2045-07-17

AI Technical Summary

Technical Problem

The existing intelligent legal question-answering system has low question-answering efficiency and poor result accuracy due to the insufficient legal field knowledge of the language model. In addition, the existing retrieval enhancement methods are costly and difficult to maintain.

Method used

Build a large language model intelligent agent, including a configuration module, a planning module, an action module, a combined query tool and a memory module. Use the combined query tool to retrieve relevant legal provisions and cases from the structured database, and use the memory module to filter and embed the most relevant content to generate answers.

Benefits of technology

It improves the efficiency and accuracy of legal Q&A, reduces retrieval costs, and ensures the timeliness and relevance of answers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120492598B_ABST
    Figure CN120492598B_ABST
Patent Text Reader

Abstract

The present invention relates to the technical field of intelligent legal question-answering, and discloses a knowledge base question-answering method and system based on a large language model intelligent agent. The method plans and decomposes legal question-answering tasks through the large language model intelligent agent; extracts question keywords and calls a combined query tool to retrieve relevant legal provisions, cases and other documents from a database; embeds question-related content in the document into the large language model intelligent agent to assist it in generating answers; the method utilizes thought chain prompts to rationally plan the intelligent agent's workflow to stimulate the capabilities of the large model, and solves the problems of low efficiency and high cost of vector database retrieval by directly retrieving question-related documents from a structured database; embeds the content most relevant to the question into the intelligent agent through a memory module, solving the problem of low accuracy of legal question-answering results due to insufficient legal field knowledge of the large model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of intelligent legal question-answering technology, and in particular to a knowledge base question-answering method and system based on a large language model intelligent agent. Background Art

[0002] With the continuous progress of society and the widespread adoption of the rule of law, public demand for legal advice is rapidly growing. However, due to the highly specialized nature of the legal field, only experienced lawyers can provide accurate legal advice. However, the number of experienced lawyers is relatively limited, while the demand for legal advice is growing. This increasingly prominent imbalance between supply and demand further impacts the efficiency and reach of consulting services. With the continuous advancement of deep learning technology, intelligent legal advice based on large language models has become possible, promising significant improvements in the efficiency of legal services. However, existing large language models are mostly pre-trained on general corpora, and their knowledge of legal expertise is relatively limited. Direct application in legal question-and-answer scenarios often fails to achieve ideal results. To improve the model's performance in the legal field, researchers have experimented with fine-tuning the model using specialized corpora such as laws, regulations, and judicial cases, thereby enhancing its legal question-and-answer capabilities. While this approach has improved the model's professionalism to a certain extent, it also has limitations, such as high update costs, limited flexibility, and difficulty in responding to changes in legal provisions. Furthermore, this approach places high demands on the quality, coverage, and annotation accuracy of the training data, limiting its scalability in practical applications.

[0003] Retrieval enhancement, as an emerging solution, offers a new approach to solving the problem of question answering in large-scale domains. By deeply integrating large language models with external knowledge bases, it can retrieve relevant legal texts, cases, and other documents in real time when answering user questions, and generate precise content based on this information, significantly improving the accuracy and timeliness of answers. However, current retrieval enhancement methods still face certain limitations in practical applications. First, most real-world legal data is stored in structured databases in the form of structured text. Large-scale conversion to vectorized storage is not only costly, but also extremely complex to update and maintain. Second, directly placing all retrieved documents into the context of a large model will cause irrelevant content to affect the large model, thereby reducing the accuracy of the answer results. It can be seen that current intelligent legal question answering suffers from low question answering efficiency and poor result accuracy due to insufficient domain knowledge of the language model. Summary of the Invention

[0004] The present invention provides a knowledge base question-answering method and system based on a large language model intelligent agent to solve the problems of low question-answering efficiency and poor result accuracy in existing intelligent legal question-answering due to insufficient domain knowledge of the language model.

[0005] In order to achieve the above object, the present invention is implemented through the following technical solutions:

[0006] In a first aspect, the present invention provides a knowledge base question answering method based on a large language model agent, comprising:

[0007] S1: Build a target module for a large language model agent, which includes a configuration module, a planning module, an action module, a combined query tool, and a memory module;

[0008] S2: Generate a large language model agent according to the configuration module, the planning module, the action module, the combined query tool, and the memory module, and input the user question into the large language model agent;

[0009] S3: The large language model agent determines the prompt text and tool description corresponding to the user question based on the configuration module;

[0010] S4: The large language model agent determines a thought chain prompt corresponding to the user question based on the planning module;

[0011] S5: The large language model agent calls the combined query tool based on the action module according to the prompt text, tool description and thought chain prompt to perform a query and obtain the query result;

[0012] S6: The large language model agent performs document screening and knowledge embedding on the query results based on the memory module to obtain a final answer.

[0013] In the second aspect, the present application provides a knowledge base question-answering system based on a large language model intelligent agent, comprising a memory, a processor, and a computer program stored on the memory and runnable on the processor, wherein the processor implements the steps of the method described in the first aspect when executing the computer program.

[0014] Beneficial effects:

[0015] The knowledge base question-answering method based on a large language model intelligent agent provided by the present invention plans and decomposes legal question-answering tasks through the large language model intelligent agent; extracts question keywords and calls a combined query tool to retrieve relevant legal provisions, cases and other documents from the database; embeds the content related to the question in the document into the large language model intelligent agent to assist it in generating answers; the method uses thought chain prompts to rationally plan the intelligent agent's workflow to stimulate the capabilities of the large model, and solves the problems of low efficiency and high cost of vector database retrieval by directly retrieving question-related documents from a structured database; embeds the content most relevant to the question into the intelligent agent through a memory module, solving the problem of low accuracy of legal question-answering results caused by insufficient legal field knowledge of the large model.

[0016] In a further solution, a combined retrieval tool is constructed to combine query keywords, and SQL statements are constructed by traversing the combination to query document content, thereby ensuring the effectiveness of the tool while enhancing the relevance of the queried documents to the questions.

[0017] In a further solution, the queried document content is divided into blocks. For each content block, a cross encoder is constructed, and the language model is used to concatenate the question and content as the input of the encoder to form a vector representation. The relevance score is obtained through the classifier, and finally the content block most relevant to the question is selected, thereby solving the problem of irrelevant content in the document affecting the large model and resulting in low accuracy of legal question answering.

[0018] In a further solution, for the content blocks that are most relevant to the question, a cross-encoder is constructed to fuse the reference content with the model context, so that the model can make a final and more accurate answer based on the reference content. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 This is one of the flow charts of a knowledge base question answering method based on a large language model agent according to a preferred embodiment of the present invention;

[0020] Figure 2 This is the second flowchart of a knowledge base question answering method based on a large language model agent according to a preferred embodiment of the present invention;

[0021] Figure 3 This is an example diagram of a legal question and answer provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0022] The following is a clear and complete description of the technical solutions of the present invention. It should be understood that the embodiments described are only a portion of the embodiments of the present invention, not all of them. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of the present invention without inventive effort are intended to fall within the scope of protection of the present invention.

[0023] Unless otherwise defined, the technical or scientific terms used in the present invention shall have the usual meanings understood by persons of ordinary skill in the field to which the present invention belongs. The words "first", "second" and similar terms used in the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, words such as "one" or "a" do not indicate a quantity limitation, but rather indicate the existence of at least one. Words such as "connected" or "connected" are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the object being described changes, the relative positional relationship also changes accordingly.

[0024] It should be understood that current intelligent legal question-answering suffers from low question-answering efficiency and poor accuracy due to insufficient domain knowledge of language models. Based on this, this application provides a knowledge-based question-answering method based on a large language model agent. It is worth noting that the knowledge-based question-answering method based on a large language model agent provided in this application can also be applied to similar question-asking scenarios, not just legal question-asking scenarios.

[0025] See Figure 1 , this application provides a knowledge base question answering method based on a large language model agent, including:

[0026] S1: Construct a target module of a large language model agent, wherein the target module includes a configuration module, a planning module, an action module, a combination query tool, and a memory module.

[0027] S2: Generate a large language model agent according to the configuration module, the planning module, the action module, the combined query tool and the memory module, and input the user question into the large language model agent.

[0028] S3: The large language model agent determines the prompt text and tool description corresponding to the user question based on the configuration module.

[0029] S4: The large language model agent determines the thought chain prompt corresponding to the user question based on the planning module.

[0030] S5: The large language model agent calls the combined query tool based on the action module according to the prompt text, tool description and thought chain prompt to perform a query and obtain the query result.

[0031] S6: The large language model agent performs document screening and knowledge embedding on the query results based on the memory module to obtain a final answer.

[0032] In this implementation, the agent is a composite framework that integrates large language models, external tools, and external knowledge, with autonomous planning, execution, and memory capabilities. Large language models include, but are not limited to, LLaMA3, Qwen2.5, DeepSeek, and others with over 1 billion versions.

[0033] The above-mentioned knowledge base question-answering method based on a large language model agent plans and decomposes legal question-answering tasks through a large language model agent; extracts question keywords and calls a combined query tool to retrieve relevant legal provisions, cases and other documents from the database; embeds the content related to the question in the document into the large language model agent to assist it in generating answers; this method uses thought chain prompts to rationally plan the agent's workflow to stimulate the capabilities of the large model, and solves the problems of low efficiency and high cost of vector database retrieval by directly retrieving question-related documents from a structured database; embeds the content most relevant to the question into the agent through a memory module, solving the problem of low accuracy of legal question-answering results due to insufficient legal field knowledge of the large model.

[0034] Below, as Figure 2 As shown in the figure, a complete example is used to introduce the steps of the above-mentioned knowledge base question answering method based on a large language model agent in detail:

[0035] 1: Building the configuration module of the intelligent agent

[0036] This example targets intelligent legal question-answering scenarios. The agent is a complex framework that integrates a large language model, external tools, and external knowledge, and possesses autonomous planning, execution, and memory capabilities. Because large language models are typically trained on multiple tasks, the agent requires specialized configuration to ensure it understands its current environment, including the task context, the agent's responsibilities, and its skills. To configure the agent, this example builds an agent configuration module prompt for the legal question-answering domain, which primarily includes prompt text and tool descriptions.

[0037] The prompt text in this example is a phrase or keyword that guides the large language model to clarify the current environment, including task background, responsibilities, and skills possessed.

[0038] In one example, the configuration prompt text in this instance is described as follows:

[0039] ="Role: You are a legal question-answering agent, designed to provide high-quality, accurate legal advice.\nTask Objective: Clearly understand the legal intent of the user's question and provide authoritative, accurate legal advice or information. You need to provide answers based on specific regulations.\nSkills: You can use the following tools to assist in completing the task:"

[0040] Tool description refers to the description text of the tool currently available to the agent, including the tool name, tool function description, parameter description, and return value, etc. For example, the tool description text of the relevant legal provisions and cases in the database can be searched using keywords. Tool Name: \n Function description: Retrieve relevant legal provisions and cases from the database based on the input keyword list\n Parameter description: : Keyword string array, used to match legal provisions and case information. \n Return value: : A list of matched legal provisions and case documents, including relevant legal provisions and case documents.

[0041] In one example, the configuration module prompts for this instance are: =“ \n ”.

[0042] 2. Constructing the Planning Module of the Legal Question Answering Agent

[0043] This application is aimed at intelligent legal question-answering scenarios. Since the intelligent agent needs to analyze the task during the answering process and complete reasoning in combination with the knowledge base, it places higher requirements on the standardization and controllability of the answering process. Therefore, it is necessary to design a planning module for the intelligent agent so that the intelligent agent can reason according to a predefined plan. This embodiment is based on the thinking chain technology to construct a thinking chain prompt to guide the intelligent agent to reasonably decompose and orderly plan the legal question-answering task, thereby ensuring the coherence and efficiency of the overall task process. The thinking chain prompt mainly includes two parts: thinking chain instructions and a few sample examples.

[0044] The thought chain instruction is a directive phrase used to guide the large model to complete reasoning tasks in a step-by-step thinking and analytical manner. In this example, the text description of the thought chain instruction is as follows: ="Please follow the steps below to reason and answer the given legal question.\n 1. Clarify the legal topic in the question.\n 2. Extract and refine the keywords in the question.\n 3. Use the keyword search tool to obtain relevant legal provisions and case documents.\n 4. Combine the relevant legal provisions and case documents to arrive at the correct answer.\n 5. Please refer to the following example to answer:"

[0045] It's worth explaining that the few-shot examples are used to demonstrate specific approaches to the problem to the larger model. They serve as high-quality question-answering examples that guide the model in task execution. In thought chaining prompts, the few-shot examples typically consist of three parts: the question, the thought chain analysis process, and the final answer. The description of the few-shot examples in this example is as follows: Question: Is it legal for a landlord to withhold a deposit if a tenant terminates the lease early? Analysis process: 1. The legal topic is 'lease contract disputes'; 2. Extract keywords: 'terminate early', 'deposit', 'is it legal'; 3. Invoke the tool Check relevant legal provisions.\n 4. According to relevant legal provisions, if a tenant violates the contract and terminates the lease prematurely without authorization, the landlord has the right to withhold partial or full refund of the deposit in accordance with the contract. If the contract does not explicitly stipulate this, a landlord's unilateral refusal to refund the deposit is suspected of being illegal, and the tenant may seek legal redress.\n Answer: If the contract explicitly stipulates that the deposit will not be refunded, it may be legal. Otherwise, the landlord's refusal to refund the deposit has no legal basis.

[0046] In this example, the thought chain prompts for the constructed planning module are: . =“ \n ”.

[0047] 3. Constructing the action module of the legal question-answering agent

[0048] Because large language models only have generation capabilities and lack the ability to call tool functions, it is necessary to build an agent action module to convert the agent's generated plans into specific actions. The action module consists of two parts: action prompts and extraction and execution.

[0049] Action prompts are tool call statements that guide the large model to output standardized outputs to ensure that the generated content is executable. The action module prompts in this example are described as follows: = "When you need to call a tool, you need to provide the tool calling information in the following format:\n Action: Tool name\n Action Input: {"Parameter name": "Parameter value",...}".

[0050] It is worth noting that extraction execution is achieved by extracting the output of the large model, obtaining the specific tool name and parameter name, and calling the corresponding tool function to obtain the specific execution result.

[0051] Specifically, we first use the rule matching method to obtain the tool name and parameters from the large model output, and the regular expression of the rule matching ,in Indicates matching of fixed string "Action:"; Indicates matching zero or more whitespace characters, including spaces, tabs, newlines, etc. is the first capturing group, where Indicates matching one or more letters, numbers or underscores. This capture group is used to extract tool function names. Indicates matching the fixed string "Action Input:"; is the second capturing group, matching the content enclosed by a pair of curly braces. This is a non-greedy match that matches any character (except newline characters) and matches as few parameters as possible to extract the function. This capture group is used to extract the tool function parameters. Then, based on the tool function name and parameters, the corresponding function in the tool function library is called to obtain the result as the output of the action module.

[0052] 4. Build a combined query tool

[0053] This example builds a combined query tool for the agent to call, enabling the agent to query and retrieve documents related to the problem from the database through keywords.

[0054] In this embodiment, the tool name of the combined query tool is designed to be , which accepts an array parameter containing query keywords The return value is a string array containing the retrieved legal provisions and case documents .

[0055] In order to obtain the most relevant document content, this application provides a combined query method. The specific steps are as follows:

[0056] First, for the input parameters ,in To query the number of keywords, construct the fuzzy matching query statement as follows:

[0057]

[0058]

[0059]

[0060] If the query result is not empty, the result Returns, where For the query documents, is the total number of documents retrieved. Since even the most relevant documents may not cover all keywords, the query results may be empty. In this case, it is necessary to construct a new keyword combination and re-query. Specifically, for the input keyword set keywords, iterate through all subset combinations of n-1 keywords, construct and execute the query in sequence. If no results are found, iterate through subset combinations of n-2 keywords and continue searching. This process continues, gradually reducing the number of keywords and traversing all possible combinations until a document that meets the conditions is retrieved or the number of keywords is reduced to 0.

[0061] 5. Constructing the Memory Module of the Legal Question-Answering Agent

[0062] This application is aimed at legal intelligent question-answering scenarios. Since the large language model has certain deficiencies in legal knowledge, it is necessary to embed the retrieved relevant legal provisions and cases into the model to assist in answering. However, the number of documents retrieved from the database is usually large, and some of the content is irrelevant to the final answer, resulting in information redundancy. To this end, this implementation example further screens the retrieval results by constructing an intelligent agent's memory module, extracts the most relevant information fragments from them, and embeds them into the large model, thereby improving the accuracy and generation quality of question-answering. The memory module consists of two parts: document screening and knowledge embedding.

[0063] It should be understood that document screening is to filter out the most relevant parts of the legal provisions and case documents retrieved from the database and filter out irrelevant redundant parts, thereby reducing the impact of redundant information on the model's answer. Specifically, first, the search results Each document in characters into blocks to get text blocks ,in is the total number of text blocks. Then, two independent BERT encoders are used to encode the user questions into and text blocks Encode and map the two into a dense vector space of the same dimension to obtain the problem vector representation And the text block vector representation Then calculate the dot product similarity between each text block vector representation and the question vector representation ,in It is Then all text blocks are sorted according to their similarity scores, and the top text blocks with the highest scores are selected. text blocks Embedded in a large model.

[0064] It is worth explaining that knowledge is embedded in the text block to be selected Embedded into the large model, so that the large model can obtain relevant knowledge and thus complete the final answer generation based on the knowledge. Since directly adding text to the prompt may exceed the maximum context length of the model, this implementation example uses the cross-attention mechanism to embed the text block into the large language model. Specifically, let the embedding vector of the current language model context after being encoded by the model initial encoder be represented as ,in The language model context participles The embedding vector of The number of word segmentations in the model context. The embedding vector of the reference text block after passing through the encoder is represented as ,in For the Reference text blocks The embedding vector of the model context is first used to calculate the query vector representation , is the dimension of the embedding vector, is the number of model context segmentations, ,in , is a linear transformation parameter matrix that can be trained. Then the key vector representation is calculated using the embedding vector of the reference text block. , is the number of reference text blocks that satisfy: ,in , All are trainable linear transformation parameter matrices. Then the following formula is used to calculate the cross attention weight matrix between the model context and the reference text :

[0065] ;

[0066] in, is the dimension of the embedding vector. is the cross attention weight matrix No. Rank The elements of the column represent the first participles For the first Reference text blocks Then, the value vector is calculated using the embedding vector of the reference text block ,in is the linear transformation parameter matrix that can be trained. Finally, the attention weight matrix is ​​used With value vector Compute fusion output representation ,This representation integrates the attention information of the current model context on the knowledge block, and the subsequent model can get the final answer based on this information.

[0067] Finally, the agent is used to process the user's question input and obtain the answer.

[0068] In one example, the constructed agent is loaded and the agent parameters are set according to the requirements, such as setting the length of each reference text block in the memory module. 512, the number of text blocks in the embedding model The value is 5. When a user enters a legal question, the final answer is obtained by combining the various modules created.

[0069] See Figure 3 , we introduce the above-mentioned knowledge base question answering method based on a large language model agent with a specific example:

[0070] The user asked: "I am a master's student and I want to transfer my household registration to Guangzhou. What are the conditions and procedures?"

[0071] The agent extracts keywords: "Master's degree", "Guangzhou", "household registration transfer", "household registration conditions", and "household registration process".

[0072] The agent constructed by this application recalls relevant articles based on keywords: "Article 4 of the Guangzhou Regulations on the Administration of Household Registration Transfer": Household registration transfer in our city is divided into three categories: talent introduction, point-based household registration, and policy-based household registration. The conditions for household registration are clarified in the Guangzhou Measures for the Administration of Talent Introduction, the Guangzhou Measures for the Administration of Point-based Household Registration, and the Guangzhou Measures for the Administration of Policy-based Household Registration. Article 5 of the Guangzhou Regulations on the Administration of Household Registration Transfer: Those who are employed or start a business in this city and meet one of the following conditions may apply for household registration as introduced talents after review, and their spouses and minor children may move with them: (1) High-level and highly skilled talents recognized or verified by our city, the age requirements vary according to different categories; (2) Persons with a doctoral degree, or a doctoral degree, or a senior professional title, must be under 50 years old; (3) Persons with a master's degree, or a master's degree, must be under 45 years old; (4) Persons with a full-time undergraduate degree from a domestic ordinary university and a bachelor's degree, or a bachelor's degree from abroad, or an intermediate professional title, must be under 40 years old; (5) Technical and skilled talents engaged in relevant occupations included in the city's professional catalog of introduced technical and skilled talents, according to their professional status, must meet the corresponding conditions such as age and time of participating in social insurance in this city (6) Other talents urgently needed for the economic and social development of Guangzhou. Article 10 of the "Regulations on the Administration of Household Registration Transfer in Guangzhou": Persons who meet the requirements and intend to transfer to the city may apply for household registration to the review department by their units or individuals in accordance with the corresponding household registration management methods and with relevant supporting documents. The review department shall strictly review the relevant supporting documents. After approval, the public security organs shall handle the household registration procedures. For those who do not meet the conditions, the applicant unit or applicant shall be notified in writing in a timely manner. "Related case: "Student Li, 26 years old, has a master's degree and is currently employed in an Internet company in Guangzhou. He meets the conditions for the introduction of talents into the city in Article 5, Item 3 of the "Regulations on the Administration of Household Registration Transfer in Guangzhou", namely "having a master's degree, being under 45 years old, and being employed or starting a business in the city." He successfully completed the household registration transfer procedures after submitting the application materials and passing the review."

[0073] The agent generated an answer based on the recalled article and case: "According to the 'Regulations on the Management of Household Registration in Guangzhou,' people with a master's degree, under the age of 45, and employed or starting a business in Guangzhou can apply for household registration as an introduced talent. Applicants can submit materials in accordance with the 'Measures for the Management of Household Registration for Introduced Talents in Guangzhou' and apply to the review department. After approval, the public security organs will handle the household registration procedures in accordance with the law."

[0074] This application also provides a knowledge base question-answering system based on a large language model agent, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-described method when executing the computer program. This knowledge base question-answering system based on a large language model agent can implement various embodiments of the above-described method and achieve the same beneficial effects, which are not described in detail here.

[0075] The above describes in detail the preferred embodiments of the present invention. It should be understood that those skilled in the art can make numerous modifications and variations based on the concepts of the present invention without inventive effort. Therefore, any technical solutions that can be derived by those skilled in the art through logical analysis, reasoning, or limited experimentation based on the concepts of the present invention and the prior art should be within the scope of protection defined by the claims.

Claims

1. A knowledge base question answering method based on a large language model agent, characterized in that: include: S1: Build a target module for a large language model agent, which includes a configuration module, a planning module, an action module, a combined query tool, and a memory module; S2: Generate a large language model agent according to the configuration module, the planning module, the action module, the combined query tool, and the memory module, and input the user question into the large language model agent; S3: The large language model agent determines a prompt text and a tool description corresponding to the user question based on the configuration module; wherein the prompt text includes task background, the agent's responsibilities and the skills it possesses; S4: The large language model agent determines a thought chain prompt corresponding to the user question based on the planning module; S5: The large language model agent calls the combined query tool based on the action module according to the prompt text, tool description and thought chain prompt to perform a query and obtain the query result; S6: The large language model agent performs document screening and knowledge embedding on the query results based on the memory module to obtain a final answer.

2. The knowledge base question answering method based on a large language model agent according to claim 1, characterized in that: The prompt text and tool description corresponding to the user question determined in S3 include: Determine roles and mission objectives; Determine the tool name, tool function, tool parameters, and return value.

3. The knowledge base question answering method based on a large language model agent according to claim 1, characterized in that: Determining the thought chain prompt corresponding to the user question in S4 includes: Determine a thought chain instruction corresponding to the user question, wherein the thought chain instruction is an instruction phrase used to guide the large model to complete the reasoning task in a step-by-step thinking and analysis manner; Determine a sample example corresponding to the user question, wherein the sample example is a question-and-answer example; Connect the thought chain instructions and sample examples to obtain thought chain prompts.

4. The knowledge base question answering method based on a large language model agent according to claim 1, characterized in that: The S5 includes: The large language model agent generates a plan based on the prompt text, tool description, and thought chain prompt; The action module parses the plan and determines the calling statement, the calling tool name, and the calling tool parameters according to the parsing result; The combined query tool is called based on the calling statement, the calling tool name and the calling tool parameters to obtain the query result from the database.

5. The knowledge base question answering method based on a large language model agent according to claim 4 is characterized in that: The calling of the combined query tool based on the calling statement, the calling tool name, and the calling tool parameters to obtain the query result from the database includes: Construct a fuzzy matching query statement corresponding to the input parameters and perform the query; If the query result is not empty, the query result is returned; if the query result is empty, a new keyword combination is constructed and the query is repeated; The step of constructing a new keyword combination and re-querying includes: For the input keyword set, traverse all subset combinations of n-1 keywords in the keyword set, build queries and execute them in sequence; if no results are retrieved, continue to traverse all subset combinations of n-2 keywords in the keyword set to query, and so on, gradually reducing the number of keywords and traversing all possible combinations until a document that meets the conditions is retrieved or the number of keywords is reduced to 0.

6. The knowledge base question answering method based on a large language model agent according to claim 1, characterized in that: The S6 includes: Each document in the query result is sorted by characters into blocks to obtain a set of text blocks , satisfying the following relationship: ; in, Represents the i-th text block, where i is 1, ..., ,in is the total number of text blocks; Two independent encoders are used to convert user questions into and text blocks Encode and map the two into a dense vector space of the same dimension to obtain the problem vector representation And the text block vector representation ,as follows: ; in, Represents the vector representation of the i-th text block, i takes the value of 1,..., ; Calculate the dot product similarity between each text block vector representation and the question vector representation, satisfying the following relationship: ; in, It is Vector representation of text blocks; Determine the similarity score based on the dot product similarity, sort all text blocks according to the similarity score, and finally select the top block with the highest score. text blocks ,in, ; represents the i-th text block with the highest score, where i is 1, ..., ; Select the text block Embedded into a large model to generate the final answer.

7. The knowledge base question answering method based on a large language model agent according to claim 6, characterized in that: The text block that will be selected Embedded into a larger model to generate the final answer, including: Assume that the context of the current large model is encoded by the model's initial encoder and the embedded vector is expressed as follows: ; in, The language model context participles The embedding vector of is the number of model context segmentations, The embedding vector of the reference text block after passing through the encoder is represented as ,in For the Reference text blocks Embedding vector of Compute query vector representation using contextual embedding vectors from large models , is the dimension of the embedding vector, is the number of model context segmentations, represents the real number field, Q satisfies the following relationship: ; in, , Both are trainable linear transformation parameter matrices; Calculate the key vector representation using the embedding vector of the reference text block , is the number of reference text blocks, satisfying the following relationship: ; in, , Both are trainable linear transformation parameter matrices; The cross attention weight matrix of the context of the large model and the reference text is calculated using the following formula : ; in, is the cross attention weight matrix No. Rank The elements of the column represent the first participles For the first Reference text blocks Attention intensity; Calculate the value vector representation using the embedding vector of the reference text block , satisfying the following relationship: ; in, is the trainable linear transformation parameter matrix; Using the attention weight matrix With value vector Compute fusion output representation , and according to the output Get the final answer.

8. A knowledge base question answering system based on a large language model agent, 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 computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Commercial real estate digital assistant system based on large model and intelligent agent

    CN119918633A

  • Legal consultation system construction method based on multi-model collaborative reasoning

    CN120030130A