Query rewriting method and query rewriting device

By obtaining the keywords and their domain information in the query statement, and obtaining synonyms for the specified domain from the inter-word relationship ontology associated with the domain information, rewriting the query statement to reduce content in non-specified domains, the problem of the query results in the prior art containing content that does not meet the user's expectations is solved, and the recall accuracy is improved.

CN119577119AInactive Publication Date: 2025-03-07SHENZHEN HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD

Patent Information

Application Number
CN202510138922.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-08
Publication Date
2025-03-07
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing word embedding method is easy to select synonyms that are not specified when rewriting the query, resulting in the query results containing content that does not meet the user's expectations, reducing the recall accuracy.

Method used

By obtaining the keywords and their domain information in the query statement, obtain synonyms for the specified domain from the inter-word relationship ontology associated with the domain information, and rewrite the query statement to reduce the content of non-specified domains.

Benefits of technology

It improves the recall accuracy of query results, reduces the appearance of content related to non-specified fields in query results, and enhances the accuracy of query rewriting.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119577119A_ABST
    Figure CN119577119A_ABST
Patent Text Reader

Abstract

Embodiments of the invention disclose a query rewriting method and apparatus, which can search for synonyms of keywords in a specified field according to field information, so that a semantic drift phenomenon can be reduced, and contents of other fields in a query result can be reduced. The method comprises the steps that after a query rewriting device obtains a keyword from a query statement from a user, field information of the keyword is determined, then synonyms of the keyword are obtained from an inter-word relation ontology associated with the field information, and the query statement is rewritten into a target query statement comprising the synonyms.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of cloud computing, and in particular to a query rewriting method and a query rewriting device. Background Art

[0002] Word embedding technology, also known as word vector technology, is a technology that converts words into vectors in the field of natural language processing.

[0003] Currently, there is a word embedding method that is roughly as follows: obtain a query statement and the document corresponding to the query statement, use the document as the context of the query statement, convert both the query statement and the context into word vectors, select the word to be changed and its synonyms based on the vector similarity, replace the word to be changed in the query statement with a synonym, and use the rewritten query statement to perform the query.

[0004] However, the above method is prone to selecting synonyms that are not in the specified field, so after rewriting the query statement, results that do not meet the user's expectations will be found. Summary of the invention

[0005] The present application provides a query rewriting method, which searches for synonyms of keywords in a specified field based on field information, thereby reducing the situation of rewriting query statements with synonyms from other fields and reducing content related to other fields in query results, thereby improving recall accuracy.

[0006] A first aspect provides a query rewriting method, the method comprising: a query rewriting device obtains keywords from a query statement from a user, determines domain information of the keywords, obtains synonyms of the keywords from an inter-word relationship ontology associated with the domain information, and rewrites the query statement into a target query statement including the synonyms. The domain information includes a domain or a scene in the domain.

[0007] According to this implementation, synonyms of keywords can be found in the specified field according to the field information, which can reduce the situation of rewriting query statements with synonyms from other fields and reduce content related to other fields in the query results, thereby improving the recall accuracy.

[0008] In some possible implementations, the query rewriting device obtains synonyms of keywords from the inter-word relationship ontology associated with the domain information, including: after the query rewriting device obtains the target vector space associated with the domain information, determining the word vector distance between the word vector of the keyword and other word vectors in the target vector space, arranging all the calculated vector distances in order from small to large, and determining the n synonyms of the keyword as the words corresponding to the first n word vector distances. The original vector space includes the initial word vectors of all words in the inter-word relationship ontology associated with the domain information.

[0009] Since the word vector distance of non-synonymous word pairs in the vector of the target vector space is greater than the word vector distance of non-synonymous word pairs in the original vector space and the word vector distance of synonymous word pairs in the vector of the target vector space is less than the word vector distance of synonymous word pairs in the original vector space, compared with obtaining synonyms based on the vector distance in the original vector space, the vector distance in the target vector space can better distinguish synonyms and non-synonymous words, reduce the probability of taking non-synonymous words as synonyms, improve the accuracy of obtaining synonyms, and thus improve the accuracy of query rewriting.

[0010] In some possible implementations, the query rewriting method of the present application also includes: after the query rewriting device obtains n documents from the knowledge base according to n target query statements, it determines the first target document according to the maximum similarity value among the similarity values ​​of the n documents and the keywords, inputs the first target document into the large language model, and outputs the first query result through the large language model. The target query statement corresponds to the synonyms of the keyword one by one. The similarity values ​​of the n documents and the keywords can reflect the relevance of the document to the user's expected results. The document corresponding to the maximum similarity value can be considered to be the document that best meets the user's expectations. After it is input into the large language model, the large language model can generate an answer that best meets the user's expectations based on the document.

[0011] In some possible implementations, the query rewriting method of the present application further includes: the query rewriting device obtains a second target document from the knowledge base according to the query statement, and when the similarity value between the first target document and the keyword is greater than the similarity value between the second target document and the keyword, the query rewriting device is triggered to input the first target document into the large language model. In this way, the query result corresponding to the rewritten query statement (i.e., the first target document) and the query result corresponding to the query statement before the rewriting can be compared, and it can be determined whether the rewriting improves the query accuracy based on the comparison result.

[0012] In some possible implementations, the query rewriting device obtains synonyms of keywords from the inter-word relationship ontology associated with the domain information, including: the query rewriting device obtains a target vector space associated with the domain information, determines the word vector distance between the word vector of the keyword and other word vectors in the target vector space, determines the minimum word vector distance from the determined word vector distances, and then determines the synonyms of the keyword as the word corresponding to the minimum word vector distance. The original vector space includes the initial word vectors of all words in the inter-word relationship ontology associated with the domain information.

[0013] Since the word vector distance of non-synonymous word pairs in the vector of the target vector space is greater than the word vector distance of non-synonymous word pairs in the original vector space and the word vector distance of synonymous word pairs in the vector of the target vector space is less than the word vector distance of synonymous word pairs in the original vector space, compared with obtaining synonyms based on the vector distance in the original vector space, the vector distance in the target vector space can better distinguish synonyms and non-synonymous words, reduce the probability of taking non-synonymous words as synonyms, improve the accuracy of obtaining synonyms, and thus improve the accuracy of query rewriting.

[0014] In some possible implementations, the query rewriting method of the present application also includes: the query rewriting device obtains a first group of documents from the knowledge base according to the target query statement, determines the maximum similarity value among the similarity values ​​of all documents in the first group of documents and the keywords, and then inputs the document corresponding to the maximum similarity value into the large language model, and outputs the second query result through the large language model. In this way, the similarity value between the document and the keyword can be obtained, which can reflect the relevance of the document to the user's expected result. The document corresponding to the maximum similarity value can be considered as the document that best meets the user's expectations. After inputting it into the large language model, the large language model can generate the answer that best meets the user's expectations based on the document.

[0015] In some possible implementations, the query rewriting method of the present application further includes: the query rewriting device obtains a second set of documents from the knowledge base according to the target query statement; for each document in the second set of documents, the query rewriting device obtains the similarity value between the document and the keyword and the perplexity value of the document, determines the score of the document according to the similarity value between the document and the keyword and the perplexity value of the document, inputs the document corresponding to the highest score into the large language model, and outputs the third query result through the large language model. Since the score is positively correlated with the similarity value between the document and the keyword and negatively correlated with the score and the perplexity value of the document, it is possible to select documents that meet the user's expectations and ensure the accuracy and generalization ability of the document.

[0016] In some other possible implementations, the target vector space is obtained by processing the original vector space using a target embedding model, and the target embedding model is used to increase the word vector distance of non-synonymous word pairs and reduce the word vector distance of synonymous word pairs.

[0017] In some other possible implementations, the target embedding model is also used to reduce the distance difference between the word vector distance of the word pair in the target vector space and the word vector distance of the word pair in the original vector space.

[0018] In some possible implementations, before the query rewriting device obtains synonyms of keywords from the inter-word relationship ontology associated with the domain information, the query rewriting method of the present application also includes: the query rewriting device obtains the inter-word relationship ontology associated with the domain information, trains an initial embedding model based on the word vectors of all words in the inter-word relationship ontology associated with the domain information, inputs the word vectors of all words in the inter-word relationship ontology into the trained target embedding model, and outputs the target vector space associated with the domain information through the target embedding model.

[0019] In some possible implementations, the query rewriting method of the present application further includes: after the query rewriting device replaces the synonyms of the target query sentence with the target synonyms input by the user, the inter-word relationship ontology associated with the domain information is updated to the inter-word relationship ontology including the keywords and the target synonyms. In this way, the inter-word relationship ontology associated with the domain information can be updated according to the synonyms rewritten by the user, and the target embedding model can be retrained based on the updated inter-word relationship ontology, thereby updating the target vector space and improving the ability to distinguish between non-synonymous words and synonyms.

[0020] In the first aspect or a possible implementation of the first aspect, the domain information is a domain, and the inter-word relationship ontology associated with the domain information includes a general synonym set, a general antonym set, a domain synonym set, and a domain non-synonym set.

[0021] In the first aspect or a possible implementation of the first aspect, the domain information is a scene in the domain, and the inter-word relationship ontology associated with the domain information includes a general synonym set, a general antonym set, a scene synonym set, and a scene non-synonym set.

[0022] The second aspect provides a query rewriting device, which includes a query rewriting module, which is used to obtain keywords from a query statement from a user, determine the domain information of the keywords, obtain synonyms of the keywords from an inter-word relationship ontology associated with the domain information, and rewrite the query statement into a target query statement including the synonyms.

[0023] In some possible implementations, the query rewriting module is specifically used to obtain a target vector space associated with domain information, determine the word vector distance between the keyword's word vector and other word vectors in the target vector space; arrange the determined word vector distances in order from small to large; and determine that the n synonyms of the keyword are the words corresponding to the first n word vector distances.

[0024] In some possible implementations, the query rewriting device also includes a first recall module and a first model processing module. The first recall module is used to obtain n documents from a knowledge base according to n target query statements, and determine a first target document according to a maximum similarity value among the similarity values ​​between the n documents and the keywords; the first model processing module is used to input the first target document into a large language model, and output a first query result through the large language model.

[0025] In some possible implementations, the first recall module is also used to obtain a second target document from the knowledge base according to the query statement; when the similarity value between the first target document and the keyword is greater than the similarity value between the second target document and the keyword, the first model processing module is triggered to input the first target document into the large language model.

[0026] In some possible implementations, the query rewriting module is specifically used to obtain a target vector space associated with domain information, determine the word vector distance between the keyword's word vector and other word vectors in the target vector space, and determine the keyword's synonyms as words corresponding to the minimum word vector distance.

[0027] In some possible implementations, the query rewriting device also includes a second recall module and a second model processing module, the second recall module is used for the query rewriting device to obtain a first group of documents from a knowledge base according to a target query statement; determine the maximum similarity value among the similarity values ​​between all documents in the first group of documents and the keyword; the second model processing module is used to input the document corresponding to the maximum similarity value into the large language model, and output the second query result through the large language model.

[0028] In some possible implementations, the query rewriting device also includes a third recall module and a third model processing module, and the third recall module is also used to obtain a second group of documents from the knowledge base according to the target query statement; for each document in the second group of documents, obtain the similarity value between the document and the keyword and the confusion value of the document; determine the score of the document according to the similarity value between the document and the keyword and the confusion value of the document; the third model processing module is used to input the document corresponding to the highest score into the large language model, and output the third query result through the large language model.

[0029] In some possible implementations, the query rewriting device also includes a construction module, which is used to obtain an inter-word relationship ontology associated with domain information; train an initial embedding model based on the word vectors of all words in the inter-word relationship ontology associated with domain information; input the word vectors of all words in the inter-word relationship ontology into the trained target embedding model, and output a target vector space associated with the domain information through the target embedding model.

[0030] In some possible implementations, the query rewriting module is also used to replace the synonyms of the target query statement with the target synonyms input by the user; the query rewriting device also includes an updating module, which is used to update the inter-word relationship ontology associated with the domain information to an inter-word relationship ontology including keywords and target synonyms.

[0031] For the explanation of terms in the second aspect, the specific steps executed by each module and the beneficial effects, please refer to the corresponding description of the first aspect.

[0032] A third aspect provides a computing device cluster. The computing device cluster includes at least one computing device, and the at least one computing device includes at least one processor and at least one memory. The at least one processor and the at least one memory communicate with each other. The at least one processor is used to execute instructions stored in the at least one memory, so that the computing device or the computing device cluster executes the query rewriting method as described in the first aspect or any implementation of the first aspect.

[0033] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, wherein the instructions instruct a computing device or a computing device cluster to execute the query rewriting method described in the first aspect or any one of the implementations of the first aspect.

[0034] In a fifth aspect, the present application provides a computer program product comprising instructions, which, when executed on a computing device or a computing device cluster, enables the computing device or the computing device cluster to execute the query rewriting method described in the first aspect or any one of the implementations of the first aspect.

[0035] Based on the implementations provided in the above aspects, this application can also be further combined to provide more implementations. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1 A schematic diagram of an online search scenario in an embodiment of the present application; Figure 2 Another schematic diagram of an online search scenario in an embodiment of the present application; Figure 3 Another schematic diagram of an online search scenario in an embodiment of the present application; Figure 4 A schematic diagram of the domain word relationship ontology in the embodiment of the present application; Figure 5 A schematic diagram of obtaining the scene word relationship ontology in an embodiment of the present application; Figure 6 A flow chart of the query rewriting method in the embodiment of the present application; Figure 7A flow chart for obtaining a target vector space in an embodiment of the present application; Figure 8 A schematic diagram of changing the word vector distance in an embodiment of the present application; Fig. 9 Another schematic diagram of changing the word vector distance in an embodiment of the present application; Fig.10 Another flow chart of the query rewriting method in the embodiment of the present application; Fig.11 Another flow chart of the query rewriting method in the embodiment of the present application; Fig.12 Another flow chart of the query rewriting method in the embodiment of the present application; Fig.13 A structural diagram of a query rewriting device in an embodiment of the present application; Fig.14 A structural diagram of a computing device in an embodiment of the present application; Fig.15 A structural diagram of a computing device cluster in an embodiment of the present application; Fig.16 A structural diagram of a computing device cluster in an embodiment of the present application. DETAILED DESCRIPTION

[0037] First, let us introduce some terms involved in this application: A document may include files and / or file fragments, including but not limited to any of the following: files in DOC format, files in DOCX format, files in TXT format, files in portable document format (PDF), files in XLS format, files in hypertext markup language (HTML), and files in extensible markup language (XML). File fragments may be, but are not limited to, file summaries, one or more paragraphs of a file, one or more sentences of a file, or a combination of the above.

[0038] The inter-word relationship ontology includes words from different sources such as general synonyms, general antonyms, synonym groups in specific fields, antonyms in specific fields, or synonym combinations in specific scenarios, antonym combinations in specific scenarios, etc., among which the synonym sets or non-synonym sets can be used as training sets for embedding models. The domain inter-word relationship ontology is an ontology that includes synonym and antonym relationships between entities in a specific domain. Its corresponding graph data structure records nodes such as domains, scenarios, synonym combinations, antonym combinations, words, documents, and the relationships between nodes. The scene inter-word relationship ontology is an ontology that includes synonym and antonym relationships between entities in a specific scenario. Its corresponding graph data structure records nodes such as scenarios, synonym combinations, antonym combinations, words, documents, and the relationships between nodes.

[0039] Synonyms refer to words with the same or similar meanings. Some word pairs are synonyms in some scenarios, but not in other scenarios. For example, apple and banana are synonyms in the field of fruits, but not in the field of mobile phones. A synonym pair includes two words and the two words are synonyms. Non-synonyms in this application include antonyms, appositives, drift words, etc. A non-synonymous pair includes two words and the two words are not synonyms.

[0040] Query rewriting is to modify the original query content into content that is more relevant to user needs. Specifically, by expanding, filtering or replacing the search terms in the original query content, the modified query content is closer to the query intent, thereby searching for more knowledge documents that meet expectations. Inputting knowledge documents into a large language model (LLM) can optimize the output results of the large language model, namely retrieval-augmented generation (RAG).

[0041] A large language model (LLM) is a deep learning model trained using a large amount of text data. It can perform language tasks such as spelling checking, grammar correction, translation, dialogue generation, and content recommendation, such as the GPT model and the LLaMA model.

[0042] The original query content is usually the query content input by the user, which includes one or more query statements, and one or more query statements can be rewritten. For each query statement, one or more words of the query statement can be rewritten. For the word to be rewritten, it can be rewritten into a synonym or a synonym sentence of the word.

[0043] The word embedding representation method is a query rewriting method based on the distribution hypothesis. It vectorizes the query content or subsequent user behaviors related to the query. For example, the access content sequence in a session in an online service is regarded as a document, and each query content is regarded as a word in the document. After the word vector is obtained using document to vector (word2vec), the word embedding model trained with the word vector is used for query, or the content recalled by the user through the query is combined as context, and the word embedding model trained with the word vector of the context is used for query. The word vector obtained by the query can be used for computing tasks such as calculating text similarity, predicting similarity and other indicators, or for unsupervised clustering tasks, to obtain words or sentences that can be used for rewriting. The word embedding model of this application can be referred to as an embedding model.

[0044] Latent Dirichlet allocation (LDA) is a topic modeling technique. Topic modeling is a natural language processing (NLP) technique that applies unsupervised learning on large text datasets to generate a set of term summaries derived from these documents. These terms can represent the main-topic set of the entire corpus, so LDA can be used to identify command entities. Named entity recognition (NER) is a technique for identifying command entities. Named entities generally refer to entities with specific meanings or strong referentiality in text, usually including names of people, places, institutions, dates and times, proper nouns, etc. Proper nouns include entities in specific fields, such as book titles, song titles, journal titles, etc.

[0045] The query rewriting method of the present application can be applied to online search scenarios or local search scenarios. Online search scenarios may include but are not limited to online artificial intelligence (AI) services, life services, ticketing queries, advertising, e-commerce platform queries, etc. Local search scenarios include local database queries.

[0046] See also Figure 1 In one embodiment, the online search scenario includes a terminal 111, a terminal 112 and a cloud service platform 120, and the cloud service platform 120 includes a query rewriting module, a recall module and a model processing module.

[0047] It should be understood that the number of terminals in the online search scenario and the number of cloud service platforms are not limited to Figure 1The terminal may be, but is not limited to, a user device such as a mobile phone, a personal computer, a tablet computer, a wearable device, or a car computer. The cloud service platform 120 is a platform that provides infrastructure, software, and services. It provides users with various resources and services through the network. The services of the cloud service platform 120 include retrieval, computing, storage, network, development tools, database, monitoring, etc. The cloud service platform 120 is usually provided by a cloud service provider and can be flexibly expanded and configured according to user needs.

[0048] Taking the terminal 111 as an example, in one embodiment, after the terminal 111 sends a question to the cloud service platform 120, the cloud service platform 120 can feed back the answer to the question to the terminal 111. Specifically, the query rewriting module is used to rewrite the words in the question according to the target vector space, the recall module is used to retrieve documents according to the rewritten question, and the model processing module is used to generate answers according to the retrieved documents and send the answers to the terminal 111. The process of the interaction between the terminal 112 and the cloud service platform 120 can refer to the process of the interaction between the terminal 111 and the cloud service platform 120.

[0049] See also Figure 2 In another embodiment, the online search scenario includes a terminal 211, a terminal 212, and a cloud service platform 220. Both the terminal 211 and the terminal 212 include a query rewriting module. After the query rewriting module of the terminal 211 rewrites the question, the rewritten question is sent to the cloud service platform 220. The cloud service platform 220 retrieves documents according to the rewritten question. The model processing module is used to generate answers according to the retrieved documents and send the answers to the terminal 211. The process of interaction between the terminal 212 and the cloud service platform 220 can refer to the process of interaction between the terminal 211 and the cloud service platform 220.

[0050] See also Figure 3 In another embodiment, the online search scenario includes a terminal 311, a terminal 312, and a cloud service platform 320. After the terminal 311 sends a question to the cloud service platform 320, the cloud service platform 320 rewrites the question, retrieves a document based on the rewritten question, and then sends the document to the terminal 311.

[0051] In some local search scenarios, the method of rewriting local server queries is similar to the method of rewriting cloud service platform queries in online search scenarios. In other local search scenarios, the method of terminal query rewriting is similar to the method of terminal query rewriting in online search scenarios, which will not be repeated here. In the above embodiments, the query statement is a question. It should be understood that the query statement can also be in the form of a task or a picture, etc. This application does not limit the form of the query statement.

[0052] For the problem that synonyms in other fields are not synonyms in the current field, but are easily used as synonyms in the current field for query rewriting, the present application can pre-set the inter-word relationship associated with the field information, obtain the synonyms of the current field in the inter-word relationship ontology associated with the field information, and then use the synonyms of the current field for query rewriting, thereby reducing the situation of erroneous rewriting. The field information of the present application can be a field or a scene in a field. When the field information is a field, the inter-word relationship ontology associated with the field information includes a general synonym set, a general antonym set, a field synonym set, and a field non-synonym set. When the field information is a scene in a field, the inter-word relationship ontology associated with the field information includes a general synonym set, a general antonym set, a scene synonym set, and a scene non-synonym set.

[0053] The following is an introduction to the method of obtaining domain synonyms and domain non-synonyms. In an optional embodiment, LDA is used to perform entity recognition on historical query statements and historical query results, and entities are added to the domain-related inter-word relationship ontology (i.e., domain inter-word relationship ontology) based on the recognized entities and the relationship between the entities and the domain. The historical query results include but are not limited to target documents and recommended documents retrieved according to historical query statements. For example, a group of topics are obtained from the document using the LDA method, and words in the same field in these topics are added to the domain inter-word relationship ontology, and word pairs with synonymous relationships are used as synonymous combinations, and word pairs with antonymous relationships are used as antonymous combinations.

[0054] Figure 4 is a schematic diagram of the ontology of the relationship between domain terms. Figure 4 As shown, in one embodiment, the entities of the domain word relationship ontology include domain 1, scene 1, scene 2, synonym combination 1, synonym combination 2, antonym combination 1, word a, word b, word c, word d, word e, document a and document b. The entity relationship includes the parent-child relationship between domain 1 and scene 1, the parent-child relationship between domain 1 and scene 2, the parent-child relationship between scene 1 and synonym combination 1, the parent-child relationship between scene 1 and synonym combination 2, and the parent-child relationship between scene 1 and antonym combination 1. The connection relationship between synonym combination 1, word a and word c indicates that word a and word c are synonyms, the connection relationship between synonym combination 2, word b and word c indicates that word b and word c are synonyms, and the connection relationship between antonym combination 1, word d and word e indicates that word d and word e are antonyms. The sources of words can also be associated. For example, the association between word a and document a indicates that the source of word a is document a, and the association between word c and document b indicates that the source of word c is document b.

[0055] The following is an introduction to the method of obtaining scene synonyms and scene non-synonyms. In another optional embodiment, LDA is used to perform entity recognition on historical query sentences and historical query results, and entities are added to the scene-related word relationship ontology (i.e., scene word relationship ontology) based on the recognized entities and the relationship between the entities and the scenes. For example, a group of topics are obtained from the document using the LDA method, and words of the same scene in these topics are added to the scene word relationship ontology, and word pairs with synonymous relationships are used as synonymous combinations, and word pairs with antonymous relationships are used as antonymous combinations.

[0056] Figure 5 A schematic diagram for obtaining the ontology of the relationship between scene words. Figure 5 As shown, in another embodiment, the first query statement is: What if the verification code for picking up the express is entered incorrectly? The second query statement is: What if the verification code for picking up the express is entered incorrectly? The recall content includes: 1. According to the normal operation process, click the yellow button of "Pick up the express" on the main interface of the express cabinet. 2. Recommended document: [Re-obtain the pickup code] Go to the express cabinet and click the button of "Re-enter the pickup code".

[0057] The entities identified from the first query statement, the second query statement, and the recalled content using LDA include: for the first query statement and the recalled content, "pick up the express", "pick up the item", and their synonymous relationships can be identified, thereby constructing synonym combination 1, which includes "pick up the express" and "pick up the item". For the first query statement and the second query statement, "input" and "press" and their synonymous relationships can be identified using LDA, thereby constructing synonym combination 2. For the second query statement and the recommended document, "input" and "input" and their synonymous relationships can be identified using LDA, and they are added to synonym combination 2, which includes "input", "press", and "input".

[0058] It should be noted that the number of fields, the number of scenarios, the number of synonymous combinations, and the number of antonymous combinations in this application are not limited to Figure 4 or Figure 5 As shown. For the domain inter-word relationship ontology or scene inter-word relationship ontology, operations such as adding, modifying or deleting entities or entity relationships can be performed. The entity recognition method can be but is not limited to the LDA method.

[0059] The following is a detailed description of the process of obtaining synonyms of the current field in the inter-word relationship ontology associated with the field information, and then using the synonyms of the current field to rewrite the query. Figure 6 In one embodiment, the query rewriting method of the present application includes the following steps: S601: Acquire keywords from a query statement from a user.

[0060] Optionally, S601 includes: obtaining documents from a knowledge base according to a query statement from a user, determining the weights of all words in the query statement and the documents, sequentially selecting words from the query statement, when the weight of the selected word is greater than the average weight, taking the selected word as a candidate keyword, then removing stop words from all candidate keywords, and taking the remaining candidate keywords as keywords. When the weight of the selected word in the query statement is less than or equal to the average weight, taking the selected word as an invalid word.

[0061] Another option is that S601 includes: obtaining documents from a knowledge base according to a query statement from a user, determining the weights of all words in the documents, sequentially selecting words from the query statement, when the weight of the selected word is greater than the average weight, taking the selected word as a candidate keyword, then removing stop words from all candidate keywords, and taking the remaining candidate keywords as keywords. When the weight of the selected word in the query statement is less than or equal to the average weight, taking the selected word as an invalid word.

[0062] In S601, the term frequency–inverse document frequency (TF-IDF) method can be specifically used to determine the weights of all words in the query statement and the documents. This can remove words with a relatively low relevance to the query intent from the query statement and select keywords with a relatively high relevance to the query intent, thereby improving the query accuracy. Among them, stop words refer to high-frequency functional words or words without practical meaning, such as prepositions, conjunctions, articles, or pronouns. For example, "的", "地", "得", "a", "the", "is", "are", "and", "of", etc. When the query statement is a structured query statement, the database can also be directly queried using the structured query statement.

[0063] S602. Determine the domain information of the keywords.

[0064] Specifically, match the keywords with the domain information in a preset domain information set to determine the domain information corresponding to the keywords. The domain information can be a domain or a scenario in the domain.

[0065] S603. Obtain the synonyms of the keywords from the ontology of word relationships associated with the domain information.

[0066] When the domain information is a domain, the ontology of word relationships associated with the domain information includes a general synonym set, a general antonym set, a domain synonym set, and a domain non-synonym set. When the domain information is a scenario in the domain, the ontology of word relationships associated with the domain information includes a general synonym set, a general antonym set, a scenario synonym set, and a scenario non-synonym set. Among them, the number of synonyms of the keywords can be one or more.

[0067] S604: rewrite the query statement into a target query statement including synonyms.

[0068] Optionally, S604 includes: replacing the keyword of the query statement with a synonym of the keyword. The number of keywords in the query statement can be one or more. Another option, S604 includes: adding the synonym to the query statement, thereby obtaining a target query statement including the synonym and the keyword.

[0069] In this embodiment, synonyms of keywords are searched in the specified field based on the field information. This can reduce the situation where query statements are rewritten with synonyms from non-specified fields (i.e., the semantic drift phenomenon), thereby reducing the content of non-specified fields in the query results, thereby improving the recall accuracy.

[0070] The above query rewriting method can directly obtain synonyms from the inter-word relationship ontology of domain information. The following introduces another query rewriting method. This method searches for the word vector of the synonym based on the word vector of the keyword in the target vector space corresponding to the inter-word relationship ontology associated with the domain information, and then determines the synonym based on the word vector of the synonym. First, the method of obtaining the target vector space is introduced. Figure 7 In one embodiment, the query rewriting method of the present application includes the following steps: S701. Obtaining the inter-word relationship ontology associated with domain information.

[0071] The specific process of the query rewriting device obtaining the inter-word relationship entity associated with the domain information can refer to the corresponding records in the previous text.

[0072] S702: Train the initial embedding model into a target embedding model according to the original vector space corresponding to the inter-word relationship ontology.

[0073] The original vector space includes the initial word vectors of all words in the inter-word relationship ontology associated with domain information. The initial embedding model can be trained as a target embedding model based on the original vector space and the loss function.

[0074] In an alternative embodiment, the loss function of the embedding model is Satisfies the following formula: ; ; ; in, Used to increase the word vector distance of non-synonymous word pairs. Including common antonyms and domain non-synonyms in the inter-word relationship ontology associated with domain information. for The u-th prediction vector in for The w-th prediction vector in , where u and w are integer variables. for and The vector distance of . is the minimum distance between non-synonymous words in an ideal state. When cosine similarity is used to represent vector distance, It can be but not limited to 1. , which is used to determine function bounds. Used to reduce the word vector distance of synonym pairs. Including common synonyms and domain synonyms in the inter-word relationship ontology associated with domain information. for The u-th prediction vector in for The w-th prediction vector in . is the maximum distance between synonyms in an ideal state. When cosine similarity is used to represent vector distance, It can be but not limited to 0. The vector distance can be represented by but not limited to cosine similarity, Euclidean distance or Manhattan distance. is a weight coefficient, and its value can be set according to actual conditions, and is not limited in this application. It should be understood that the u-th prediction vector corresponds to the u-th vector in the original vector space, and the w-th prediction vector corresponds to the w-th vector in the original vector space. Specifically, the u-th vector can be input into the embedding model, and the u-th prediction vector can be output through the embedding model.

[0075] The target embedding model obtained by training based on the loss function of this embodiment can increase the word vector distance of non-synonymous word pairs and reduce the word vector distance of synonymous word pairs.

[0076] In another alternative embodiment, for example, the loss function of the embedding model is Satisfies the following formula: ; ; ; ; i and j are integer variables. is the total number of vectors in the original vector space. It is a vector subset of the original vector space. The specific size can be set according to actual conditions and is not limited in this application. is the vector distance between the i-th prediction vector and the j-th prediction vector, is the vector distance between the i-th vector and the j-th vector in the original vector space. It should be understood that the i-th prediction vector corresponds to the i-th vector in the original vector space. Specifically, the i-th vector can be input into the embedding model, and the i-th prediction vector can be output through the embedding model.

[0077] The present application may specifically use, but is not limited to, the gradient descent method to train the embedding model. When training the embedding model, When the value of is the minimum value, the training is completed. The target embedding model obtained by training based on the loss function of this embodiment can also reduce the distance difference between the word vector distance of the word pair in the target vector space and the word vector distance of the word pair in the original vector space, so that the target vector space is bent toward the original vector space to maintain the original semantic information. Optionally, the vectors in the original vector space and the target vector space are both word vectors.

[0078] S703: Input the original vector space into the target embedding model, and output the target vector space associated with the domain information through the target embedding model.

[0079] The word vector distance of non-synonymous word pairs in the target vector space is greater than the word vector distance of non-synonymous word pairs in the original vector space, and the word vector distance of synonymous word pairs in the vector of the target vector space is less than the word vector distance of synonymous word pairs in the original vector space. It should be understood that a non-synonymous word pair includes two words and the two words are not synonyms. A synonymous word pair includes two words and the two words are synonyms.

[0080] In this embodiment, the inter-word relationship ontology associated with the domain information and the target vector space corresponding to the inter-word relationship ontology can be constructed. Compared with the original vector space, the word vector distance of the synonymous word pair in the target vector space is small and the word vector distance of the non-synonymous word pair is large. Therefore, in the target vector space, the word vector of the synonym is searched according to the word vector of the keyword, and then the synonym corresponding to the word vector of the synonym is determined, which can reduce the situation of using non-synonymous words in this field as synonyms, so as to improve the accuracy of query rewriting.

[0081] Secondly, the embedding model obtained by training according to the gradient descent method in this application is a lightweight model, and its model parameter amount is less than or equal to one hundred thousandth of the model parameter amount of the BERT model. Compared with pre-trained models such as the BERT model, the training cost of the embedding model of this application is lower. Due to the small number of model parameters, the computational complexity and inference speed of this application when running the embedding model are smaller.

[0082] See also Figure 8In one embodiment, taking the mobile phone field as an example, Huawei is the antonym of apple, apple is the synonym of iphone, and banana is the drift word of apple. In the original vector space, the vector distance between apple and banana is recorded as the original vector distance 1, and the vector distance between Huawei and iphone is recorded as the original vector distance 2. After the original vector space is transformed by the embedding model, in the target vector space, the vector distance of antonyms (such as Huawei and apple) is increased, the vector distance of drift words (such as apple and banana) is increased, the vector distance of synonyms (such as apple and iphone) is reduced, and the vector distance between Huawei and iphone is maintained (that is, the original vector distance 2).

[0083] The present application may also adopt a segmented training embedding model. For example, firstly, the embedding model is trained using a general synonym library, a general antonym library, a synonym set in multiple fields, and a non-synonym set in multiple fields, and then the embedding model is adjusted using rewritten words associated with domain information. The adjustment method may be, but is not limited to, supervised fine-tuning (SFT). SFT is a technology for adjusting the model. It uses labeled data to retrain the pre-trained model to make the model better suited to specific tasks or application scenarios.

[0084] In an alternative embodiment, the loss function of the embedding model is Satisfies the following formula: ; ; ; ; ; It is a vector space including keywords and their rewritten words. is the target vector space. When, based on K Adjust the embedding model. There is no need to adjust the embedding model. is a weight coefficient, and its value can be set according to actual conditions and is not limited in this application.

[0085] In this way, the embedding model can be corrected based on the keywords and synonyms provided by users, so that the embedding model can be more accurately applied to the specified field or scenario.

[0086] See also Fig. 9, in another embodiment, in the original vector space, the vector distance between an apple and a banana is denoted as the original vector distance 1, and the vector distance between Huawei and iPhone is denoted as the original vector distance 2. The original vector space further includes word vectors of scene synonyms, where the scene synonyms include the mobile phone market and Huawei, the mobile phone market and the apple, and the mobile phone market and iPhone. After the original vector space is transformed by the embedding model, in the target vector space, the vector distance of antonyms (such as Huawei and the apple) is increased, the vector distance of drifting words (such as the apple and the banana) is increased, the vector distance of synonyms (such as the apple and iPhone) is decreased, and the vector distance between Huawei and iPhone (i.e., the original vector distance 2) is maintained. The vector distance of scene synonyms is decreased, for example, the vector distance between the mobile phone market and Huawei, the vector distance between the mobile phone market and the apple, and the vector distance between the mobile phone market and iPhone are decreased.

[0087] The method for query rewriting based on the synonym vectors in the target vector space is introduced below. Please refer to Fig.10 , in one embodiment, the query rewriting method of the present application includes the following steps: S1001. Obtain keywords from the query statement from the user.

[0088] Optionally, S1001 includes: obtaining a document from the knowledge base according to the query statement from the user, determining the weights of all the words in the query statement and the document, when the weight of the selected word in the query statement is greater than the average weight, taking the selected word in the query statement as a candidate keyword, and then removing the stop words from the candidate keywords, and taking the remaining candidate keywords as keywords. When the weight of the selected word in the query statement is less than the average weight, the selected word is taken as an invalid word.

[0089] Another option is that S1001 includes: obtaining a document from the knowledge base according to the query statement from the user, determining the weights of all the words in the document, and the query rewriting device selects candidate keywords from the query statement, and the weight of the candidate word is greater than the average weight of all the words; the query rewriting device removes the stop words from the candidate keywords and takes the remaining candidate keywords as keywords.

[0090] Specifically, the term frequency–inverse document frequency (TF-IDF) method can be used to determine the weights of all the words in the query statement and the document. This can remove the words irrelevant to the query intention from the query statement and select the keywords related to the query intention, thereby improving the query accuracy. Stop words refer to high-frequency functional words or words without practical meaning, such as prepositions, conjunctions, articles, or pronouns. For example, "de", "di", "de", "a", "the", "is", "are", "and", "of", etc. The number of keywords in the query statement can be one or more.

[0091] S1002: Determine the domain information of the keyword.

[0092] Specifically, the LDA method can be used to process the query statement to determine the field with the highest relevance to the query statement, which is the field to which the keyword belongs, or to determine the scene with the highest relevance to the query statement, which is the scene to which the keyword belongs.

[0093] S1003: Obtain a target vector space associated with domain information.

[0094] The target vector space can be found in Figure 7 The corresponding description of the illustrated embodiment.

[0095] S1004: Determine the word vector distance between the word vector of the keyword and other word vectors in the target vector space.

[0096] The word vector distance can be cosine distance (i.e., cosine similarity), Euclidean distance, or Manhattan distance, and can also be expressed in other ways, which is not limited in this application.

[0097] S1005. Arrange the determined word vector distances in ascending order.

[0098] S1006: Determine the n synonyms of the keyword as words corresponding to the first n word vector distances.

[0099] It should be understood that the word vectors of the n synonyms correspond to the smallest n word vector distances, and other sorting methods (such as sorting from large to small, and then selecting the last n word vector distances) or other methods can also be used to select the smallest n word vector distances. n is a positive integer, and the value of n can be set according to actual conditions, and this application does not limit it.

[0100] S1007: Obtain target query sentences corresponding to n synonyms.

[0101] The target query statement corresponds to the synonyms of the keyword one by one. Optionally, S1007 includes: replacing the keyword of the query statement with the synonym of the keyword. Another option, S1007 includes: adding the synonym to the query statement, thereby obtaining the target query statement including the synonym and the keyword.

[0102] S1008. Obtain n documents from the knowledge base according to the n target query statements.

[0103] The knowledge base includes at least one of factual knowledge, rules or strategies. The content of the knowledge base can be but is not limited to vectors.

[0104] S1009: Determine a first target document according to a maximum similarity value among similarity values ​​between the n documents and the keyword.

[0105] Specifically, a document corresponding to the maximum similarity value (ie, the first target document) is selected from the n documents, and it can be considered as the document closest to the user's expectation among the n documents.

[0106] S1010: Acquire a second target document from the knowledge base according to the query statement.

[0107] Specifically, one or more documents are obtained from the knowledge base according to the query statement. When one document is obtained, the document is used as the second target document. When multiple documents are obtained, the similarity values ​​of the multiple documents and the keyword are compared, and the document corresponding to the maximum similarity value is used as the second target document.

[0108] S1011. Is the similarity value between the first target document and the keyword greater than the similarity value between the second target document and the keyword? If yes, execute S1012; if no, execute S1013.

[0109] When the similarity value between the first target document and the keyword is greater than the similarity value between the second target document and the keyword, it indicates that rewriting can improve the query results, and the first target document is closer to the user's expectations than the second target document. When the similarity value between the first target document and the keyword is less than the similarity value between the second target document and the keyword, it indicates that rewriting cannot improve the query results, and the second target document is closer to the user's expectations than the first target document. At this time, the rewritten query statement and the first target document can be ignored, and the second target document corresponding to the original query statement is used as the input of the large language model to ensure that the output result is as close to the user's expectations as possible.

[0110] S1012: Input the first target document into the large language model, and output the query result through the large language model.

[0111] S1013: Input the second target document into the large language model, and output the query result through the large language model.

[0112] In this embodiment, the word vectors of synonyms are searched in the target vector space corresponding to the domain information according to the word vectors of the keywords, so that the word vectors of synonyms can be quickly searched.

[0113] Secondly, compared with directly searching for synonyms in the inter-word relationship ontology associated with domain information, synonyms are determined based on their word vectors in the target vector space. The synonyms obtained in this way are more accurate, can reduce the semantic drift phenomenon, and can reduce content related to non-specified fields in the query results, thereby improving the recall accuracy.

[0114] Thirdly, by comparing the query results before and after the rewriting, the document that is closer to the user's expectations can be selected, which can improve or maintain the accuracy of the document. In addition, by processing the document using a large language model, a summary of the document can be generated for easy reference by the user.

[0115] This application can also use other methods to obtain the target document from the document, for example, combining the similarity value and the document perplexity to score the document, and obtaining the target document based on the score. Fig.10 In the illustrated embodiment, S1009 may not be executed, and the following steps may be executed: for each of the n documents, the similarity value between the document and the keyword and the perplexity value of the document are obtained; the score of the document is determined according to the similarity value between the document and the keyword and the perplexity value of the document, the document corresponding to the highest score is input into the large language model, and the query result is output through the large language model.

[0116] Specifically, the document can be input into the large language model, and the perplexity of the document can be calculated based on the output of the large language model. Since the score is positively correlated with the similarity between the document and the keyword and negatively correlated with the perplexity of the document, it is possible to select documents that meet user expectations and ensure the accuracy and generalization ability of the document.

[0117] For ease of understanding, the query rewriting method of the present application is introduced below using another specific example. Fig.11 In another embodiment, the query rewriting method of the present application includes the following steps: S1101, extracting synonym sets and non-synonymous word sets in the target domain.

[0118] In this embodiment, a general synonym library, a general antonym library, a synonym set of multiple fields, and a non-synonym set of multiple fields can be pre-configured, and then the synonym set and non-synonym set of the target field are extracted from the general synonym library, the general antonym library, the synonym set of multiple fields, and the non-synonym set of multiple fields. The synonym set of the target field includes but is not limited to the general synonym library and the synonym set of the target field. The non-synonym set of the target field includes but is not limited to the general antonym library and the antonym set of the target field.

[0119] S1102. Use LDA to label entities in the target domain.

[0120] Specifically, the LDA method is used to obtain a set of topics from the synonym set and non-synonymous word set of the target domain. In these topics, the words of the target domain are added to the target domain word relationship ontology, and the word pairs with synonymous relationships are taken as synonymous combinations, and the word pairs with antonymous relationships are taken as antonymous combinations.

[0121] S1103. Filter using SimRank++.

[0122] Among them, SimRank++ is a collaborative filtering algorithm that can measure the similarity of entities in context. The historical recall content is the document obtained based on the historical query statement. According to SimRank++, the content with a similarity value higher than the similarity threshold can be filtered out from the historical recall content. The similarity threshold can be set according to the actual situation. It should be understood that the method of filtering the historical recall content can be but not limited to SimRank++.

[0123] S1104. Extract entities using BERT.

[0124] Bidirectional encoder representation from transformers (BERT) is a pre-trained model for natural language processing tasks that can extract entities from documents. Specifically, BERT is used to extract entities from content filtered by SimRank++, recalled content in a session, keywords, and user-rewritten words. A session refers to a temporary information exchange process between devices, in which at least one device saves current state information and historical information for communication. After a terminal establishes a session with a network device, the terminal can display historical query statements and receive recalled content sent by the network device. Recalled content in a session refers to query results received from a network device in a session, such as a file summary, a file paragraph, a file, etc. After the user enters a query statement, the keywords of the query statement are modified, and the modified words are the user-rewritten words.

[0125] S1105. Use LDA to label entities in the target domain.

[0126] Specifically, the LDA method is used to obtain a set of topics from the entities extracted by BERT. In these topics, the words in the target field are added to the target field word relationship ontology, and the word pairs with synonymous relationships are taken as synonymous combinations, and the word pairs with antonymous relationships are taken as antonymous combinations.

[0127] S1106. Construct the target domain inter-word relationship ontology.

[0128] Specifically, the entity of the target domain is marked according to S1102 and S1105, and the relationship ontology between words in the target domain can be constructed.

[0129] S1107. Train the embedding model.

[0130] Optionally, the words of the target domain inter-word relationship ontology are converted into word vectors, and the word vectors of the target domain inter-word relationship ontology (i.e., the original vector space) are used as the training set of the embedding model, and the training set is trained using an unsupervised training algorithm to obtain the embedding model. It should be understood that the training method can be but is not limited to an unsupervised training algorithm. The loss function used for training can refer to the loss function recorded above.

[0131] S1108. Obtain a target vector space of a target domain.

[0132] Specifically, the original vector space is input into the embedding model, and the target vector space of the target domain is output through the embedding model.

[0133] S1109: The user inputs a query statement.

[0134] S1110, pre-processing (including classification and slicing).

[0135] The categories of query statements include structured query statements and unstructured query statements. By classifying query statements, it can be determined whether the query statement belongs to a structured query statement or an unstructured query statement. When a query statement includes multiple sub-query statements, the query statement can be sliced, each slice being a sub-query statement. Querying based on multiple sub-query statements can improve retrieval performance. Sub-query statements can also be classified to further improve retrieval performance. When a query statement does not include multiple sub-query statements, slicing is not required.

[0136] S1111. Get the first five documents according to the query statement.

[0137] For structured query statements, you can directly use the structured query statements to search the knowledge base or other databases to obtain documents. For unstructured query statements, you can extract keywords from the unstructured query statements, and then use the keywords to search the knowledge base or other databases to obtain documents. When the query statement includes multiple sub-query statements, you can use the multiple sub-query statements to perform retrieval respectively.

[0138] S1112. Is the similarity between the first five documents and the keyword lower than expected? If yes, execute S1113; if no, execute S1121.

[0139] The similarity between the first 5 documents and the keyword is lower than expected, indicating that the first 5 documents do not meet the user's expectations, and the query statement needs to be rewritten to execute S1113 to S1120. The similarity between the first 5 documents and the keyword is higher than expected, indicating that the first 5 documents meet the user's expectations.

[0140] S1113. Obtain the word weights of the query statement and the first five documents.

[0141] Specifically, the TF-IDF method can be used to determine the weights of all words in the query statement and the first five documents as well as the average word weight.

[0142] S1114. Filter out candidate keywords based on average word weights.

[0143] When the weight of the selected word is greater than the weight average, the selected word is used as a candidate keyword. When the weight of the selected word is less than or equal to the weight average, the selected word is ignored.

[0144] S1115. Remove stop words from candidate keywords.

[0145] Stop words refer to high-frequency functional words or words without actual meaning. Removing stop words can screen out keywords that are highly relevant to the query intent and remove words with low relevance to the query intent from the query statement, thereby improving the query accuracy.

[0146] S1116. Keyword matching field.

[0147] S1117. Determine the word vector of the keyword in the target vector space.

[0148] The keywords are matched with the domains in the preset domain set, and when the keywords match the target domain, the word vector of the keywords is determined in the target vector space of the target domain.

[0149] S1118. Determine the word vectors of the first five synonyms in the target vector space.

[0150] In the target vector space, calculate the word vector distance from the keyword's word vector to other word vectors, sort the calculation results from small to large, and the word vectors corresponding to the first n word vector distances are the word vectors of the first five synonyms.

[0151] S1119. Determine the target query sentences corresponding to the first five synonyms.

[0152] The query statements are rewritten using five synonyms to obtain five target query statements.

[0153] S1120. Determine a first target document from the documents corresponding to the five query statements.

[0154] The similarity values ​​between the documents corresponding to the five query statements and the keywords are calculated respectively, and the document corresponding to the maximum similarity value is selected from the five documents as the first target document.

[0155] S1121. Determine a second target document from the first five documents.

[0156] If the similarity between the first five documents and the keyword is higher than or equal to the expected value, the second target document is determined from the first five documents.

[0157] S1122. Is the similarity between the first target document and the keyword greater than the similarity between the second target document and the keyword? If so, the first target document is input into the large language model, and the large language model outputs the query result. If not, the second target document is input into the large language model, and the large language model outputs the query result.

[0158] Among them, S1101 to S1108 are the process of obtaining the target vector space offline. S1109 to S1122 are the process of online query rewriting. The number of documents and the number of synonyms are not limited to Fig.11 As shown, the specific settings can be made according to the actual situation.

[0159] In this embodiment, the word vectors of synonyms are searched in the target vector space of the target field according to the word vectors of the keywords, so that the word vectors of synonyms in the specified field can be quickly searched.

[0160] Secondly, compared with directly searching for synonyms in the inter-word relationship ontology associated with domain information, synonyms are determined based on their word vectors in the target vector space. The synonyms obtained in this way are more accurate, can reduce the semantic drift phenomenon, and can reduce content related to non-specified fields in the query results, thereby improving the recall accuracy.

[0161] Thirdly, by comparing the query results before and after the rewriting, the document that is closer to the user's expectations can be selected, which can improve or maintain the accuracy of the document. In addition, by processing the document using a large language model, a summary of the document can be generated for easy reference by the user.

[0162] Fig.10 The embodiment shown can determine the rewriting effect based on the documents obtained from multiple queries. The following is an introduction to the method of rewriting queries based on the most similar synonyms. Fig.12 In another embodiment, the query rewriting method of the present application includes the following steps: S1201. Acquire keywords from a query statement from a user.

[0163] S1202: Determine the domain information of the keyword.

[0164] S1203: Obtain a target vector space associated with domain information.

[0165] S1204: Determine the word vector distance between the word vector of the keyword and other word vectors in the target vector space.

[0166] S1201~S1204 are similar to S1001~S1004, and the details can be found in the previous records.

[0167] S1205. Determine the synonyms of the keyword as the words corresponding to the minimum word vector distance.

[0168] S1206: Obtain a target query sentence including synonyms.

[0169] S1207. Obtain a first group of documents from the knowledge base according to the target query statement.

[0170] S1208: Determine a first target document according to a maximum similarity value among similarity values ​​between all documents in the first group of documents and the keyword.

[0171] It can be seen from S1205 to S1208 that the word corresponding to the minimum word vector distance is usually the synonym closest to the keyword. Based on it, documents that meet user expectations can be obtained, and the document corresponding to the maximum similarity value (i.e., the first target document) can be considered as the document closest to user expectations.

[0172] S1209: Acquire a second target document from the knowledge base according to the query statement.

[0173] S1210. Is the similarity value between the first target document and the keyword greater than the similarity value between the second target document and the keyword? If yes, execute S1211; if no, execute S1212.

[0174] S1211. Input the first target document into the large language model, and output the query result through the large language model.

[0175] S1212: Input the second target document into the large language model, and output the query result through the large language model.

[0176] S1209~S1212 are similar to S1010~S1013.

[0177] In this embodiment, the word vectors of synonyms are searched in the target vector space corresponding to the domain information according to the word vectors of the keywords, so that the word vectors of synonyms can be quickly searched.

[0178] Secondly, compared with directly searching for synonyms in the inter-word relationship ontology associated with domain information, synonyms are determined in the target vector space based on their word vectors. The synonyms obtained in this way are more accurate, which can reduce the situation of rewriting query statements with synonyms of non-specified fields, and can reduce the content related to non-specified fields in the query results, thereby improving the recall accuracy.

[0179] Thirdly, the documents that are close to the user's expectations can be quickly found based on the synonyms with the highest similarity. Moreover, the large language model can be used to process the documents and generate summary content of the documents for easy reference by users.

[0180] This application can also use other methods to obtain the target document from the document, for example, combining the similarity value and the document perplexity to score the document, and obtaining the target document based on the score. Fig.12 In the illustrated embodiment, S1207 to S1212 may not be executed, and the following steps may be executed: a second group of documents is obtained from the knowledge base according to the target query statement; for each document in the second group of documents, a similarity value between the document and the keyword and a perplexity value of the document are obtained; a score of the document is determined according to the similarity value between the document and the keyword and the perplexity value of the document, the document corresponding to the highest score is input into the large language model, and a third query result is output through the large language model.

[0181] Specifically, the document can be input into the large language model, and the perplexity of the document can be calculated based on the output of the large language model. Since the score is positively correlated with the similarity between the document and the keyword and negatively correlated with the perplexity of the document, it is possible to select documents that meet user expectations and ensure the accuracy and generalization ability of the document.

[0182] The following is an introduction to the hardware for implementing the query rewriting method in this application. Fig.13 In one embodiment, the query rewriting device 1300 of the present application includes a query rewriting module 1301, a recall module 1302 and a model processing module 1303, wherein the query rewriting module 1301 is used to obtain keywords from a query statement from a user; determine the domain information of the keywords; obtain synonyms of the keywords from the inter-word relationship ontology associated with the domain information; and rewrite the query statement into a target query statement including the synonyms.

[0183] As an example of a software functional unit, the query rewrite module 1301 may include code running on a computing instance. Among them, the computing instance may include at least one of a physical host (computing device), a virtual machine, and a container. Further, the above computing instance may be one or more. For example, the query rewrite module 1301 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed in the same region (region) or in different regions. Furthermore, the multiple hosts / virtual machines / containers used to run the code may be distributed in the same availability zone (AZ) or in different AZs, each AZ including one data center or multiple data centers with close geographical locations. Among them, usually a region may include multiple AZs.

[0184] Similarly, multiple hosts / virtual machines / containers used to run the code can be distributed in the same virtual private cloud (VPC) or in multiple VPCs. Usually, a VPC is set up in a region. For cross-region communication between two VPCs in the same region and between VPCs in different regions, a communication gateway needs to be set up in each VPC to achieve interconnection between VPCs through the communication gateway.

[0185] As an example of a hardware functional unit, the query rewriting module 1301 may include at least one computing device, such as a server, etc. Alternatively, the query rewriting module 1301 may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0186] The multiple computing devices included in the query rewrite module 1301 can be distributed in the same region or in different regions. The multiple computing devices included in the query rewrite module 1301 can be distributed in the same AZ or in different AZs. Similarly, the multiple computing devices included in the query rewrite module 1301 can be distributed in the same VPC or in multiple VPCs. The multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.

[0187] In other embodiments, the query rewriting module 1301 may be used to perform Figure 6-7 as well as Figure 10 to Figure 12 In any step of the query rewriting method shown in the figure, the recall module 1302 can be used to perform Figure 6-7 as well as Figure 10 to Figure 12 The model processing module 1303 can be used to perform any step performed by the query rewriting device in the query rewriting method shown in FIG. Figure 6-7 as well as Figure 10 to Figure 12Any step executed by the query rewriting device in the query rewriting method shown in the figure, the steps implemented by the query rewriting module 1301, the recall module 1302 and the model processing module 1303 can be specified as needed, and the query rewriting module 1301, the recall module 1302 and the model processing module 1303 can be implemented respectively. Figure 6-7 as well as Figure 10 to Figure 12 The different steps in the query rewriting method shown are used to implement the full functionality of the query rewriting device. It should be understood that when the query rewriting module 1301, the recall module 1302 or the model processing module 1303 implements all the steps performed by the query rewriting device, the other two modules are optional. Figure 1 to Figure 3 In the embodiment shown, the query rewrite module can realize the function of the recall module 1302. Figure 1 to Figure 3 In the embodiment shown, the recall module can realize the function of the model processing module 1303. Figure 1 to Figure 3 Functions of the model processing module in the illustrated embodiment.

[0188] In some embodiments, the query rewriting device 1300 also includes a construction module, which is used to obtain an inter-word relationship ontology associated with domain information; train an initial embedding model based on the word vectors of all words in the inter-word relationship ontology associated with domain information; input the word vectors of all words in the inter-word relationship ontology into the trained target embedding model, and output a target vector space associated with the domain information through the target embedding model.

[0189] In some embodiments, the query rewriting device 1300 also includes an update module, and the query rewriting module 1301 is also used to replace the synonyms of the target query statement with the target synonyms input by the user, and the update module is used to update the inter-word relationship ontology associated with the domain information to an inter-word relationship ontology including keywords and target synonyms.

[0190] The present application also provides a computing device 1400. Fig.14 As shown, in one embodiment, the computing device 1400 includes: a bus 1402, a processor 1404, a memory 1406, and a communication interface 1408. The processor 1404, the memory 1406, and the communication interface 1408 communicate with each other via the bus 1402. It should be understood that the present application does not limit the number of processors and memories in the computing device 1400.

[0191] The bus 1402 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.14 The bus 1402 may include a path for transmitting information between various components of the computing device 1400 (eg, the memory 1406, the processor 1404, and the communication interface 1408).

[0192] The processor 1404 may include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP). The processor may include one or more processing cores.

[0193] The memory 1406 may include a volatile memory, such as a random access memory (RAM). The memory 1406 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD) or a solid state drive (SSD). In some embodiments, the memory 1406 stores executable program code, and the processor 1404 executes the executable program code to implement the functions of the aforementioned query rewriting module 1301, the recall module 1302 and the model processing module 1303, thereby implementing the above-mentioned query rewriting method.

[0194] The communication interface 1408 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 1400 and other devices or communication networks.

[0195] The embodiment of the present application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smart phone.

[0196] like Fig.15 As shown, the computing device cluster includes at least one computing device 1400. The memory 1406 in one or more computing devices 1400 in the computing device cluster may store the same instructions for executing the query rewriting method.

[0197] It should be noted that the memory 1406 in different computing devices 1400 in the computing device cluster can store different instructions, which are respectively used to execute part of the functions of the query rewriting device. That is, the instructions stored in the memory 1406 in different computing devices 1400 can implement the functions of the query rewriting module 1301, the recall module 1302 and the model processing module 1303, such as Fig.16 shown.

[0198] The embodiment of the present application also provides a computer program product including instructions. The computer program product may be software or a program product including instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computing device, the at least one computing device executes the query rewriting method of the present application. The computer program product may be client software, network software, or an application called through an interface.

[0199] The embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center that contains one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk). The computer-readable storage medium includes instructions that instruct the computing device to execute the query rewriting method of the present application.

[0200] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0201] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the protection scope of the technical solutions of the embodiments of the present invention.

Claims

1. A query rewriting method, characterized in that: The method is applied to a query rewriting device, the query rewriting device is used to rewrite a query statement, and the method includes: The query rewriting device obtains keywords from a query statement from a user; The query rewriting device determines the domain information of the keyword; The query rewriting device obtains synonyms of the keyword from the inter-word relationship ontology associated with the domain information; The query rewriting device rewrites the query sentence into a target query sentence including the synonyms.

2. The method according to claim 1, characterized in that The query rewriting device obtains synonyms of the keyword from the inter-word relationship ontology associated with the domain information, including: The query rewriting device obtains a target vector space associated with the domain information, wherein the word vector distance of non-synonymous word pairs in the target vector space is greater than the word vector distance of the non-synonymous word pairs in the original vector space, and the word vector distance of synonymous word pairs in the vector of the target vector space is less than the word vector distance of the synonymous word pairs in the original vector space, and the original vector space includes initial word vectors of all words in the inter-word relationship ontology associated with the domain information; The query rewriting device determines the word vector distance between the word vector of the keyword and other word vectors in the target vector space; The query rewriting device arranges the determined word vector distances in order from small to large; The query rewriting device determines that n synonyms of the keyword are words corresponding to the first n word vector distances, where n is an integer greater than 1.

3. The method according to claim 2, characterized in that The method further comprises: The query rewriting device obtains n documents from a knowledge base according to n target query statements, wherein the target query statements correspond one-to-one to the synonyms of the keywords; The query rewriting device determines a first target document according to a maximum similarity value among similarity values ​​between the n documents and the keyword; The query rewriting device inputs the first target document into a large language model, and outputs a first query result through the large language model.

4. The method according to claim 3, characterized in that The method further comprises: The query rewriting device acquires a second target document from the knowledge base according to the query statement; When the similarity value between the first target document and the keyword is greater than the similarity value between the second target document and the keyword, the query rewriting device is triggered to input the first target document into a large language model.

5. The method according to claim 1, characterized in that: The query rewriting device obtains synonyms of the keyword from the inter-word relationship ontology associated with the domain information, including: The query rewriting device obtains a target vector space associated with the domain information, wherein the word vector distance of non-synonymous word pairs in the target vector space is greater than the word vector distance of the non-synonymous word pairs in the original vector space, and the word vector distance of synonymous word pairs in the vector of the target vector space is less than the word vector distance of the synonymous word pairs in the original vector space, and the original vector space includes initial word vectors of all words in the inter-word relationship ontology associated with the domain information; The query rewriting device determines the word vector distance between the word vector of the keyword and other word vectors in the target vector space; The query rewriting device determines the synonyms of the keyword as words corresponding to the minimum word vector distance.

6. The method according to claim 5, characterized in that The method further comprises: The query rewriting device obtains a first set of documents from a knowledge base according to the target query statement; The query rewriting device determines the maximum similarity value among the similarity values ​​between all documents in the first group of documents and the keyword; The query rewriting device inputs the document corresponding to the maximum similarity value into a large language model, and outputs a second query result through the large language model.

7. The method according to claim 5, characterized in that The method further comprises: The query rewriting device obtains a second set of documents from a knowledge base according to the target query statement; For each document in the second group of documents, the query rewriting device obtains a similarity value between the document and a keyword and a perplexity value of the document; The query rewriting device determines a score of the document according to a similarity value between the document and a keyword and a perplexity value of the document, wherein the score is positively correlated with the similarity value between the document and the keyword and negatively correlated with the perplexity value of the document; The query rewriting device inputs the document corresponding to the highest score into the large language model, and outputs the third query result through the large language model.

8. The method according to any one of claims 2 to 7, characterized in that The target vector space is obtained by processing the original vector space using a target embedding model, and the target embedding model is used to increase the word vector distance of non-synonymous word pairs and reduce the word vector distance of synonymous word pairs.

9. The method according to claim 8, characterized in that The target embedding model is also used to reduce the distance difference between the word vector distance of the word pair in the target vector space and the word vector distance of the word pair in the original vector space.

10. The method according to claim 8, characterized in that Before the query rewriting device obtains the synonyms of the keyword from the inter-word relationship ontology associated with the domain information, the method further includes: The query rewriting device obtains the inter-word relationship ontology associated with the domain information; The query rewriting device trains the initial embedding model into a target embedding model according to the original vector space corresponding to the inter-word relationship ontology; The query rewriting device inputs the original vector space into the target embedding model, and outputs the target vector space associated with the domain information through the target embedding model.

11. The method according to any one of claims 1 to 7, characterized in that The method further comprises: The query rewriting device replaces the synonyms of the target query sentence with target synonyms input by the user; The query rewriting device updates the inter-word relationship ontology associated with the domain information to an inter-word relationship ontology including the keyword and the target synonym.

12. The method according to any one of claims 1 to 7, characterized in that The domain information is a domain, and the inter-word relationship ontology associated with the domain information includes a general synonym set, a general antonym set, a domain synonym set, and a domain non-synonym set.

13. The method according to any one of claims 1 to 7, characterized in that The domain information is a scene in a domain, and the inter-word relationship ontology associated with the domain information includes a general synonym set, a general antonym set, a scene synonym set, and a scene non-synonym set.

14. A query rewriting device, characterized in that: include: A query rewriting module, used to obtain keywords from a query statement from a user; Determining domain information of the keyword; Acquire synonyms of the keyword from the inter-word relationship ontology associated with the domain information; and rewrite the query statement into a target query statement including the synonyms.

15. The device according to claim 14, characterized in that The query rewriting module is specifically used to obtain a target vector space associated with the domain information, wherein the word vector distance of non-synonymous word pairs in the vector of the target vector space is greater than the word vector distance of the non-synonymous word pairs in the original vector space and the word vector distance of synonymous word pairs in the vector of the target vector space is less than the word vector distance of the synonymous word pairs in the original vector space, and the original vector space includes the initial word vectors of all words in the inter-word relationship ontology associated with the domain information; Determine the word vector distance from the word vector of the keyword to other word vectors in the target vector space; arrange the determined word vector distances in order from small to large; determine the n synonyms of the keyword as the words corresponding to the first n word vector distances, where n is an integer greater than 1.

16. The device according to claim 15, characterized in that The device also includes: A first recall module is used to obtain n documents from a knowledge base according to n target query statements, wherein the target query statements correspond to synonyms of the keyword one by one; and determine a first target document according to a maximum similarity value among similarity values ​​between the n documents and the keyword; The first model processing module is used to input the first target document into a large language model, and output a first query result through the large language model.

17. The device according to claim 16, characterized in that The first recall module is also used to obtain a second target document from the knowledge base according to the query statement; when the similarity value between the first target document and the keyword is greater than the similarity value between the second target document and the keyword, the first model processing module is triggered to input the first target document into the large language model.

18. The device according to claim 14, characterized in that The query rewriting module is specifically used to obtain a target vector space associated with the domain information, wherein the word vector distance of non-synonymous word pairs in the vector of the target vector space is greater than the word vector distance of the non-synonymous word pairs in the original vector space and the word vector distance of synonymous word pairs in the vector of the target vector space is less than the word vector distance of the synonymous word pairs in the original vector space, and the original vector space includes the initial word vectors of all words in the inter-word relationship ontology associated with the domain information; Determine the word vector distance between the word vector of the keyword and other word vectors in the target vector space; determine the synonyms of the keyword as the word corresponding to the minimum word vector distance.

19. The device according to claim 18, characterized in that The device also includes: A second recall module, used for the query rewriting device to obtain a first group of documents from the knowledge base according to the target query statement; determine the maximum similarity value among the similarity values ​​of all documents in the first group of documents and the keyword; The second model processing module inputs the document corresponding to the maximum similarity value into the large language model, and outputs the second query result through the large language model.

20. The device according to claim 18, characterized in that The device also includes: A third recall module is used to obtain a second group of documents from the knowledge base according to the target query statement; for each document in the second group of documents, the query rewriting device obtains a similarity value between the document and a keyword and a perplexity value of the document; the query rewriting device determines a score of the document according to the similarity value between the document and the keyword and the perplexity value of the document, wherein the score is positively correlated with the similarity value between the document and the keyword and negatively correlated with the perplexity value of the document; The third model processing module inputs the document corresponding to the highest score into the large language model, and outputs the third query result through the large language model.

21. The device according to any one of claims 15 to 20, characterized in that The target vector space is obtained by processing the original vector space using a target embedding model, and the loss function of the target embedding model is used to increase the word vector distance of non-synonymous word pairs and reduce the word vector distance of synonymous word pairs.

22. The device according to claim 21, characterized in that The target embedding model is also used to reduce the distance difference between the word vector distance of the word pair in the target vector space and the word vector distance of the word pair in the original vector space.

23. The device according to claim 21, characterized in that The device also includes: A construction module is used to obtain an inter-word relationship ontology associated with domain information; train an initial embedding model based on the word vectors of all words in the inter-word relationship ontology associated with the domain information; input the word vectors of all words in the inter-word relationship ontology into the trained target embedding model, and output a target vector space associated with the domain information through the target embedding model.

24. The device according to any one of claims 14 to 20, characterized in that The query rewriting module is also used to replace the synonyms of the target query sentence with target synonyms input by the user; The device also includes: An updating module is used to update the inter-word relationship ontology associated with the domain information to an inter-word relationship ontology including the keyword and the target synonym.

25. The device according to any one of claims 14 to 20, characterized in that The domain information is a domain, and the inter-word relationship ontology associated with the domain information includes a general synonym set, a general antonym set, a domain synonym set, and a domain non-synonym set.

26. The device according to any one of claims 14 to 20, characterized in that The domain information is a scene in a domain, and the inter-word relationship ontology associated with the domain information includes a general synonym set, a general antonym set, a scene synonym set, and a scene non-synonym set.

Citation Information

Patent Citations

  • Method for replacing synonyms according to scenes and comparing standard word groups according to scene classification

    CN107590124A

  • Query statement rewriting method and device

    CN110969024A

  • Automatic vectorization model construction method for assisting text2sql

    CN118861083A

  • RF-powered backscatter cognitive radio network system and action mode selection method using the same

    KR1020220021846A

  • Modifying computerized searches through the generation and use of semantic graph data models

    US11263277B1

Cited By

  • Method and device for processing user query command based on large model

    CN120448617A

  • Information distribution method and device, electronic equipment and storage medium

    CN120596720A

  • Query method and electronic equipment

    CN120705290A