Retrieval method and device, equipment, storage medium and program product
By using the dendrogram search method in the big model search system, relevant information is retrieved from the nodes of the tree map, refined candidate knowledge text, and target search text is determined, the problem of insufficient refinement of the search information in the existing technology is solved, the search accuracy and recall rate are improved, and the answers generated by the big model are ensured to be more accurate.
Patent Information
- Application Number
- CN202411848328.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-16
- Publication Date
- 2025-05-02
AI Technical Summary
The search information used in the prior art to guide the text generated by the big model is not refined and accurate enough, resulting in low search accuracy and recall, affecting the big model's understanding of the search information, and thus generating inaccurate answers.
By searching target nodes related to user input problems from the nodes of the tree graph, candidate knowledge text is generated based on the hierarchical relationship between the target nodes and each node in the tree graph, and flexibly processing the target nodes according to the original structure of the original data, adjust the granularity of the candidate knowledge text to obtain more refined and accurate text, and finally determine the target search text to guide the big model to generate answers.
Improves the accuracy and recall of searches, making candidate knowledge text more refined and accurate, thus helping big models better understand and generate more accurate answers.
Smart Images

Figure CN119917612A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of text processing technology, and in particular to a retrieval method, device, equipment, storage medium and program product. Background Art
[0002] Retrieval-Augmented Generation (RAG) is a cutting-edge technology that combines language models and information retrieval technology to improve the quality and accuracy of text generation and question answering. When the model needs to generate text or answer questions, it first retrieves relevant information from a large collection of documents, and then uses the retrieved information to guide text generation. This combination of external knowledge sources enables the model to generate more accurate and contextual answers while reducing the risk of model hallucinations.
[0003] However, the retrieval information currently used to guide large models to generate text is not refined and accurate enough, resulting in low retrieval accuracy and recall rates, which is not conducive to the large model's understanding of the retrieval information and makes it easy for the large model to generate inaccurate answers. Summary of the invention
[0004] The present application provides a retrieval method, apparatus, device, storage medium and program product to improve the accuracy and recall rate of retrieval.
[0005] According to a first aspect of an embodiment of the present application, a retrieval method is provided, comprising:
[0006] Retrieving a target node related to the user input question from the nodes of the tree diagram; wherein the tree diagram is constructed based on the original data, and the hierarchical relationship between the nodes in the tree diagram is determined based on the original structure of the original data;
[0007] Generate candidate knowledge texts based on the hierarchical relationship between the target node and each node in the tree diagram;
[0008] Based on the candidate knowledge text, a target retrieval text is determined; wherein the target retrieval text is used to guide the large model to generate an answer corresponding to the user input question.
[0009] According to a second aspect of an embodiment of the present application, a retrieval device is provided, including:
[0010] A retrieval unit, used to retrieve target nodes related to the user input question from the nodes of the tree diagram; wherein the tree diagram is constructed based on the original data, and the hierarchical relationship between the nodes in the tree diagram is determined based on the original structure of the original data;
[0011] A generating unit, configured to generate candidate knowledge texts based on the hierarchical relationship between the target node and each node in the tree diagram;
[0012] A processing unit is used to determine a target retrieval text based on the candidate knowledge text; wherein the target retrieval text is used to guide the large model to generate an answer corresponding to the user input question.
[0013] According to a third aspect of an embodiment of the present application, there is provided an electronic device, including a memory and a processor;
[0014] The memory is connected to the processor and is used to store programs;
[0015] The processor is used to implement the retrieval method as described in the first aspect by running the program in the memory.
[0016] According to a fourth aspect of an embodiment of the present application, a storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the retrieval method as described in the first aspect is implemented.
[0017] According to a fifth aspect of an embodiment of the present application, a computer program product is provided, comprising computer program instructions, which, when executed by a processor, enable the processor to execute the retrieval method as described in the first aspect.
[0018] In the present application, the target node related to the user input question is retrieved from the node of the tree diagram, wherein the tree diagram is constructed based on the original data, and the hierarchical relationship between each node in the tree diagram is determined based on the original structure of the original data, so as to fully tap the effective information contained in the original structure of the original data and reduce the loss of effective information. Moreover, based on the hierarchical relationship between the target node and each node in the tree diagram, a candidate knowledge text is generated, and the target node retrieved is flexibly reprocessed according to the original structure of the original data to generate a candidate knowledge text, and the granularity of the candidate knowledge text is flexibly adjusted. On the basis of ensuring that the answer required for the user input question can be included, a candidate knowledge text with appropriate granularity and as refined as possible is further obtained, which can make the candidate knowledge text more refined and accurate. Based on the candidate knowledge text, a target retrieval text is determined, wherein the target retrieval text is used to guide the large model to generate the answer corresponding to the user input question. On the basis of the refinement and accuracy of the candidate knowledge text, the target retrieval text is also more refined and accurate. The more refined and accurate target retrieval text helps the understanding of the large model, and the generated answer is more accurate, which improves the accuracy and recall rate of the retrieval. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0020] Figure 1 A schematic diagram of a search method provided in an embodiment of the present application;
[0021] Figure 2 A schematic diagram of a process of constructing a tree diagram provided in an embodiment of the present application;
[0022] Figure 3 A schematic diagram of an exemplary raw data provided in the embodiments of the present application;
[0023] Figure 4 A schematic diagram of an exemplary tree diagram provided in the embodiments of the present application;
[0024] Figure 5 A schematic diagram of a process of step 101 provided in an embodiment of the present application;
[0025] Figure 6 A schematic diagram of a process of step 503 provided in an embodiment of the present application;
[0026] Figure 7 A schematic diagram of a process of step 102 provided in an embodiment of the present application;
[0027] Figure 8 A schematic diagram of a process of step 103 provided in an embodiment of the present application;
[0028] Fig. 9 A flowchart of step 801 provided in an embodiment of the present application;
[0029] Fig.10 A schematic diagram of a search method provided in an embodiment of the present application;
[0030] Fig.11 A schematic diagram of an exemplary prompt word provided in an embodiment of the present application;
[0031] Fig.12 A schematic diagram of the structure of a retrieval device provided in an embodiment of the present application;
[0032] Fig.13 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0033] Retrieval-augmented generation refers to a cutting-edge technology that combines language models and information retrieval techniques to improve the quality and accuracy of text generation and question answering. When the model needs to generate text or answer a question, it first retrieves relevant information from a large collection of documents, and then uses the retrieved information to guide text generation. This combination of external knowledge sources enables the model to generate more accurate and contextual answers while reducing the risk of model hallucinations.
[0034] For example, in the medical field, due to the limited training knowledge in the medical field, the big model still has a certain lack of understanding of the depth of medical knowledge. At the same time, due to the lower tolerance rate in the medical field, the reliability, traceability and timeliness of the medical knowledge involved in the big model's answers are put forward higher requirements. Therefore, it is very necessary to generate high-quality retrieval information to guide the big model to generate text.
[0035] Currently, there are two main solutions for generating retrieval information:
[0036] Solution 1
[0037] The original knowledge is divided into segments of fixed length according to fixed windows to build a knowledge base, and retrieval is performed based on each segmented fixed-length segment to obtain retrieval information.
[0038] The knowledge required to build a knowledge base should be as refined as possible while ensuring completeness. Therefore, it is difficult to obtain reasonable knowledge fragments by only segmenting according to a fixed number of words. Although some improvements can be made through the flexible setting of window length and window interval, its limitations are also obvious. Taking the setting of window length as an example, if the length is set to a small value, the complete knowledge may be segmented into different blocks, making it difficult to return the complete knowledge required for retrieval, especially for more complex knowledge that requires a longer length to discuss. If the length is set to a large value, the knowledge density in the returned results will decrease, which is not conducive to large models obtaining effective answers from them.
[0039] Solution 2
[0040] Use a large language model to generate summaries or question-answer pairs for the segmented knowledge fragments to obtain a summarized version of the original knowledge or more detailed points for retrieval, ultimately achieving the goal of improving the recall rate.
[0041] It can refine or extract the original knowledge from different aspects, increasing the probability of being correctly retrieved, but it cannot bring out the effective information in the structure of the original material itself, which will cause certain information loss. In addition, this type of method is highly dependent on the performance of the large model used, which not only increases the cost, but also may cause errors caused by the hallucination problem of the large model, which also brings certain risks to the retrieval results.
[0042] Therefore, the retrieval information currently used to guide the large model to generate text is not refined and accurate enough, resulting in low retrieval accuracy and recall, which is not conducive to the large model's understanding of the retrieval information and makes it easy for the large model to generate inaccurate answers.
[0043] In order to improve the accuracy and recall rate of retrieval, the present application provides a retrieval method, apparatus, device, storage medium and program product.
[0044] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0045] Exemplary Implementation Environment
[0046] The retrieval method according to the embodiment of the present application can be executed by an electronic device such as a terminal device or a server, and the terminal device can be a user equipment (UE), a mobile device, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. The server can be an independent physical server, a server cluster composed of multiple physical servers, or a cloud server capable of cloud computing. The method can be implemented by a processor calling a computer-readable program instruction stored in a memory.
[0047] Exemplary Methods
[0048] The search method provided in the present application can be applied to the medical field as well as other fields. The following embodiments illustrate the search method by taking the application of the medical field as an example, but do not limit this.
[0049] See also Figure 1 In an exemplary embodiment, a retrieval method is provided. Figure 1 As shown in the figure, the process of the retrieval method mainly includes:
[0050] Step 101, retrieving a target node related to the user input question from the nodes of the tree diagram.
[0051] Among them, the tree diagram is constructed based on the original data, and the hierarchical relationship between each node in the tree diagram is determined based on the original structure of the original data.
[0052] In an exemplary embodiment, in the medical field, the raw data include but are not limited to the following categories:
[0053] (1) Medical books;
[0054] (2) Various medical-related professional terms, such as detailed introductions to various diseases and drugs;
[0055] (3) International Classification of Diseases (ICD) diagnosis and surgery coding table, three medical insurance catalogs, and other medical insurance policy-related documents;
[0056] (4) Question and answer pairs on medical-related issues;
[0057] (5)Paper data in the medical field.
[0058] In an exemplary embodiment, the original structure of the original data may refer to the original logical structure of the original data. For example, the original structure of the original data includes multiple levels, namely chapters, sections, paragraphs, etc.
[0059] In some embodiments, Figure 2 As shown in the figure, the construction process of the tree diagram includes:
[0060] Step 201, segmenting the original data according to the various levels of titles in the original structure of the original data to obtain various text blocks.
[0061] For example, for unstructured original materials such as books, for the common formats of titles at all levels, for example, the formats of titles at all levels can be Chapter X, Section X, etc., or they can be serial numbers, the first-level serial numbers are "one, two, three", the second-level serial numbers are "(one)(two)(three)", the third-level serial numbers are "1.2.3.", the fourth-level serial numbers are "(1)(2)(3)", the fifth-level serial numbers are "①②③", etc., regular expressions can be used to identify the titles at all levels in the original structure of the original materials, and the original materials can be segmented according to the titles at all levels in the original structure of the original materials to obtain various text blocks; or according to the hierarchical relationship between the titles at all levels that have been set in the structured document, for example, the document has clearly marked which contents are first-level titles, second-level titles, third-level titles, etc., and the structured document can be directly segmented according to the hierarchical relationship between the titles at all levels that have been set to obtain various text blocks.
[0062] In an exemplary embodiment, step 201 may be to directly determine the titles of each level in the original structure of the original data as text blocks, one title corresponds to one text block, and determine the body text between two adjacent titles as a text block to obtain each text block.
[0063] In an exemplary embodiment, Figure 3 Shown is a schematic diagram of an exemplary raw data. Figure 3 This is an excerpt from the medical book "Pathology". Figure 3 In the text, “I. Atrophy” is the first-level heading, “(I) Types of atrophy” and “(II) Pathological changes of atrophy” are the second-level headings under “I. Atrophy”, “1. Physiological atrophy” and “2. Pathological atrophy” are the third-level headings under “(I) Types of atrophy”, and “(1) Nutritional atrophy (atrophy due to inadequate nutrition)”, “(2) Compressive atrophy (atrophy due to pressure)”, “(3) Disuse atrophy (atrophy due to decreased workload)”, “(4) Denervation atrophy (atrophy due to loss of innervation)”, “(5) Endocrine atrophy (atrophy due to loss of endocrine stimulation)” and “(6) Atrophy due to aging and injury (atrophy due to aging and injury)” are the fourth-level headings under “2. Pathological atrophy (pathological atrophy)”.
[0064] Figure 3In the example, the original data are segmented according to the various levels of titles in the original structure of the original data to obtain various text blocks. The specific text blocks may include: "I. Atrophy", "(I) Types of atrophy", "1. Physiological atrophy", "Seen in pubertal atrophy of the thymus...", "2. Pathological atrophy", "According to the cause of occurrence, it can be divided into:", "(1) Malnutrition atrophy (atrophy due to inadequatenutrition)", "May be due to insufficient protein intake...", "(2) Compression atrophy (atrophy due to pressure)", "Due to long-term pressure on tissues and organs...", "(3) Disuse atrophy (atrophy due to decreased workload)", "May be due to long-term organ tissues...", "(4) Denervation atrophy (atrophy due to loss of innervation)", "Due to motor neurons or axons...", "(5) Endocrine atrophy (atrophy due to loss of endocrine stimulation)", "Due to decreased endocrine gland function...", "(6) Atrophy due to aging and injury (atrophy due to aging and injury)". injury)", "neuronal and myocardial cells...", "(ii) pathological changes of atrophy", "the volume of atrophic cells, tissues and organs decreases...".
[0065] In some embodiments, before step 201, the process of constructing the tree diagram further includes: preprocessing the original data.
[0066] In an exemplary embodiment, preprocessing mainly includes data screening and cleaning.
[0067] Data screening refers to evaluating the quality of data and removing some invalid data. For example, in medical books and papers, some documents are converted into text documents after being recognized using OCR (Optical Character Recognition) technology. Due to reasons such as image clarity and text format, the text may have problems such as typos, missing characters, garbled characters, and paragraph splicing. Some of these problems will seriously affect reading, so it is necessary to identify and exclude these data.
[0068] Data cleaning mainly involves removing redundant parts from the original data. For example, the data converted from various medical professional books often contain irrelevant data such as headers, footers, and title page information. This part is mainly removed using regular expressions.
[0069] Step 202: Determine each node in the tree diagram based on each text block.
[0070] In some embodiments, step 202 includes: determining a text block whose text length is less than or equal to a text length threshold as a node in a dendrogram; based on the semantic similarity between adjacent sentences in a text block whose text length is greater than the text length threshold, segmenting the text block whose text length is greater than the text length threshold to obtain individual sub-text blocks; determining each sub-text block as a node in the dendrogram; wherein the text length of the sub-text block is less than or equal to the text length threshold.
[0071] In an exemplary embodiment, the text length threshold can be 2 sentences, 3 sentences, or other length thresholds. The present application is not limited to this. The text length threshold is set to a relatively small value. When the candidate knowledge text is subsequently generated based on the target node, the content of the target node can be directly spliced without refining the content of the target node, thereby reducing the loss of effective information and making the candidate knowledge text more accurate.
[0072] In an exemplary embodiment, based on the semantic similarity between adjacent sentences in a text block whose text length is greater than a text length threshold, the text block whose text length is greater than the text length threshold is segmented to obtain individual sub-text blocks, which may include: splitting the text block whose text length is greater than the text length threshold by periods, converting each sentence into a sentence representation vector using a vector model (for example, MoE (Mixture of Experts), BGE (BAAI General Embedding), etc.), calculating the semantic similarity between adjacent sentences, and when the semantic similarity between adjacent sentences is lower than a certain threshold, it is considered that the two sentences are talking about different things, and segmentation can be performed here to obtain individual sub-text blocks.
[0073] The text blocks whose text length is less than or equal to the text length threshold are determined as nodes in the dendrogram, and the text blocks whose text length is greater than the text length threshold are segmented to obtain sub-text blocks, and each sub-text block is determined as a node in the dendrogram, wherein the text length of the sub-text block is less than or equal to the text length threshold, so that the text length of each node in the dendrogram is less than or equal to the text length threshold, and the text length of each node in the dendrogram is limited to an appropriate length, which is convenient for subsequent retrieval of target nodes related to the user input question from the nodes of the dendrogram and generation of candidate knowledge text based on the target node. Moreover, based on the semantic similarity between adjacent sentences in the text blocks whose text length is greater than the text length threshold, the text blocks whose text length is greater than the text length threshold are segmented to obtain each sub-text block, which can improve the knowledge integrity of each sub-text block, reduce the occurrence of segmenting the complete knowledge into different sub-text blocks, and improve the accuracy and recall rate of retrieval.
[0074] In other embodiments, step 202 may be implemented in other ways, including but not limited to the following ways:
[0075] Method 1
[0076] Directly identify each text block as each node in the tree diagram.
[0077] Method 2
[0078] Each text block is refined, and each refined text block is determined as each node in the tree diagram.
[0079] Method 3
[0080] Based on the semantic similarity between adjacent sentences in the text block, the text block is segmented to obtain sub-text blocks; each sub-text block is refined, and the refined sub-text blocks are determined as nodes in the tree diagram.
[0081] Step 203, based on the hierarchical relationship between the titles at each level in the original structure of the original data, determine the hierarchical relationship between the nodes in the tree diagram.
[0082] For example, the node corresponding to the next level title is the child node of the node corresponding to the previous level title to which the next level title belongs, and the node corresponding to the body text is the child node of the node corresponding to the title to which the body text belongs. A node in the tree diagram may have one child node, may have at least two child nodes, or may have no child nodes, and this application does not limit this.
[0083] Step 204: construct a tree diagram based on the nodes in the tree diagram and the hierarchical relationships between the nodes in the tree diagram.
[0084] In an exemplary embodiment, Figure 4 Shown is a schematic diagram of an exemplary tree diagram. Figure 4 is based on Figure 3 The dendrogram constructed from the provided exemplary raw data, Figure 4 The English content in the middle node is not displayed, but in fact the node can contain English content.
[0085] Figure 3In the text, "I. Atrophy" is the first-level heading, "(I) Types of atrophy" and "(II) Pathological changes of atrophy" are the second-level headings under "I. Atrophy", "1. Physiological atrophy" and "2. Pathological atrophy" are the third-level headings under "(I) Types of atrophy", "Seen in pubertal atrophy of the thymus..." is the main text under "1. Physiological atrophy", "According to the cause of occurrence, it is divided into:" is the main text under "2. Pathological atrophy", "(1) Malnutrition atrophy (atrophy due to inadequate nutrition)", "(2) Pressure atrophy (atrophy due to pressure)", "(3) Disuse atrophy (atrophy due to decreased workload)", "(4) Denervation atrophy (atrophy due to loss of innervation)", "(5) Endocrine atrophy (atrophy due to loss of endocrine stimulation)", "(6) Atrophy due to aging and injury (atrophy due to aging andinjury)" is the four-level heading under "According to the cause of occurrence, it is divided into:".
[0086] “It may be due to insufficient protein intake…” is the main text under “(1) Atrophy due to inadequate nutrition”, “It may be due to long-term pressure on tissues and organs…” is the main text under “(2) Atrophy due to compression (atrophy due to pressure)”, “It may be due to long-term organ tissue…” is the main text under “(3) Atrophy due to disuse (atrophy due to decreased workload)”, “It may be due to motor neurons or axons…” is the main text under “(4) Atrophy due to denervation (atrophy due to loss of innervation)”, “It may be due to decreased endocrine gland function…” is the main text under “(5) Endocrine atrophy (atrophy due to loss of endocrine stimulation)”, and “It may be due to nerve cells and cardiomyocytes…” is the main text under “(6) Atrophy due to aging and injury (atrophy due to aging and injury)”. “The volume of atrophied cells, tissues and organs decreases…” is the main text under “(ii) Pathological changes of atrophy”.
[0087] Figure 4In the example, “(I) Types of atrophy” and “(II) Pathological changes of atrophy” are subnodes of “I. Atrophy”; “1. Physiological atrophy” and “2. Pathological atrophy” are subnodes of “(I) Types of atrophy”; “Seen in pubertal atrophy of the thymus…” is a subnode of “1. Physiological atrophy”; “According to the cause of occurrence, it is divided into:” is a subnode of “2. Pathological atrophy”; “(1) Malnutrition atrophy (atrophy due to inadequate nutrition)”, “(2) Compression atrophy (atrophy due to pressure)”, “(3) Disuse atrophy (atrophy due to decreased workload)”, “(4) Denervation atrophy (atrophy due to loss of innervation)”, “(5) Endocrine atrophy (atrophy due to loss of endocrine stimulation)” and “(6) Atrophy due to aging and injury (atrophy due to aging and injury)” are subnodes of “According to the cause of occurrence, it is divided into:”.
[0088] “May be due to insufficient protein intake…” is a child node of “(1) Atrophy due to inadequate nutrition”, “May be due to long-term pressure on tissues and organs…” is a child node of “(2) Atrophy due to pressure”, “May be due to long-term…” is a child node of “(3) Atrophy due to decreased workload”, “May be due to motor neurons or axons…” is a child node of “(4) Atrophy due to loss of innervation”, “May be due to decreased endocrine gland function…” is a child node of “(5) Endocrine atrophy…”, and “May be due to nerve cells and cardiomyocytes…” is a child node of “(6) Atrophy due to aging and injury”. “The volume of atrophied cells, tissues and organs decreases…” is a child node of “(ii) Pathological changes of atrophy”. Figure 4In the example, the English content in the node is not displayed, but in fact the node contains English content.
[0089] There are many high-quality knowledge in the medical field, mainly including medical professional books and various professional entries. The common feature of these original materials is that they have a multi-level and fine classification structure. The most intuitive manifestation is that medical books are usually composed of multiple layers of titles with clear hierarchies. A lot of effective knowledge is often contained in the structure of each layer of titles, but the existing knowledge base cannot effectively mine this knowledge. Therefore, not only a lot of effective information is lost, but also the granularity of the output retrieval information cannot be flexibly adjusted according to these structures, which not only leads to the limitation of the precision and recall rate of the retrieval, but also makes it difficult to obtain a complete and concise answer.
[0090] In the present application, the original data is segmented according to the titles of each level in the original structure of the original data to obtain various text blocks, and the nodes in the tree diagram are determined based on the various text blocks. The hierarchical relationship between the nodes in the tree diagram is determined based on the hierarchical relationship between the titles of each level in the original structure of the original data. A tree diagram is constructed based on the nodes in the tree diagram and the hierarchical relationship between the nodes in the tree diagram, so as to fully explore the effective information contained in the original structure of the original data and reduce the loss of effective information. The hierarchical relationship between the titles of each level in the original structure of the original data is fully utilized to construct a tree diagram, and the total score, inclusion or enumeration and other relationships provided by the original multi-layer results in each original data are retained. The retrieved target nodes are flexibly reprocessed according to the original structure of the original data to generate candidate knowledge texts, and the granularity of the candidate knowledge texts is flexibly adjusted. On the basis of ensuring that the answers required for the user's input questions can be included, candidate knowledge texts with appropriate granularity and as refined as possible are further obtained, which can make the candidate knowledge texts more refined and accurate. It can improve the knowledge density in the candidate knowledge text. More refined and accurate knowledge helps the understanding of the large model, and the generated answers are more accurate, thereby improving the accuracy and recall rate of retrieval.
[0091] By constructing a tree diagram, we can mine the effective information of different granularities contained in the original structure of the original data, effectively avoiding the problem of information loss or out-of-context quotations caused by the segmentation method of the traditional knowledge base, and can effectively improve the accuracy of knowledge retrieval and the knowledge density of the returned retrieved information.
[0092] In some embodiments, step 101 may include: retrieving a target node related to the user input question from the nodes of the tree diagram by a retrieval method.
[0093] For example, a first vector of the user input question and second vectors corresponding to each node in the tree diagram can be generated. Based on the first vector and each second vector, a first node related to the user input question is retrieved from the nodes of the tree diagram, and the first node is determined as the target node. Alternatively, based on the user input question, information retrieval based on the text content of each node in the tree diagram is performed, and a second node related to the user input question is determined from the nodes of the tree diagram, and the second node is determined as the target node.
[0094] In other embodiments, Figure 5 As shown, step 101 includes:
[0095] Step 501 : determining a first vector of a question input by a user and a second vector corresponding to each node in a tree diagram.
[0096] In an exemplary embodiment, step 501 may be to convert the user input question into a high-dimensional representation vector through a vector model to obtain a first vector of the user input question; and obtain a second vector corresponding to each node in the tree diagram. Since each node in the tree diagram does not change during each search process, each node in the tree diagram may be converted into a high-dimensional representation vector through a vector model in advance before step 501 to obtain a second vector corresponding to each node in the tree diagram. When executing step 501, the second vector corresponding to each node in the tree diagram generated in advance may be directly obtained, which can reduce the amount of calculation in the search process and improve the search efficiency.
[0097] In an exemplary embodiment, the vector model may be MoE (Mixture of Experts), BGE (BAAI General Embedding), or the like.
[0098] Step 502: based on the first vector and each second vector, retrieve a first node related to the user input question from the nodes of the tree diagram.
[0099] In an exemplary embodiment, based on the first vector and each second vector, the first node related to the user input question is retrieved from the nodes of the tree diagram, which may be to calculate the similarity between the first vector and each second vector, and determine the first node related to the user input question from the nodes of the tree diagram based on each similarity. For example, the similarities may be sorted from large to small, and the nodes corresponding to the first M similarities may be determined as the first nodes related to the user input question; or the nodes corresponding to the similarities greater than the similarity threshold may be determined as the first nodes related to the user input question.
[0100] In an exemplary embodiment, step 501 and step 502 can be completed using a vector database or a general database with a vector retrieval plug-in, such as a PostgreSQL database (an object-relational database management system) and a pgvector plug-in (pgvector is an extension plug-in based on PostgreSQL that provides users with a set of powerful vector storage and query functions), and the retrieval efficiency can be improved by establishing a vector index.
[0101] Step 503: Based on the question input by the user, information retrieval based on the text content is performed on each node in the tree diagram, and a second node related to the question input by the user is determined from the nodes in the tree diagram.
[0102] In an exemplary embodiment, information retrieval based on text content may include at least one of information retrieval by searching for keywords, information retrieval by editing distance, information retrieval by TF-IDF (Term Frequency-Inverse Document Frequency), and information retrieval by BM25 (Best Matching 25, an information retrieval algorithm, an improved version of the TF-IDF algorithm). Of course, information retrieval based on text content may also include other retrieval methods, which are not limited in this application.
[0103] In some embodiments, Figure 6 As shown, step 503 includes:
[0104] Step 601, performing the following operations for any node in the tree diagram: determining the word frequency corresponding to each word in the user input question in any node.
[0105] In the exemplary embodiment, any node in the tree diagram is represented by D, and the jth word in the user input question is represented by q j Indicates that the word q j The frequency of words in document D is expressed as f(q j ,D) indicates that word frequency is a basic indicator to measure the importance of a word in a document. The higher the word frequency, the greater the importance of the word in the document.
[0106] In an exemplary embodiment, the frequency of each word in each node of the tree diagram can be calculated in advance before step 601. In each subsequent search process, when executing step 601, the frequency of each word in the user input question is directly matched with the word in each node of the tree diagram, and the frequency of the word in the successfully matched node is determined as the frequency of the word in the user input question. This can reduce the amount of calculation in the search process and improve the search efficiency.
[0107] Step 602: determine the inverse document frequency corresponding to each word in the user input question in the tree diagram.
[0108] In an exemplary embodiment, the jth word in the user input question is represented by q j It means that IDF(q j ) is the word q j The inverse document frequency is an indicator of the uniqueness or information content of a word for the entire document set. The inverse document frequency is determined by the number of documents in the entire document set that contain the word. If a word appears in many documents, the IDF value of the word will be low, and vice versa. This means that rare words usually have higher IDF values and thus have greater weight in the relevance score. The document set here refers to each node in the tree diagram, and a node in the tree diagram is regarded as a document.
[0109] For example, the word q j The inverse document frequency IDF(q j ) is calculated as follows:
[0110]
[0111] Among them, N refers to the total number of documents in the document collection, that is, the total number of nodes in the dendrogram; n(q i ) refers to the document collection containing the word q j The number of documents that contain word q in the dendrogram j The number of nodes in q j The inverse document frequency IDF(q j ) can also be other formulas, and this application does not limit this.
[0112] In an exemplary embodiment, the inverse document frequency of each word in each node of the tree diagram can be calculated in advance before step 602. In each subsequent retrieval process, each word in the user input question is directly matched with each word in each node of the tree diagram when step 602 is executed, and the inverse document frequency of the word in the successfully matched node is determined as the inverse document frequency of the word in the user input question. This can reduce the amount of calculation in the retrieval process and improve retrieval efficiency.
[0113] Step 603: Determine the relevance score between any node and the user input question based on each word frequency and each inverse document frequency.
[0114] In the exemplary embodiment, any node in the tree diagram is represented by D, the user input question is represented by Q, and the jth word in the user input question is represented by q j Indicates that the word q j The frequency of words in document D is expressed as f(q j ,D) means, IDF(q j) is the word q j The inverse document frequency of any node D and the user input question Q is represented by Score(D,Q). The specific calculation formula of Score(D,Q) is as follows:
[0115]
[0116] Among them, n refers to the total number of words in the user input question; k1 and b are adjustable parameters, usually k1 is between 1.2 and 2, b is usually set to 0.75, k1 and b can also be set to other values; |D| is the document length of any node D in the dendrogram, and the document length is used to adjust the influence of word frequency, because longer documents may have higher word frequency simply because of their length; avgdl is the average length of all documents, that is, the average document length of each node in the dendrogram, which is used to standardize the length of different documents so that documents of different lengths can be compared fairly. Before step 603, after the dendrogram is constructed, |D| and avgdl can be directly calculated in advance, and |D| and avgdl can be directly used when executing step 603 in each subsequent retrieval process, which can reduce the amount of calculation in the retrieval process and improve retrieval efficiency.
[0117] The specific calculation formula of Score(D,Q) may also be other formulas, and this application is not limited to this.
[0118] Step 604: Based on the correlation scores corresponding to the nodes in the tree diagram, determine a second node related to the user input question from the nodes in the tree diagram.
[0119] In an exemplary embodiment, step 604 may be to determine the node whose relevance score is greater than the relevance score threshold as the second node related to the user input question; or it may be to sort the relevance scores from large to small and determine the nodes corresponding to the first S relevance scores as the second node related to the user input question.
[0120] The following operations are performed for any node in the tree diagram: determine the word frequency corresponding to each word in the user input question in any node, determine the inverse document frequency corresponding to each word in the user input question in the tree diagram, determine the correlation score between any node and the user input question based on each word frequency and each inverse document frequency, determine the second node related to the user input question from the nodes of the tree diagram based on the correlation score corresponding to each node in the tree diagram, and through the word frequency and inverse document frequency, the second node related to the user input question can be quickly and accurately determined from the text level.
[0121] Step 504: Determine a target node related to the user input question based on the first node and the second node.
[0122] In an exemplary embodiment, step 504 may be to merge the first node and the second node, remove duplicate nodes, and determine the node obtained after deduplication as the target node related to the user input question. That is, nodes that only belong to the first node and not to the second node, nodes that only belong to the second node and not to the first node, and nodes that belong to both the first node and the second node are all determined as target nodes related to the user input question.
[0123] In an exemplary embodiment, step 504 may also be to determine a node that belongs to both the first node and the second node as a target node related to the question input by the user.
[0124] Determine the first vector of the user input question and the second vector corresponding to each node in the dendrogram; based on the first vector and each second vector, retrieve the first node related to the user input question from the nodes of the dendrogram; based on the user input question, perform text content-based information retrieval on each node in the dendrogram; determine the second node related to the user input question from the nodes of the dendrogram; determine the target node related to the user input question based on the first node and the second node; use different retrieval methods, vector-based retrieval and text content-based information retrieval, determine the target node related to the user input question from the nodes of the dendrogram; the retrieved target nodes are more accurate, avoid missing nodes related to the user input question, and improve the retrieval accuracy and recall rate.
[0125] Step 102, generating candidate knowledge texts based on the hierarchical relationship between the target node and each node in the tree diagram.
[0126] In some embodiments, Figure 7 As shown, step 102 includes:
[0127] Step 701, performing the following operations for any untraversed target node: determining any untraversed target node as the starting node of traversal, traversing each first adjacent node adjacent to any untraversed target node, and determining the target node in each first adjacent node as the first intermediate node.
[0128] In the exemplary embodiment, reference is made to breadth-first search (BFS). Breadth-first search refers to a traversal strategy that starts from an untraversed node in the graph, first traverses all adjacent nodes of the node, and then traverses the adjacent nodes of each adjacent node in turn. In the present application, step 701 is to traverse each first adjacent node adjacent to any untraversed target node, select the target node from the first adjacent nodes, and determine it as the first intermediate node.
[0129] Step 702, traverse each (i+1)th adjacent node adjacent to the i-th intermediate node, and determine the target node in each (i+1)th adjacent node as the (i+1)th intermediate node.
[0130] Wherein, i is a positive integer.
[0131] In an exemplary embodiment, when i=1, each second adjacent node adjacent to the first intermediate node is traversed, and the target node in each second adjacent node is determined as the second intermediate node; when i=2, each third adjacent node adjacent to the second intermediate node is traversed, and the target node in each third adjacent node is determined as the third intermediate node; and so on, the traversal is performed.
[0132] Step 703, when the preset conditions are met, stop traversal, and sort and concatenate any untraversed target node, the first intermediate node and the (i+1)th intermediate node according to the hierarchical relationship between the nodes in the tree diagram to generate a candidate knowledge text.
[0133] The preset conditions include that there is no target node among the (i+1)th adjacent nodes adjacent to the i-th intermediate node, and there is no target node among the nodes adjacent to the (i+1)th adjacent nodes.
[0134] When there is no target node among the (i+1)th adjacent nodes adjacent to the i-th intermediate node, and there is no target node among the nodes adjacent to the (i+1)th adjacent nodes, it is considered that there is no adjacent target node near the i-th intermediate node and the traversal is stopped.
[0135] Any untraversed target node, the first intermediate node and the (i+1)th intermediate node are sorted and concatenated according to the hierarchical relationship between the nodes in the tree diagram to generate a candidate knowledge text, and then steps 701, 702 and 703 are repeated for the next untraversed target node to obtain the next candidate knowledge text, until all target nodes have been traversed to obtain all candidate knowledge texts.
[0136] According to the original structure of the original data, the target nodes retrieved are flexibly reprocessed to generate candidate knowledge texts, and the granularity of the candidate knowledge texts is flexibly adjusted. On the basis of ensuring that the answers required by the user input questions can be included, the candidate knowledge texts with appropriate granularity and as refined as possible are further obtained, which can make the candidate knowledge texts more refined and accurate. A breadth-first node traversal method based on a tree diagram is constructed for retrieval, which further gives play to the advantages of the tree diagram. According to the knowledge structure stored in the tree diagram, it is possible to flexibly grasp which level of knowledge should be output, and on this basis, multiple candidate knowledge texts are formed, and the advantages and disadvantages of multiple candidate knowledge texts are systematically evaluated and output. It can not only match the knowledge of a certain level corresponding to the user input question, but also avoid outputting large sections of redundant explanatory texts. It can give play to the advantages of the tree diagram knowledge base and use the known knowledge structure to find a suitable balance between the knowledge integrity and refinement of the output candidate knowledge texts, so as to better meet the requirements of the large language model for knowledge retrieval.
[0137] In some other embodiments, step 102 includes: directly sorting the target nodes according to the hierarchical relationship between the nodes in the tree diagram and concatenating them to generate candidate knowledge texts.
[0138] In other embodiments, step 102 includes: refining the target nodes to obtain refined target nodes, sorting the refined target nodes according to the hierarchical relationship between the nodes in the tree diagram, and splicing them to generate candidate knowledge texts.
[0139] Step 103: Determine the target retrieval text based on the candidate knowledge text.
[0140] Among them, the target retrieval text is used to guide the large model to generate answers corresponding to the user input questions.
[0141] In some embodiments, step 103 includes: directly determining the candidate knowledge text as the target retrieval text.
[0142] In other embodiments, Figure 8 As shown, step 103 includes:
[0143] Step 801, determining the relevance between the user input question and each candidate knowledge text.
[0144] In some embodiments, a candidate knowledge text is obtained by concatenating at least one target node.
[0145] In some embodiments, Fig. 9 As shown, step 801 includes:
[0146] Step 901, perform the following operations for any candidate knowledge text: sort the target nodes of any candidate knowledge text by their relevance to the user input question through various search methods, and obtain the relevance sorting results corresponding to each search method.
[0147] For example, various retrieval methods include vector retrieval and BM25, and the target nodes of the candidate knowledge text 1 obtained by splicing are target node 1, target node 2, target node 3, and target node 4 respectively. The relevance sorting result corresponding to the vector retrieval is {target node 1, target node 2, target node 3, target node 4}, and the relevance sorting result corresponding to BM25 is {target node 3, target node 1, target node 2, target node 4}.
[0148] Step 902, based on the position of any target node corresponding to any candidate knowledge text in each relevance ranking result, determine the comprehensive relevance between any target node corresponding to any candidate knowledge text and the user input question.
[0149] In the exemplary embodiment, the set of target nodes of any candidate knowledge text obtained by splicing is represented by E, any target node corresponding to any candidate knowledge text is represented by e, the set of relevance ranking results is represented by R, a relevance ranking result is represented by r, the position of the target node e in the relevance ranking result r is represented by r(e), and the comprehensive relevance between any target node e corresponding to any candidate knowledge text and the user input question is represented by RRF e Indicates that RRF e The specific calculation formula is as follows:
[0150]
[0151] Here, k is a constant, usually 60 by default, but it can also take other values.
[0152] Step 903, based on the comprehensive relevance between each target node of any candidate knowledge text and the user input question obtained by splicing, determine the relevance between any candidate knowledge text and the user input question.
[0153] In the exemplary embodiment, the set of target nodes obtained by splicing any candidate knowledge text is represented by E, any target node corresponding to any candidate knowledge text is represented by e, and the comprehensive relevance between any target node e corresponding to any candidate knowledge text and the user input question is represented by RRF e The relevance between any candidate knowledge text and the user input question is expressed as RRF all Indicates that RRFall The specific calculation formula is as follows:
[0154]
[0155] RRF (Reciprocal Rank Fusion) is a method that combines multiple result sets with different relevance indicators into a single result set. When there are rankings generated by multiple different retrieval methods that need to be merged, RRF can obtain a higher quality final ranking by combining the advantages of multiple retrieval methods.
[0156] Reverse sort fusion does not mean that the ranking results are in reverse order, but The inverse of the ranking position r(e) is calculated. The higher the ranking, the smaller r(e). The larger the RRF e The bigger.
[0157] The following operations are performed for any candidate knowledge text: each target node of any candidate knowledge text is concatenated, and is sorted according to the relevance between the target nodes and the user input question by various retrieval methods to obtain the relevance sorting results corresponding to each retrieval method; based on the position of any target node corresponding to any candidate knowledge text in each relevance sorting result, the comprehensive relevance between any target node corresponding to any candidate knowledge text and the user input question is determined; based on the comprehensive relevance between each target node of any candidate knowledge text obtained by concatenation and the user input question, the relevance between any candidate knowledge text and the user input question is determined; the relevance sorting results corresponding to each retrieval method are comprehensively considered; a higher quality final ranking is obtained by combining the advantages of multiple retrieval methods, and then the relevance between any candidate knowledge text and the user input question is determined, which can improve the accuracy of the relevance between any candidate knowledge text and the user input question.
[0158] In some other embodiments, step 801 includes: directly determining the relevance between the user input question and each candidate knowledge text based on a retrieval method.
[0159] Step 802: Determine the target retrieval text from each candidate knowledge text based on each relevance.
[0160] In an exemplary embodiment, step 802 may be to calculate the classification value corresponding to each candidate knowledge text based on the correlation between the user input question and each candidate knowledge text, and determine the target retrieval text from each candidate knowledge text based on the classification value corresponding to each candidate knowledge text.
[0161] In an exemplary embodiment, the relevance between the tth candidate knowledge text and the user input question is expressed as x t Indicates that the classification value corresponding to the t-th candidate knowledge text is expressed as softmax(x t ) means that softmax(x t ) is calculated as follows:
[0162]
[0163] In an exemplary embodiment, a target retrieval text is determined from each candidate knowledge text based on the classification value corresponding to each candidate knowledge text. The candidate knowledge text with a classification value greater than a classification threshold may be determined as the target retrieval text, or the classification values may be sorted from large to small, and the candidate knowledge texts corresponding to the first T classification values may be determined as the target retrieval text, or the candidate knowledge text with the largest classification value may be determined as the target retrieval text. The present application does not impose any restrictions on this.
[0164] Determine the relevance between the user input question and each candidate knowledge text, and based on each relevance, determine the target retrieval text from each candidate knowledge text. This can further screen out the target retrieval text with high relevance to the user input question from each candidate knowledge text. On the basis of the refinement and accuracy of the candidate knowledge text, the target retrieval text is also more refined and accurate. A more refined and accurate target retrieval text helps the large model to understand, and the generated answer is more accurate, thereby improving the retrieval accuracy and recall rate.
[0165] In some embodiments, Fig.10 As shown, the retrieval method also includes:
[0166] Step 1001, generating prompt words based on the target search text and the user input question.
[0167] In an exemplary embodiment, Fig.11 Shown is a schematic diagram of an exemplary prompt word. Fig.11 The source information of the target search text is marked in the prompt word to facilitate subsequent tracing.
[0168] Step 1002, input the prompt word into the large model, and obtain the answer corresponding to the user input question output by the large model.
[0169] Among them, the prompt word is used to instruct the large model to generate the answer corresponding to the user input question based on the target retrieval text.
[0170] Based on the target retrieval text and user input questions, it can instruct the large model to generate answers corresponding to user input questions based on the target retrieval text. Refined and accurate target retrieval text helps the large model understand, and the generated answers are more accurate, thereby improving the retrieval accuracy and recall rate.
[0171] In summary, in this application, the target nodes related to the user input question are retrieved from the nodes of the tree diagram, wherein the tree diagram is constructed based on the original data, and the hierarchical relationship between the nodes in the tree diagram is determined based on the original structure of the original data, so as to fully tap the effective information contained in the original structure of the original data and reduce the loss of effective information. Moreover, based on the hierarchical relationship between the target node and the nodes in the tree diagram, the candidate knowledge text is generated, and the target node retrieved is flexibly reprocessed according to the original structure of the original data to generate the candidate knowledge text, and the granularity of the candidate knowledge text is flexibly adjusted. On the basis of ensuring that the answer required by the user input question can be included, the candidate knowledge text with appropriate granularity and as refined as possible is further obtained, which can make the candidate knowledge text more refined and accurate. Based on the candidate knowledge text, the target retrieval text is determined, wherein the target retrieval text is used to guide the large model to generate the answer corresponding to the user input question. On the basis of the refinement and accuracy of the candidate knowledge text, the target retrieval text is also more refined and accurate. The more refined and accurate target retrieval text helps the understanding of the large model, and the generated answer is more accurate, which improves the accuracy and recall rate of the retrieval.
[0172] Exemplary Devices
[0173] Accordingly, the present application also provides a retrieval device, such as Fig.12 As shown, the retrieval device comprises:
[0174] A retrieval unit 1201 is used to retrieve target nodes related to the user input question from the nodes of the tree diagram; wherein the tree diagram is constructed based on the original data, and the hierarchical relationship between the nodes in the tree diagram is determined based on the original structure of the original data;
[0175] A generating unit 1202, configured to generate a candidate knowledge text based on the hierarchical relationship between the target node and each node in the tree diagram;
[0176] The processing unit 1203 is used to determine a target search text based on the candidate knowledge text; wherein the target search text is used to guide the large model to generate an answer corresponding to the user input question.
[0177] Optionally, the retrieval unit 1201 includes:
[0178] A vector determination subunit, used to determine a first vector of the user input question and a second vector corresponding to each node in the tree diagram;
[0179] A first retrieval subunit, configured to retrieve a first node related to the user input question from the nodes of the tree diagram based on the first vector and each of the second vectors;
[0180] A second retrieval subunit is used to perform information retrieval based on text content on each node in the tree diagram based on the question input by the user, and determine a second node related to the question input by the user from the nodes in the tree diagram;
[0181] The first processing subunit is used to determine a target node related to the user input question based on the first node and the second node.
[0182] Optionally, the second retrieval subunit is specifically configured to:
[0183] For any node in the tree diagram, perform the following operations:
[0184] Determine the word frequency corresponding to each word in the user input question in any one of the nodes;
[0185] Determine the inverse document frequency corresponding to each word in the user input question in the tree diagram;
[0186] Determine a relevance score between the arbitrary node and the user input question based on each of the word frequencies and each of the inverse document frequencies;
[0187] Based on the relevance scores corresponding to the nodes in the tree diagram, a second node related to the user input question is determined from the nodes in the tree diagram.
[0188] Optionally, the generating unit 1202 includes:
[0189] The first traversal subunit is used to perform the following operations for any untraversed target node: determine the any untraversed target node as a starting node for traversal, traverse each first adjacent node adjacent to the any untraversed target node, and determine the target node in each first adjacent node as a first intermediate node;
[0190] The second traversal subunit is used to traverse each (i+1)th adjacent node adjacent to the i-th intermediate node, and determine the target node in each (i+1)th adjacent node as the (i+1)th intermediate node; wherein i is a positive integer;
[0191] The second processing sub-unit is used to stop traversal when a preset condition is met, and sort and splice any untraversed target node, the first intermediate node and the (i+1)th intermediate node according to the hierarchical relationship between the nodes in the tree diagram to generate a candidate knowledge text;
[0192] The preset conditions include that there is no target node among the (i+1)th adjacent nodes adjacent to the i-th intermediate node, and there is no target node among the nodes adjacent to the (i+1)th adjacent nodes.
[0193] Optionally, the processing unit 1203 includes:
[0194] A third processing subunit is used to determine the relevance between the user input question and each of the candidate knowledge texts;
[0195] The fourth processing subunit is used to determine the target retrieval text from each of the candidate knowledge texts based on each of the relevances.
[0196] Optionally, one of the candidate knowledge texts is obtained by concatenating at least one target node;
[0197] The third processing subunit is specifically configured to:
[0198] For any candidate knowledge text, perform the following operations:
[0199] The target nodes of any candidate knowledge text obtained by splicing are sorted according to the relevance between the target nodes and the user input question by using various search methods to obtain the relevance sorting results corresponding to the various search methods;
[0200] Determine the comprehensive relevance between any target node corresponding to any candidate knowledge text and the user input question based on the position of any target node corresponding to any candidate knowledge text in each of the relevance ranking results;
[0201] Based on the comprehensive relevance between each target node of the any one candidate knowledge text and the user input question obtained by splicing, the relevance between the any one candidate knowledge text and the user input question is determined.
[0202] Optionally, the retrieval device further comprises:
[0203] A prompt word generating unit, used for generating prompt words based on the target search text and the user input question;
[0204] An answer output unit is used to input the prompt word into the big model to obtain the answer corresponding to the user input question output by the big model, wherein the prompt word is used to instruct the big model to generate the answer corresponding to the user input question based on the target retrieval text.
[0205] Optionally, the retrieval device further comprises:
[0206] A segmentation unit, used for segmenting the original data according to the various levels of titles in the original structure of the original data to obtain various text blocks;
[0207] A node determination unit, used for determining each node in the tree diagram based on each of the text blocks;
[0208] A relationship determination unit, configured to determine the hierarchical relationship between the nodes in the tree diagram based on the hierarchical relationship between the titles at each level in the original structure of the original data;
[0209] A construction unit is used to construct the tree diagram based on each node in the tree diagram and the hierarchical relationship between each node in the tree diagram.
[0210] Optionally, the node determination unit is specifically configured to:
[0211] Determine a text block whose text length is less than or equal to a text length threshold as a node in the dendrogram;
[0212] Based on the semantic similarity between adjacent sentences in the text block whose text length is greater than the text length threshold, the text block whose text length is greater than the text length threshold is segmented to obtain various sub-text blocks;
[0213] Determine each sub-text block as a node in the tree diagram;
[0214] The text length of the sub-text block is less than or equal to a text length threshold.
[0215] The search device provided in this embodiment belongs to the same application concept as the search method provided in the above embodiments of this application, can execute the search method provided in any of the above embodiments of this application, and has the corresponding functional modules and beneficial effects of executing the search method. For technical details not fully described in this embodiment, please refer to the specific processing content of the search method provided in the above embodiments of this application, and will not be repeated here.
[0216] The functions implemented by the above retrieval unit 1201, generation unit 1202 and processing unit 1203 can be implemented by the same or different processors respectively, and the embodiments of the present application are not limited thereto.
[0217] It should be understood that the units in the above devices can be implemented in the form of a processor calling software. For example, the device includes a processor, the processor is connected to a memory, and instructions are stored in the memory. The processor calls the instructions stored in the memory to implement any of the above methods or realize the functions of each unit of the device, wherein the processor can be a general-purpose processor, such as a CPU or a microprocessor, etc., and the memory can be a memory in the device or a memory outside the device. Alternatively, the units in the device can be implemented in the form of hardware circuits, and the functions of some or all units can be realized by designing the hardware circuits. The hardware circuit can be understood as one or more processors; for example, in one implementation, the hardware circuit is an ASIC, and the functions of some or all of the above units are realized by designing the logical relationship of the components in the circuit; for another example, in another implementation, the hardware circuit can be implemented by PLD, taking FPGA as an example, which can include a large number of logic gate circuits, and the connection relationship between the logic gate circuits is configured by the configuration file, so as to realize the functions of some or all of the above units. All units of the above devices can be implemented in the form of a processor calling software, or in the form of hardware circuits, or in part by a processor calling software, and the remaining part is implemented in the form of hardware circuits.
[0218] In an embodiment of the present application, a processor is a circuit with the ability to process signals. In one implementation, the processor may be a circuit with the ability to read and run instructions, such as a CPU, a microprocessor, a GPU, or a DSP; in another implementation, the processor may implement certain functions through the logical relationship of a hardware circuit, and the logical relationship of the hardware circuit is fixed or reconfigurable, such as a hardware circuit implemented by an ASIC or PLD, such as an FPGA. In a reconfigurable hardware circuit, the process of the processor loading a configuration document to implement the hardware circuit configuration can be understood as the process of the processor loading instructions to implement the functions of some or all of the above units. In addition, it can also be a hardware circuit designed for artificial intelligence, which can be understood as an ASIC, such as an NPU, TPU, DPU, etc.
[0219] It can be seen that each unit in the above device can be one or more processors (or processing circuits) configured to implement the above method, such as: CPU, GPU, NPU, TPU, DPU, microprocessor, DSP, ASIC, FPGA, or a combination of at least two of these processor forms.
[0220] In addition, all or part of the units in the above device can be integrated together, or can be implemented independently. In one implementation, these units are integrated together and implemented in the form of a SOC. The SOC may include at least one processor for implementing any of the above methods or implementing the functions of each unit of the device. The type of the at least one processor may be different, for example, including a CPU and an FPGA, a CPU and an artificial intelligence processor, a CPU and a GPU, etc.
[0221] Exemplary Electronic Devices
[0222] An embodiment of the present application provides an electronic device, see Fig.13 As shown, the device includes:
[0223] Memory 200 and processor 210;
[0224] The memory 200 is connected to the processor 210 and is used to store programs;
[0225] The processor 210 is used to implement the retrieval method disclosed in any of the above embodiments by running the program stored in the memory 200.
[0226] Specifically, the electronic device may further include: a bus, a communication interface 220 , an input device 230 and an output device 240 .
[0227] The processor 210, the memory 200, the communication interface 220, the input device 230 and the output device 240 are connected to each other via a bus.
[0228] A bus may include a pathway that transfers information between components of a computer system.
[0229] The processor 210 may be a general-purpose processor, such as a general-purpose central processing unit (CPU), a microprocessor, etc., or an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the scheme of the present invention. It may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0230] The processor 210 may include a main processor, and may also include a baseband chip, a modem, and the like.
[0231] The memory 200 stores a program for executing the technical solution of the present invention, and may also store an operating system and other key services. Specifically, the program may include a program code, and the program code includes a computer operation instruction. More specifically, the memory 200 may include a read-only memory (ROM), other types of static storage devices that can store static information and instructions, a random access memory (RAM), other types of dynamic storage devices that can store information and instructions, a disk storage, a flash, and the like.
[0232] The input device 230 may include a device for receiving data and information input by a user, such as a keyboard, a mouse, a camera, a scanner, a light pen, a voice input device, a touch screen, a pedometer, or a gravity sensor.
[0233] Output device 240 may include devices that allow information to be output to a user, such as a display screen, printer, speaker, etc.
[0234] The communication interface 220 may include any transceiver or the like to communicate with other devices or communication networks, such as Ethernet, Radio Access Network (RAN), Wireless Local Area Network (WLAN), etc.
[0235] The processor 210 executes the program stored in the memory 200 and calls other devices, which can be used to implement each step of any retrieval method provided in the above embodiments of the present application.
[0236] Exemplary computer program products and storage media
[0237] In addition to the above-mentioned methods and devices, an embodiment of the present application may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the retrieval method according to various embodiments of the present application described in any of the above-mentioned embodiments of this specification.
[0238] The computer program product may be written in any combination of one or more programming languages to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages, such as Java, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as an independent software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0239] In addition, the embodiment of the present application may also be a storage medium on which a computer program is stored. The computer program is executed by a processor to execute the steps of the retrieval method according to various embodiments of the present application described in any of the above embodiments of this specification, and specifically the following steps may be implemented:
[0240] Step 101, retrieving a target node related to the user input question from the nodes of the tree diagram.
[0241] Among them, the tree diagram is constructed based on the original data, and the hierarchical relationship between each node in the tree diagram is determined based on the original structure of the original data.
[0242] Step 102, generating candidate knowledge texts based on the hierarchical relationship between the target node and each node in the tree diagram.
[0243] Step 103: Determine the target retrieval text based on the candidate knowledge text.
[0244] Among them, the target retrieval text is used to guide the large model to generate answers corresponding to the user input questions.
[0245] For the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0246] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0247] The steps in the methods of each embodiment of the present application can be adjusted in order, combined and deleted according to actual needs, and the technical features recorded in each embodiment can be replaced or combined.
[0248] The modules and sub-modules in the devices and terminals in the various embodiments of the present application can be combined, divided and deleted according to actual needs.
[0249] In the several embodiments provided in the present application, it should be understood that the disclosed terminals, devices and methods can be implemented in other ways. For example, the terminal embodiments described above are only schematic, for example, the division of modules or submodules is only a logical function division, and there may be other division methods in actual implementation, for example, multiple submodules or modules can be combined or integrated into another module, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0250] The modules or submodules described as separate components may or may not be physically separated, and the components of the modules or submodules may or may not be physical modules or submodules, that is, they may be located in one place, or they may be distributed on multiple network modules or submodules. Some or all of the modules or submodules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0251] In addition, each functional module or submodule in each embodiment of the present application may be integrated into one processing module, or each module or submodule may exist physically separately, or two or more modules or submodules may be integrated into one module. The above-mentioned integrated modules or submodules may be implemented in the form of hardware or in the form of software functional modules or submodules.
[0252] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0253] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly by hardware, software units executed by a processor, or a combination of the two. The software units may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0254] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0255] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be 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 present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A search method, characterized in that: include: Retrieving a target node related to the user input question from the nodes of the tree diagram; wherein the tree diagram is constructed based on the original data, and the hierarchical relationship between the nodes in the tree diagram is determined based on the original structure of the original data; Generate candidate knowledge texts based on the hierarchical relationship between the target node and each node in the tree diagram; Based on the candidate knowledge text, a target retrieval text is determined; wherein the target retrieval text is used to guide the large model to generate an answer corresponding to the user input question.
2. The search method according to claim 1, characterized in that: The step of retrieving a target node related to the user input question from the nodes of the tree diagram includes: Determine a first vector of the user input question and a second vector corresponding to each node in the tree diagram; Based on the first vector and each of the second vectors, retrieving a first node related to the user input question from the nodes of the tree diagram; Based on the user input question, perform information retrieval based on text content on each node in the tree diagram, and determine a second node related to the user input question from the nodes in the tree diagram; Based on the first node and the second node, a target node related to the user input question is determined.
3. The search method according to claim 2, characterized in that: The step of performing text content-based information retrieval on each node in the tree diagram based on the user input question, and determining a second node related to the user input question from the nodes in the tree diagram, comprises: For any node in the tree diagram, perform the following operations: Determine the word frequency corresponding to each word in the user input question in any one of the nodes; Determine the inverse document frequency corresponding to each word in the user input question in the tree diagram; Determine a relevance score between the arbitrary node and the user input question based on each of the word frequencies and each of the inverse document frequencies; Based on the relevance scores corresponding to the nodes in the tree diagram, a second node related to the user input question is determined from the nodes in the tree diagram.
4. The search method according to claim 1, characterized in that: The generating of candidate knowledge texts based on the hierarchical relationship between the target node and each node in the tree diagram includes: For any untraversed target node, perform the following operations: Determine any one of the untraversed target nodes as the starting node of the traversal, traverse each first adjacent node adjacent to the any one of the untraversed target nodes, and determine the target node in each first adjacent node as the first intermediate node; Traverse each (i+1)th adjacent node adjacent to the i-th intermediate node, and determine the target node in each (i+1)th adjacent node as the (i+1)th intermediate node; wherein i is a positive integer; When the preset conditions are met, the traversal is stopped, and any untraversed target node, the first intermediate node and the (i+1)th intermediate node are sorted and spliced according to the hierarchical relationship between the nodes in the tree diagram to generate a candidate knowledge text; The preset conditions include that there is no target node among the (i+1)th adjacent nodes adjacent to the i-th intermediate node, and there is no target node among the nodes adjacent to the (i+1)th adjacent nodes.
5. The search method according to claim 1, characterized in that: The step of determining a target retrieval text based on the candidate knowledge text comprises: Determining the relevance between the user input question and each of the candidate knowledge texts; Based on the respective relevances, a target retrieval text is determined from the respective candidate knowledge texts.
6. The search method according to claim 5, characterized in that: One of the candidate knowledge texts is obtained by splicing based on at least one target node; The determining of the relevance between the user input question and each of the candidate knowledge texts includes: For any candidate knowledge text, perform the following operations: The target nodes of any candidate knowledge text obtained by splicing are sorted according to the relevance between the target nodes and the user input question by using various search methods to obtain the relevance sorting results corresponding to the various search methods; Determine the comprehensive relevance between any target node corresponding to any candidate knowledge text and the user input question based on the position of any target node corresponding to any candidate knowledge text in each of the relevance ranking results; Based on the comprehensive relevance between each target node of the any one candidate knowledge text and the user input question obtained by splicing, the relevance between the any one candidate knowledge text and the user input question is determined.
7. The search method according to claim 1, characterized in that: The method further comprises: Generate prompt words based on the target search text and the user input question; The prompt word is input into the large model to obtain the answer corresponding to the user input question output by the large model, wherein the prompt word is used to instruct the large model to generate the answer corresponding to the user input question based on the target search text.
8. The search method according to claim 1, characterized in that: The method further comprises: According to the various levels of titles in the original structure of the original data, the original data is segmented to obtain various text blocks; Based on each of the text blocks, determining each node in the tree diagram; Determine the hierarchical relationship between the nodes in the tree diagram based on the hierarchical relationship between the titles at each level in the original structure of the original data; The tree diagram is constructed based on the nodes in the tree diagram and the hierarchical relationships between the nodes in the tree diagram.
9. The search method according to claim 8, characterized in that: Determining each node in the tree diagram based on each of the text blocks includes: Determine a text block whose text length is less than or equal to a text length threshold as a node in the dendrogram; Based on the semantic similarity between adjacent sentences in the text block whose text length is greater than the text length threshold, the text block whose text length is greater than the text length threshold is segmented to obtain various sub-text blocks; Determine each sub-text block as a node in the tree diagram; The text length of the sub-text block is less than or equal to a text length threshold.
10. A search device, characterized in that: include: A retrieval unit, used to retrieve target nodes related to the user input question from the nodes of the tree diagram; wherein the tree diagram is constructed based on the original data, and the hierarchical relationship between the nodes in the tree diagram is determined based on the original structure of the original data; A generating unit, configured to generate candidate knowledge texts based on the hierarchical relationship between the target node and each node in the tree diagram; A processing unit is used to determine a target retrieval text based on the candidate knowledge text; wherein the target retrieval text is used to guide the large model to generate an answer corresponding to the user input question.
11. An electronic device, characterized in that: including memory and processor; The memory is connected to the processor and is used to store programs; The processor is used to implement the retrieval method according to any one of claims 1 to 9 by running the program in the memory.
12. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, the retrieval method according to any one of claims 1 to 9 is implemented.
13. A computer program product, characterized in that The method comprises computer program instructions, which, when executed by a processor, enable the processor to perform the retrieval method according to any one of claims 1 to 9.