Method, device and equipment for improving accuracy of query result of knowledge base and storage medium
By dividing the knowledge base into multiple sub-bases and utilizing a dynamic weight allocation mechanism, the accuracy problem in massive document retrieval is solved, improving the efficiency and flexibility of knowledge base queries and ensuring the relevance and accuracy of query results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-09
- Publication Date
- 2026-03-10
AI Technical Summary
Existing RAG technology struggles to effectively filter out the most relevant content to user queries when dealing with massive amounts of documents, resulting in poor search result accuracy.
The knowledge base is divided into multiple sub-bases, and semantic description information is generated for each sub-base. The information is then converted into sub-base vectors using an embedding model. Relevant documents are retrieved from each sub-base through similarity calculation and dynamic weight allocation, and the results are finally fused.
It significantly improves the accuracy and efficiency of knowledge base query results, ensures that the sub-databases most relevant to user questions contribute more documents, reduces computational complexity, and improves query speed.
Smart Images

Figure CN121636668A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, and more particularly, to a method and device for improving the accuracy of knowledge base query results, equipment and storage medium. BACKGROUND
[0002] Currently, knowledge base retrieval systems generally use the Retrieval-Augmented Generation (RAG) technical framework (Lewis et al., 2020). This framework usually includes the following core processes: first, for the query text input by the user, the semantic analysis and fuzzy matching algorithm is used to convert it into a semantic representation that can be used for vectorization processing; second, the semantic representation is mapped to the vector feature space and similarity calculation is performed with the vectorized document entries in the knowledge base to retrieve candidate information highly relevant to the query content; finally, the retrieved candidate information is combined with the input of the generation model, and the result is reconstructed and optimized by the generation model to generate a response content that better meets the user's query intent.
[0003] However, with the increase in the number of knowledge base documents, the existing RAG document search technology gradually exposes some significant defects. Specifically, the existing technology, when faced with a large number of documents, cannot return all the documents in the library to the user at once, but returns the top N most relevant documents through similarity matching. In the case of extremely large number of documents, this method is difficult to effectively filter out the most relevant content to the user query, resulting in poor accuracy of the search results.
[0004] The root cause of this problem is that the existing RAG has difficulty extracting highly relevant documents from a large amount of information when dealing with a large number of documents. Although large models have certain semantic understanding and matching capabilities, due to the large number of documents and complex content, the model cannot comprehensively and accurately evaluate the relevance of all documents. Ultimately, the search results often contain some inaccurate or greatly deviated content from the query topic, thereby affecting the user's query experience.
[0005] Therefore, there is an urgent need for a new method that can effectively improve the accuracy and efficiency of massive knowledge base queries. SUMMARY
[0006] In view of the above problems, the present application is proposed in order to provide a method, device, equipment and storage medium for improving the accuracy of knowledge base query results, which overcomes the above problems or at least partially solves the above problems.
[0007] In order to achieve the above purpose, the present application adopts the following technical solutions: In a first aspect, embodiments of the present invention provide a method for improving the accuracy of knowledge base query results, comprising the following steps: S1. Knowledge base segmentation and vectorization steps: Divide the knowledge base into multiple segments and generate semantic description information for each segment; use a preset embedding model to convert the semantic description information of each segment into segment vectors and store them in a vector database. S2. User question vectorization step: Receive user query questions and use the embedding model to convert the user query questions into user question vectors; S3. Similarity Calculation and Weight Allocation Steps: Calculate the similarity score between the user question vector and each of the sub-database vectors, and determine the query weight corresponding to each sub-database based on the similarity score; S4. Dynamic weight query steps: Based on the query weight of each sub-database, allocate a corresponding number of documents to be returned for each sub-database, and retrieve the top few documents with the highest relevance to the user's query question from each sub-database, wherein the number of documents returned is proportional to the query weight; S5. Result Fusion and Return Steps: The documents retrieved from each sub-database are fused to generate the final query results and return them.
[0008] In one embodiment, in step S1, the criteria for dividing the multiple sub-databases include at least one of the following: document domain, type, source, or application scenario.
[0009] In one embodiment, in step S3, determining the query weight corresponding to each sub-database based on the similarity score specifically involves: The similarity scores of all databases are normalized using the Softmax function, and the normalized probability values are used as the query weights for each database.
[0010] In one embodiment, the Softmax function is calculated using the following formula:
[0011] in, The similarity score between the i-th database segment and the question, where N is the total number of database segments. The normalized probability value is between (0,1) and the sum of all probabilities is 1; e is the natural constant. This is the sum of all sub-indices' index values.
[0012] In one embodiment, in step S4, the allocation of a corresponding number of documents to be returned for each database is specifically achieved through the following formula:
[0013] in, Return the number of documents for the i-th database partition. The query weight for the i-th database shard. Returns the total number of documents for the preset; round(·) is a function that converts a floating-point number to the nearest integer.
[0014] In one embodiment, step S5, the fusion processing of documents retrieved from each sub-database, specifically includes: Calculate the fusion score for each document, which is the product of the original similarity score of the document in its respective sub-database and the query weight of that sub-database; All documents are sorted in descending order based on the fusion score, and the top K documents are selected as the final query result.
[0015] In one embodiment, the formula for calculating the fusion score for each document is as follows:
[0016] The original score is obtained by calculating the vector similarity between document k and the user query in its own sub-database. The query weight for the i-th database shard; This is the weighted fusion score.
[0017] Secondly, embodiments of the present invention provide an apparatus for improving the accuracy of knowledge base query results, comprising: Knowledge base segmentation and vectorization module: Divides the knowledge base into multiple segments and generates semantic description information for each segment; uses a preset embedding model to convert the semantic description information of each segment into segment vectors and stores them in the vector database; User question vectorization module: Receives user query questions and uses the embedding model to convert the user query questions into user question vectors; Similarity calculation and weight allocation module: calculates the similarity score between the user question vector and each of the database sub-vectors, and determines the query weight corresponding to each database sub-vector based on the similarity score; Dynamic weighted query module: Based on the query weight of each sub-database, it allocates a corresponding number of documents to be returned for each sub-database, and retrieves the top few documents with the highest relevance to the user's query question from each sub-database, wherein the number of documents returned is proportional to the query weight; The results fusion and return module: merges the documents retrieved from each sub-database, generates the final query results, and returns them.
[0018] Thirdly, embodiments of the present invention provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method as described in any one of the embodiments of the first aspect.
[0019] Fourthly, embodiments of the present invention provide a computer-readable storage medium having a computer program stored thereon, characterized in that the program, when executed by a processor, implements the method as described in any one of the embodiments of the first aspect.
[0020] The descriptions of the second and third aspects of this invention can be referred to the detailed description of the first aspect; and the beneficial effects described in the second and third aspects can be referred to the analysis of the beneficial effects of the first aspect, which will not be repeated here.
[0021] As can be seen from the above technical solution, compared with the prior art, the present invention has the following technical advantages: Improve query efficiency: By splitting the knowledge base into multiple independent sub-databases and vectorizing them, the computational burden of each query is reduced, enabling faster processing of user queries; High flexibility: The dynamic query weighting mechanism enables the system to dynamically adjust the query strategy based on the relevance of each knowledge base sub-database, ensuring that the query results better meet the user's needs.
[0022] Accuracy Improvement: Through a weighted allocation mechanism, the database shards more relevant to user queries are ensured to return more documents, significantly improving the accuracy and relevance of query results. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0024] Figure 1 This is a flowchart of a method for improving the accuracy of knowledge base query results provided in an embodiment of the present invention; Figure 2 This is a block diagram of a device for improving the accuracy of knowledge base query results provided in an embodiment of the present invention; Figure 3 This is a structural diagram of a computer device provided in an embodiment of the present invention. Detailed Implementation
[0025] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0026] This invention discloses a method for improving the accuracy of knowledge base query results, referring to... Figure 1 As shown, it includes the following steps: S1. Knowledge base segmentation and vectorization steps: Divide the knowledge base into multiple segments and generate semantic description information for each segment; use a preset embedding model to convert the semantic description information of each segment into segment vectors and store them in a vector database. S2. User question vectorization step: Receive user query questions and use the embedding model to convert the user query questions into user question vectors; S3. Similarity Calculation and Weight Allocation Steps: Calculate the similarity score between the user question vector and each of the sub-database vectors, and determine the query weight corresponding to each sub-database based on the similarity score; S4. Dynamic weight query steps: Based on the query weight of each sub-database, allocate a corresponding number of documents to be returned for each sub-database, and retrieve the top few documents with the highest relevance to the user's query question from each sub-database, wherein the number of documents returned is proportional to the query weight; S5. Result Fusion and Return Steps: The documents retrieved from each sub-database are fused to generate the final query results and return them.
[0027] In this embodiment, the method, through database sharding and weight allocation, ensures that the knowledge sub-database most relevant to the user's query intent contributes more results, effectively avoiding the bias of Top-N retrieval under a single vector space, thereby significantly improving the relevance and accuracy of the returned results. It also further optimizes query efficiency by dividing the large-scale knowledge base into multiple sub-databases for management, reducing the vector space complexity required for a single query and improving retrieval speed. Furthermore, this invention offers strong flexibility and scalability; the dynamic weighting mechanism allows the system to adaptively adjust the query strategies of different database shards, facilitating subsequent expansion of the knowledge base and adjustments to the database sharding structure.
[0028] The following is a detailed explanation of each of the above steps: S1. Knowledge base partitioning and vectorization steps: In this step, a partitioned management mechanism is adopted for the knowledge base to improve the clarity of the knowledge organization structure and the efficiency of semantic retrieval. Specifically, the knowledge base is logically partitioned based on the source attributes of the knowledge content, usage scenarios, document structure types and business relevance, or the domain of the documents.
[0029] Taking the field of power and environment-related monitoring equipment as an example, it can be divided into "Equipment Basic Knowledge Base," "Operation and Maintenance Standards Knowledge Base," and "Fault Case Knowledge Base," etc. The "Equipment Basic Knowledge Base" mainly stores the structure and parameters of equipment such as UPS, batteries, distribution cabinets, high and low voltage switchgear, air conditioners / precision air conditioners, environmental monitoring equipment, diesel generators, bus couplers, and transformers. The "Operation and Maintenance Standards Knowledge Base" includes inspection standards (daily / weekly / monthly reports), UPS / air conditioner / power distribution inspection procedures, maintenance cycles, work order standards, change procedures, and SOP standards. The "Fault Case Knowledge Base" includes UPS module failures, excessive battery voltage differential, ATS switching failures, air conditioner high / low voltage failures, generator start-up failures, and electrical equipment overheating.
[0030] After constructing the dynamic environment knowledge base, a full semantic vectorization transformation is performed on each sub-database. Specifically, this involves: automatically traversing all knowledge entries within the sub-database, using a text parser to segment document content into semantic units, and then using an embedding model (e.g., BGE-large-zh, BGE-m3) to generate a high-dimensional vector representation for each semantic unit, forming a continuous and complete set of vectors for the entire sub-database. During the generation process, metadata such as the original document location, content hash value, and sub-database number for each vector is recorded. This data is then batch-processed and written to the vector database to achieve a complete semantic index structure for each sub-database. Through this method, full vectorization of the entire sub-database is achieved. This process provides an efficient vectorized representation for subsequent queries, enabling rapid comparison of the content of each sub-database with the user's question.
[0031] S2, User Question Vectorization Steps: For user queries, the same embedding technology (such as the BGE series models) used in the knowledge base is employed to transform natural language queries into high-dimensional vector representations, enabling user intent to have computable semantic expression in the vector space.
[0032] S3. Similarity Calculation and Weight Allocation Steps: Once the user's question is vectorized, similarity calculations can be performed on the query vector and the sub-database vectors within the same vector space. Cosine similarity, dot product, or other distance metrics are used to retrieve the knowledge fragments closest to the user's intent, providing precise contextual support for subsequent semantic retrieval, answer generation, and intelligent reasoning. In other words, this yields the initial similarity score between the user's question vector and each sub-database.
[0033] Subsequently, the similarity scores between user questions and various knowledge base sub-databases are normalized to convert the relevance of different sub-databases into comparable weight values. In one implementation, the Softmax function is used to normalize these scores, converting them into query weights in the form of a probability distribution. The formula for calculating Softmax is as follows:
[0034] in, This represents the similarity score between the i-th database segment and the user question vector. For example, assuming there are three database segments, the original similarity scores calculated with the user questions are as follows: =0.9 (fault case library) (Operations and Maintenance Standards Library) (Equipment basic library).
[0035] N represents the total number of database sub-databases. In the example above, the total number of database sub-databases N = 3.
[0036] The normalized probability value is the normalized weight of the i-th sub-database, which is between (0,1) and the sum of all probabilities is 1; it represents the relative importance or hit probability of the i-th sub-database relative to all sub-databases; it is obtained by dividing the index value of the i-th sub-database by the sum of the index values of all sub-databases.
[0037] e is the natural constant; The raw score The result of performing an exponential operation (with the natural constant e as the base). Its function is to amplify the differences, mapping the original scores to a positive number space. More importantly, it can amplify the relative gap between high and low scores; high scores become very large after the exponential operation; low scores, although they also become larger, are by a small margin; in addition, it ensures computability: preparing for subsequent probabilisticization.
[0038] This is the sum of all sub-indices' index values.
[0039] For example: Calculate the exponent value: e 0.9 ≈ 2.46 e 0.5 ≈ 1.65 e 0.2 ≈ 1.22 Calculate the total: 2.46 + 1.65 + 1.22 = 5.33 Calculate the final weights: Fault Case Library Weights: = 2.46 / 5.33 ≈ 0.461 (i.e. 46.1%) Operation and maintenance standards library weight: = 1.65 / 5.33 ≈ 0.310 (i.e., 31.0%) Equipment base library weight: = 1.22 / 5.33 ≈ 0.229 (i.e., 22.9%) Verification: 0.461 + 0.310 + 0.229 = 1.000 S4. Dynamic weight query steps: Based on the query weight of each sub-database, a corresponding number of documents are returned for each sub-database, and the top few documents with the highest relevance to the user's query question are retrieved from each sub-database, wherein the number of documents returned is proportional to the query weight; The specific formula for assigning a corresponding number of documents to each database is as follows:
[0040] in, Return the number of documents for the i-th database partition. The query weight for the i-th database shard. Returns the total number of documents for the preset; round(·) is a function that converts a floating-point number to the nearest integer.
[0041] Based on the weight coefficients of each knowledge base sub-base, a certain number of highly similar documents are retrieved from each sub-base proportionally. For example, the total number of retrievals is set to 100, and the weights of the three sub-bases are as follows: Maintenance Manual Knowledge Base 30%, Standards and Specifications Knowledge Base 60%, and Emergency Response Plan Knowledge Base 10%. The system will ultimately return the top 30, 60, and 10 most relevant documents from the three sub-bases respectively, to ensure that knowledge from different sub-bases is included in the final result set according to its importance.
[0042] An example to illustrate the entire process: Assuming the system has 3 databases, the total number of documents returned is... = 100. Weight of each sub-database. as follows: Sub-database A (Fault Case Database): Weight = 0.461 Sub-database B (Operations and Maintenance Standards Database): Weight = 0.310 Sub-database C (Equipment Base Database): Weight = 0.229 Step 1: Calculate the number of theoretical documents = 0.461 * 100 = 46.1 (articles) = 0.310 * 100 = 31.0 (articles) = 0.229 * 100 = 22.9 (articles) Step 2: Use the round function to round to the nearest integer. = round(46.1) = 46 (articles) = round(31.0) = 31 (articles) = round(22.9) = 23 (articles) Step 3: Verify the sum The final total number of documents allocated: 46 + 31 + 23 = 100 (documents), compared to the preset number. Totally consistent.
[0043] S5. Result Fusion and Return Steps: After completing the cross-database document retrieval, this invention adopts a unified integration strategy to merge the document sets returned by different databases.
[0044] In one implementation, the documents returned by each sub-database can be directly concatenated in order to form the final candidate set; In another preferred embodiment, a secondary sorting is performed based on the original document similarity score and the database weight to improve the accuracy of cross-database fusion; this includes the following sub-steps: (1) Calculate the fusion score for each document, wherein the fusion score is the product of the original similarity score of the document in its respective sub-database and the query weight of the sub-database; (2) Sort all documents in descending order according to the fusion score, and select the top K documents as the final query result.
[0045] Specifically, a fusion score is calculated for each document:
[0046] The original score is obtained by calculating the vector similarity between document k and the user query in its own sub-database. The query weight for the i-th database shard; This is the weighted fusion score.
[0047] according to All candidate documents are sorted as a whole, and the top-K results are returned as the final search results. This method can effectively achieve unified sorting of documents across different databases, avoiding recall bias caused by differences in database size or similarity distribution, thereby improving the accuracy and robustness of the system output.
[0048] For example: After completing step S4, dynamic weight query, a batch of documents is now available: The top 30 documents from database A, each with a similarity score within database A, for example, 0.95, 0.93, 0.90... The top 60 documents from database shard B, each with a similarity score within database shard B, for example, 0.88, 0.87, 0.85... The top 10 documents from database shard C, each with a similarity score within shard C, for example, 0.91, 0.90, 0.89... Simply mixing these 100 documents together and then sorting them only based on their original similarity scores would be seriously unfair, because similarity scores within different databases may not be comparable.
[0049] Scenario 1: Different scales of scoring. The scoring in shard A might be "lenient," with document scores generally above 0.9; while the scoring in shard B might be "strict," with even the most relevant documents scoring only 0.88. Direct sorting would result in a large number of documents from shard A appearing before the top-level documents from shard B, even if the latter might be more relevant.
[0050] Scenario 2: Different distribution: Database C may be a small-scale, highly specialized database, and its documents and queries can naturally achieve a high semantic matching score.
[0051] Therefore, directly using the raw scores for sorting will distort the relevance importance expressed by the weights of the database shards themselves.
[0052] Therefore, a fusion score is calculated for each document:
[0053] For example: Suppose the total number of documents returned is 100. Database sharding weights: Fault Case Library (Library A): =0.6 Operation and Maintenance Standards Library (B Library): =0.3 Equipment base library (C library): =0.1 Now, take one document from each of the databases for comparison:
[0054] Analysis of sorting results: 1. If based on the raw score The sorting order is: Library B documents (0.95) > Library C documents (0.90) > Library A documents (0.85). This completely ignores the important information that "fault cases" are more relevant overall than "operation and maintenance specifications" and "equipment basics" (weight 0.6 > 0.3 > 0.1).
[0055] 2. If based on fusion score The sorting order is: Library A document (0.510) > Library B document (0.285) > Library C document (0.090). This result is reasonable and perfect: it acknowledges that the document in Library B is the most relevant in its domain (with a raw score of 0.95 being the highest). However, the system also uses weights... It emphasizes a more important overall message: "The user's current problem is the best match for the contents of the fault case library (weight 0.6)."
[0056] Therefore, the final ranking prioritizes displaying high-quality documents from the most relevant sub-database (fault case database). This ensures that the top results returned to the user are not only of high quality but also originate from the knowledge domain that best matches the user's query intent.
[0057] Through the above-described embodiments, the present invention can effectively solve the accuracy problem in massive document retrieval and improve the efficiency and flexibility of knowledge base query.
[0058] Based on the same inventive concept, this invention also provides an apparatus for improving the accuracy of knowledge base query results. Since the principle of these apparatuses in solving the problem is similar to the aforementioned method for improving the accuracy of knowledge base query results, the implementation of this apparatus can refer to the implementation of the aforementioned method, and the repeated parts will not be described again.
[0059] Reference Figure 2 As shown, this embodiment of the invention also provides an apparatus for improving the accuracy of knowledge base query results, comprising: Knowledge base segmentation and vectorization module: Divides the knowledge base into multiple segments and generates semantic description information for each segment; uses a preset embedding model to convert the semantic description information of each segment into segment vectors and stores them in the vector database; User question vectorization module: Receives user query questions and uses the embedding model to convert the user query questions into user question vectors; Similarity calculation and weight allocation module: calculates the similarity score between the user question vector and each of the database sub-vectors, and determines the query weight corresponding to each database sub-vector based on the similarity score; Dynamic weighted query module: Based on the query weight of each sub-database, it allocates a corresponding number of documents to be returned for each sub-database, and retrieves the top few documents with the highest relevance to the user's query question from each sub-database, wherein the number of documents returned is proportional to the query weight; The results fusion and return module: merges the documents retrieved from each sub-database, generates the final query results, and returns them.
[0060] Based on the same inventive concept, referring to Figure 3 As shown, the present invention also provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; When a processor executes a program stored in memory, it can implement a method for improving the accuracy of knowledge base query results, as described in the above embodiment.
[0061] like Figure 3 As shown, the electronic device may include: a processor 10, a communication interface 20, a memory 30, and a communication bus 40, wherein the processor 10, the communication interface 20, and the memory 30 communicate with each other via the communication bus 40. The processor 10 can call logical instructions in the memory 30 to execute methods to improve the accuracy of knowledge base query results. These methods include: S1. Knowledge base segmentation and vectorization steps: Divide the knowledge base into multiple segments and generate semantic description information for each segment; use a preset embedding model to convert the semantic description information of each segment into segment vectors and store them in a vector database. S2. User question vectorization step: Receive user query questions and use the embedding model to convert the user query questions into user question vectors; S3. Similarity Calculation and Weight Allocation Steps: Calculate the similarity score between the user question vector and each of the sub-database vectors, and determine the query weight corresponding to each sub-database based on the similarity score; S4. Dynamic weight query steps: Based on the query weight of each sub-database, allocate a corresponding number of documents to be returned for each sub-database, and retrieve the top few documents with the highest relevance to the user's query question from each sub-database, wherein the number of documents returned is proportional to the query weight; S5. Result Fusion and Return Steps: The documents retrieved from each sub-database are fused to generate the final query results and return them.
[0062] This invention also provides a computer-readable storage medium, in which a program stored is used to execute the above-described method for improving the accuracy of knowledge base query results, and the program can be executed on a processor.
[0063] Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory, random access memory, magnetic disks, or optical disks.
[0064] The program stored on this medium is loaded into the processor's memory and executed to perform various functions. This storage medium, connected to hardware devices, enables the computer to execute the aforementioned methods and steps for improving the accuracy of knowledge base query results.
[0065] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section.
[0066] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for improving the precision of knowledge base query results, characterized by, The method comprises the following steps: S1, a knowledge base sub-database vectorization step: dividing the knowledge base into multiple sub-databases, and generating semantic description information for each sub-database; converting the semantic description information of each sub-database into a sub-database vector by using a preset embedding model, and storing the sub-database vector into a vector database; S2, a user question vectorization step: receiving a user query question, and converting the user query question into a user question vector by using the embedding model; S3, a similarity calculation and weight allocation step: calculating a similarity score between the user question vector and each of the sub-database vectors, and determining a query weight corresponding to each sub-database based on the similarity score; S4, a dynamic weight query step: allocating a corresponding number of document returns to each sub-database according to the query weight of each sub-database, and retrieving the top several documents with the highest relevance to the user query question from each sub-database, wherein the number of document returns is proportional to the query weight; S5, a result fusion and return step: performing fusion processing on the documents retrieved from each sub-database, generating a final query result, and returning the final query result.
2. The method of claim 1, wherein, In step S1, the basis for dividing the multiple sub-databases includes at least one of the fields, types, sources, or application scenarios of the documents.
3. The method of claim 1, wherein, In step S3, the determination of the query weight corresponding to each sub-database based on the similarity score is specifically: using a Softmax function to normalize the similarity scores of all sub-databases, and taking the probability value obtained after normalization as the query weight of each sub-database.
4. The method of claim 1, wherein, The calculation formula of the Softmax function is as follows: wherein, is the similarity score of the ith sub-library to the problem, N is the total number of sub-libraries, is the normalized probability value, between (0, 1), and the sum of all probabilities is 1; e is the natural constant; is the sum of all sub-library index values.
5. The method of claim 3, wherein, In S4, the allocation of the corresponding number of document returns to each sub-database is specifically implemented by the following formula: wherein, the number of returned documents for the i-th sub-database, the query weight for the i-th sub-database, the total number of preset returned documents; and round(·) is a function of converting a floating-point number into the nearest integer.
6. The method of claim 1, wherein, In S5, the fusion processing on the documents retrieved from each sub-database specifically includes: calculating a fusion score of each document, the fusion score being the product of the original similarity score of the document in its corresponding sub-database and the query weight of the sub-database; sorting all documents in descending order according to the fusion scores, and selecting the top K documents as the final query result.
7. The method of claim 6, wherein, The formula for calculating the fusion score of each document is as follows: the original score obtained by performing vector similarity calculation between the document k and the user query in the sub-database to which the document k belongs; the query weight of the i-th sub-database; the weighted fusion score.
8. An apparatus for improving the accuracy of knowledge base query results, characterized in that, It comprises: a knowledge base sub-database vectorization module: dividing the knowledge base into multiple sub-databases, and generating semantic description information for each sub-database; converting the semantic description information of each sub-database into a sub-database vector by using a preset embedding model, and storing the sub-database vector into a vector database; a user question vectorization module: receiving a user query question, and converting the user query question into a user question vector by using the embedding model; a similarity calculation and weight allocation module: calculating a similarity score between the user question vector and each of the sub-database vectors, and determining a query weight corresponding to each sub-database based on the similarity score; a dynamic weight query module: allocating a corresponding number of document returns to each sub-database according to the query weight of each sub-database, and retrieving the top several documents with the highest relevance to the user query question from each sub-database, wherein the number of document returns is proportional to the query weight; a result fusion and return module: performing fusion processing on the documents retrieved from each sub-database, generating a final query result, and returning the final query result.
9. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor implements the method of any one of claims 1 to 7 when executing the program.
10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The program is executed by a processor to implement the method of any one of claims 1 to 7.
Citation Information
Patent Citations
Multi-knowledge-base retrieval and answer integration optimization method, retrieval enhancement generation system, equipment and medium
CN119312896A
Document processing method, knowledge retrieval method and equipment for multiple knowledge bases
CN119396959A