A retrieval method, electronic device, storage medium and program product
By vectorizing user queries and performing multi-dimensional retrieval, the problem of insufficient semantic understanding in existing question-answering systems has been solved, resulting in higher retrieval accuracy and coverage, and improved user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA SOUTHERN AIRLINES DIGITAL TECHNOLOGY (GUANGDONG) CO LTD
- Filing Date
- 2026-01-26
- Publication Date
- 2026-06-02
AI Technical Summary
Existing question-answering retrieval systems have weak semantic understanding capabilities when faced with massive amounts of unstructured text data, making it difficult to handle synonyms and contextual dependencies, resulting in low retrieval accuracy and impacting user experience and service efficiency.
By vectorizing the initial query input by the user, combining dense and sparse vector retrieval techniques, and integrating keyword exact matching and semantic fuzzy matching, a second candidate answer is generated, breaking through the limitations of word matching and improving the system's generalized retrieval capability.
It significantly improves the accuracy and coverage of question-and-answer retrieval, ensures the relevance and precision of search results, and enhances user experience and service efficiency.
Smart Images

Figure CN122132423A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a retrieval method, electronic device, storage medium, and program product. Background Technology
[0002] In today's information-saturated era, enterprises face significant challenges in managing massive amounts of unstructured text data and efficiently utilizing knowledge. This is especially true in application scenarios such as intelligent customer service, enterprise knowledge bases, and online support platforms, where user inquiries are becoming increasingly diverse and semantically complex.
[0003] Current question-answering retrieval systems widely use search engines based on traditional relational databases (such as MySQL) or basic keyword matching. These systems primarily rely on exact keyword matching or simple fuzzy matching algorithms to respond to user queries.
[0004] However, current retrieval systems suffer from weak semantic understanding and poor generalization performance, making it difficult to handle real-world scenarios such as synonyms and contextual dependencies. This results in low retrieval accuracy and inaccurate responses, severely impacting user experience and service efficiency. Summary of the Invention
[0005] This application provides a retrieval method, electronic device, storage medium, and program product for enhancing the semantic understanding of user queries and improving retrieval accuracy.
[0006] In a first aspect, this application provides a retrieval method, comprising: retrieving a first database based on an initial query statement input by a user to obtain a first candidate answer, the first database including multiple question-answer pairs; vectorizing the initial query statement to obtain a first vectorized query statement; retrieving a second database based on the first vectorized query statement to obtain a second candidate answer, the second candidate answer including multiple vectorized question-answer pairs; and obtaining an answer to the query statement based on the first candidate answer and the second candidate answer.
[0007] The technical solution provided in this application offers at least the following benefits: First, it retrieves data from a first database based on the initial query input by the user. Then, by vectorizing the initial query and retrieving data from a second database based on the first vectorized query, it can understand the user's query intent semantically based on the vectorized results, overcoming the limitations of word matching and presenting question-answer pairs that are semantically similar to the user's question but have different expressions as second candidate answers, significantly improving the system's generalized retrieval capability. Finally, the final answer to the query is determined based on the first and second candidate answers, enabling the system to simultaneously integrate the advantages of precise keyword matching and semantic fuzzy matching. This significantly improves the coverage and overall retrieval quality of questions and answers while ensuring relevance, thereby increasing retrieval accuracy.
[0008] One possible implementation involves extracting keywords from the initial query statement; searching a first database based on the keywords to obtain a first candidate answer; and the question-answer pair corresponding to the first candidate answer includes the keywords.
[0009] Another possible implementation involves the following steps: the first vectorized query statement includes a dense vectorized query statement and a sparse vectorized query statement; a dense vector retrieval is performed on the second database based on the dense vectorized query statement to obtain dense vector retrieval results; a sparse vector retrieval is performed on the second database based on the sparse vectorized query statement to obtain sparse vector retrieval results; and a second candidate answer is obtained based on the dense vector retrieval results and the sparse vector retrieval results.
[0010] Another possible implementation involves using a weighted sorter to determine the weights of dense vector retrieval results and sparse vector retrieval results. The weights reflect the importance of either the dense or sparse vector retrieval results. Based on the weights of the dense and sparse vector retrieval results, a second candidate answer is obtained.
[0011] Another possible implementation is to extract keywords from the initial query statement; vectorize the keywords; and search the second database based on the vectorized keywords and the first vectorized query statement to obtain the second candidate answer.
[0012] Another possible implementation involves semantically expanding the initial query statement to obtain an expanded query statement; the expanded query statement is semantically similar to the initial query statement but expressed differently; the expanded query statement is then vectorized to obtain a second vectorized query statement; based on the first and second vectorized query statements, a search is performed on the second database to obtain a second candidate answer.
[0013] Another possible implementation is to deduplicate the first and second candidate answers to obtain deduplicated candidate answers; score the deduplicated candidate answers; and determine the answer to the query statement based on the score results.
[0014] Secondly, this application provides a retrieval device, comprising: a retrieval module and a processing module; the retrieval module is used to retrieve a first database based on an initial query statement input by a user, and obtain a first candidate answer; the processing module is used to perform vectorization processing on the initial query statement, and obtain a first vectorized query statement; the retrieval module is further used to retrieve a second database based on the first vectorized query statement, and obtain a second candidate answer; the processing module is further used to obtain an answer to the query statement based on the first candidate answer and the second candidate answer.
[0015] One possible implementation is that the processing module is also used to extract keywords from the initial query statement; to search the first database based on the keywords to obtain a first candidate answer; and the question-answer pair corresponding to the first candidate answer includes the keywords.
[0016] Another possible implementation is that the first vectorized query statement includes a dense vectorized query statement and a sparse vectorized query statement; the retrieval module is also used to perform dense vector retrieval on the second database based on the dense vectorized query statement to obtain dense vector retrieval results; perform sparse vector retrieval on the second database based on the sparse vectorized query statement to obtain sparse vector retrieval results; and obtain a second candidate answer based on the dense vector retrieval results and the sparse vector retrieval results.
[0017] Another possible implementation is that the processing module is also used to employ a weighted sorter to determine the weights of the dense vector retrieval results and the sparse vector retrieval results; the weights are used to reflect the importance of the dense vector retrieval results or the sparse vector retrieval results; and based on the weights of the dense vector retrieval results and the sparse vector retrieval results, a second candidate answer is obtained.
[0018] Another possible implementation involves a processing module that extracts keywords from the initial query statement; vectorizes the keywords; and retrieves a second database based on the vectorized keywords and the first vectorized query statement to obtain a second candidate answer.
[0019] Another possible implementation involves a processing module that performs semantic expansion on the initial query statement to obtain an expanded query statement. The expanded query statement is semantically similar to the initial query statement but expressed differently. The expanded query statement is then vectorized to obtain a second vectorized query statement. Based on the first and second vectorized query statements, a search is performed on the second database to obtain a second candidate answer.
[0020] Another possible implementation is that the processing module is also used to deduplicate the first candidate answer and the second candidate answer to obtain the deduplicated candidate answer; to score the deduplicated candidate answer; and to determine the answer to the query statement based on the scoring results.
[0021] Thirdly, this application provides an electronic device comprising: a processor and a memory; the memory storing processor-executable instructions; when the processor is configured to execute the instructions, causing the electronic device to implement the method of the first aspect described above.
[0022] Fourthly, this application provides a computer-readable storage medium comprising: computer software instructions; which, when executed in an electronic device, cause the electronic device to implement the method described in the first aspect.
[0023] Fifthly, this application provides a computer program product comprising a computer program; when the computer program is run in an electronic device, it causes the electronic device to implement the method described in the first aspect.
[0024] The beneficial effects of the second to fifth aspects mentioned above are described in the corresponding description of the first aspect and will not be repeated here. Attached Figure Description
[0025] Figure 1 This application provides a schematic diagram of the architecture of a retrieval system.
[0026] Figure 2 A flowchart illustrating a retrieval method provided in an embodiment of this application; Figure 3 A flowchart illustrating a second candidate answer generation method provided in an embodiment of this application; Figure 4 This application provides a schematic diagram of a search answer generation process. Figure 5 A flowchart illustrating a storage and retrieval method provided in an embodiment of this application; Figure 6 This is a schematic diagram illustrating the composition of a retrieval device provided in an embodiment of this application; Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0027] The following is a detailed description of a retrieval method, electronic device, storage medium, and program product provided in this application, with reference to the accompanying drawings.
[0028] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can represent three situations: A exists alone, A and B exist simultaneously, and B exists alone.
[0029] The terms "first" and "second," etc., used in the specification and drawings of this application are used to distinguish different objects or to distinguish different treatments of the same object, rather than to describe a specific order of objects.
[0030] Furthermore, the terms "comprising" and "having," and any variations thereof, used in the description of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the steps or units listed, but may optionally include other steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus.
[0031] It should be noted that in the embodiments of this application, the words "exemplary" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of the words "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0032] To facilitate a clear description of the technical solutions of the embodiments of this application, the terms "first" and "second" are used in the embodiments of this application to distinguish the same or similar items with essentially the same function and effect. Those skilled in the art can understand that the terms "first" and "second" are not intended to limit the quantity or execution order.
[0033] In the description of this application, unless otherwise stated, "a plurality of" means two or more.
[0034] In today's information-saturated era, enterprises face significant challenges in managing massive amounts of unstructured text data and efficiently utilizing knowledge. This is especially true in application scenarios such as intelligent customer service, enterprise knowledge bases, and online support platforms, where user inquiries are becoming increasingly diverse and semantically complex.
[0035] Current question-answering retrieval systems widely use search engines based on traditional relational databases (such as MySQL) or basic keyword matching. These systems primarily rely on exact keyword matching or simple fuzzy matching algorithms to respond to user queries.
[0036] However, current search engines rely on keyword matching, making it difficult to accurately identify the semantic similarity between user queries and question-answer pairs. This leads to inaccurate search results or omissions of relevant questions and answers. For complex semantics and polysemous words, traditional methods lack a vectorization process, making it difficult to perform high-dimensional searches. This results in weak semantic understanding and poor generalization performance, making it difficult to handle real-world scenarios such as synonyms and contextual dependencies. Consequently, search accuracy is low, responses are inaccurate, and user experience and service efficiency are negatively impacted.
[0037] To address the aforementioned technical problems, this application provides a retrieval method. The method involves: firstly, retrieving a first database based on an initial query input by the user; then, vectorizing the initial query and retrieving a second database based on the first vectorized query. This allows for a semantic understanding of the user's query intent based on the vectorized results, overcoming the limitations of word matching and presenting question-answer pairs that are semantically similar to the user's question but express differently as second candidate answers, significantly improving the system's generalized retrieval capability. Finally, the final answer to the query is determined based on the first and second candidate answers, enabling the system to simultaneously integrate the advantages of precise keyword matching and semantic fuzzy matching. This significantly improves the coverage and overall retrieval quality of the questions and answers while ensuring relevance, thereby increasing retrieval accuracy.
[0038] The embodiments provided in this application will now be described in detail with reference to the accompanying drawings.
[0039] The retrieval method provided in this application can be applied to, for example... Figure 1 The example shown is a retrieval system. For instance... Figure 1 As shown, a retrieval system 10 of this application includes: an electronic device 11 and a storage device 12.
[0040] In this setup, a communication connection is established between electronic device 11 and storage device 12. For example, the connection method can be wireless, such as Bluetooth or Wi-Fi; alternatively, it can be wired, such as fiber optic, etc., without limitation. For example, electronic device 11 and storage device 12 can be connected to the Internet via a router, thereby enabling the communication connection between them.
[0041] In some implementations, electronic device 11 can collect question-and-answer data from external data sources, and then vectorize the question-and-answer data before sending it to storage device 12, whereby storage device 12 can store the question-and-answer data and the vectorized question-and-answer data.
[0042] In some implementations, the electronic device 11 can also receive question-and-answer data and vectorized question-and-answer data from the storage device 12, thereby enabling the electronic device 11 to retrieve the data and fulfill the user's search request.
[0043] In some embodiments, electronic device 11 can be a server, for example, a single server, or a server cluster consisting of multiple servers. In some embodiments, the server cluster can also be a distributed cluster.
[0044] In some embodiments, the electronic device 11 can be a terminal device, such as a mobile phone, tablet computer, desktop computer, laptop computer, handheld computer, notebook computer, ultra-mobile personal computer (UMPC), netbook, cellular phone, personal digital assistant (PDA), augmented reality (AR) / virtual reality (VR) device, etc. This application embodiment does not impose any special limitations on the specific form of the terminal device.
[0045] In some implementations, storage device 12 can receive question-and-answer data and vectorized question-and-answer data from electronic device 11, and then store the data. Storage device 12 can also send the stored question-and-answer data and vectorized question-and-answer data to electronic device 11, so that electronic device 11 can perform retrieval based on the data.
[0046] In some embodiments, the electronic device 11 and the storage device 12 can be as follows: Figure 1 As shown, there are two separate devices, or electronic device 11 and storage device 12 can be integrated into the same device.
[0047] In some implementations, storage device 12 can be a server, such as a standalone database server, or a storage cluster consisting of multiple storage nodes. The storage cluster can also be a distributed storage cluster.
[0048] In some embodiments, the storage device 12 can be a local storage medium for the terminal device, such as a solid-state drive (SSD), an embedded multimedia card (eMMC), universal flash storage (UFS), or a hard disk drive (HDD). This application embodiment does not impose any special limitations on the specific type of this local storage medium.
[0049] In some embodiments, the retrieval system 10 may also include a prompting device 13.
[0050] The notification device 13 establishes a communication connection with the electronic device 11 and the storage device 12.
[0051] In some implementations, the prompting device 13 is used to display search results. For example, the prompting device 13 may be a voice prompting device, in which case the prompting device 12 presents the search results to the user by reading them aloud. Alternatively, the prompting device 13 may also be a display device, in which case the prompting device 13 presents the search results to the user by displaying them on a screen.
[0052] It should be noted that the system architecture described in the embodiments of this application is for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and does not constitute a limitation on the technical solutions provided in the embodiments of this application. As those skilled in the art will know, with the evolution of system architecture, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.
[0053] The following description, in conjunction with the accompanying drawings, introduces a retrieval method provided by an embodiment of this application.
[0054] For example, the retrieval method provided in this application can be used through... Figure 1 The retrieval system shown is implemented, or, through... Figure 1 The electronic device in the retrieval system shown is implemented.
[0055] See Figure 2 This is a flowchart illustrating a retrieval method provided in an embodiment of this application. Figure 2 As shown, the retrieval method provided in this application includes the following steps S201 to S204.
[0056] S201. Based on the initial query statement input by the user, the first database is searched to obtain the first candidate answer.
[0057] The first database includes multiple question-and-answer pairs.
[0058] In some embodiments, the initial query entered by the user refers to a piece of text actively entered by the user through the system's interactive interface. This text expresses the user's intent, question, or information they require. The initial query entered by the user is the original input and starting point for the system's retrieval and question-and-answer process.
[0059] For example, the initial query entered by the user may include: text directly generated by the user through keyboard input, voice interaction, etc.; or text content imported from other applications or system interfaces through copy-paste, sharing interface calls, etc. The initial query entered by the user may be a complete sentence, a short list of keywords, or a colloquial phrase containing grammatical defaults.
[0060] In some embodiments, the first database refers to a storage system specifically designed for storing and managing question-and-answer pair data. The first database is the core data source upon which the system relies to perform traditional retrieval methods such as keyword matching and exact matching.
[0061] For example, the first database may include a data storage system built using relational databases, document databases, or search engine technologies. The first database internally stores massive amounts of question-answer pair data and can establish efficient inverted indexes and other data structures for the question fields in the question-answer pair data to support fast full-text retrieval.
[0062] In some embodiments, question-answer pair data refers to structured data units pre-built and stored in a first database. Each question-answer pair consists of a standard question and a corresponding standard question and answer.
[0063] In some embodiments, the initial query statement entered by the user can be obtained in real time through a search box in a graphical user interface, a voice interaction interface, or an application programming interface.
[0064] In some embodiments, after obtaining the initial query statement input by the user, preprocessing operations can be performed on the initial query statement input by the user. For example, correcting spelling errors in the initial query statement input by the user, or performing word segmentation on the initial query statement input by the user.
[0065] In some embodiments, a first database deployed locally or remotely can be accessed and connected to by reading pre-configured database connection parameters.
[0066] S202. The initial query statement is vectorized to obtain the first vectorized query statement.
[0067] In some embodiments, vectorization refers to the computational process of converting an initial query statement in text form into a fixed-dimensional numerical vector using a specific algorithm or model. Vectorization can encode the semantic information of text into a form that computers can perform mathematical calculations and similarity comparisons in.
[0068] For example, vectorization processing may include using a pre-trained language model, such as BERT, Sentence-BERT, or Embeddings models, taking the initial query statement as input, and obtaining its corresponding sentence vector representation. Vectorization processing may also include using traditional text representation methods, such as TF-IDF weighted bag-of-words model vectors.
[0069] In some embodiments, the initial query statement can be densely vectorized and sparsely vectorized to form a first vectorized query statement.
[0070] In some embodiments, a dense vector is a mathematical form that represents text, images, or other data as a fixed-length, low-dimensional array of real numbers. Most or all dimensions of a dense vector contain non-zero values, and the numerical values of each dimension collectively encode abstract semantic features of the input data. Dense vectors are typically generated by deep neural network models that map discrete symbolic information into a continuous vector space, ensuring that semantically similar texts are located close to each other in the space, thus supporting semantic matching based on vector similarity.
[0071] In some embodiments, a sparse vector is a mathematical form that represents text as a very high-dimensional text, with the vast majority of dimensions being zero. The total dimensions of a sparse vector are typically the same size as a predefined vocabulary, with each dimension corresponding to a specific term in the vocabulary. Only when the text contains a particular term does its corresponding dimension have a non-zero weight value (such as term frequency, TF-IDF value, or weights predicted by a neural network). The non-zero dimensions of a sparse vector directly correspond to specific words appearing in the text, making it ideal for retrieval tasks based on precise keyword matching.
[0072] For example, in the dense vectorization path, the complete original query statement is directly input into a pre-trained semantic encoding model (such as Sentence-BERT or BGE). This model performs deep semantic understanding and encoding on the query statement, outputting a dense vector of fixed dimensions composed of floating-point numbers, thus obtaining the densely vectorized query statement. In the sparse vectorization path, firstly, based on the core principle of the BM25 algorithm, the word frequency of the extracted keywords is calculated, and combined with inverse document frequency statistics preloaded from the database, each keyword is assigned a corresponding weight. Finally, these weights are mapped into a high-dimensional vector corresponding to the dimension of the global vocabulary, with the dimension of non-keywords being zero, thereby generating a high-dimensional sparse weight vector, which is the sparsely vectorized query statement.
[0073] In some embodiments, keywords can also be vectorized. For example, keyword vectorization can be performed using the same method as vectorizing the initial query statement.
[0074] S203. Based on the first vectorized query statement, the second database is searched to obtain the second candidate answer.
[0075] The second candidate answer includes multiple vectorized question-answer pairs.
[0076] In some embodiments, the second database is a specially designed vector database or an extended search engine that supports vector retrieval. The second database internally stores vectorized question-answer pairs and constructs an efficient index structure for this high-dimensional vector data.
[0077] In some embodiments, vectorized question-answer pairs are a data format constructed by converting the question text and its associated question-answer text in the question-answer pair into fixed-dimensional numerical vectors through a pre-trained model.
[0078] For example, a vectorized question-answer pair may include a question vector obtained by vectorizing the question text, and a question-answer vector associated with that question vector. The vectorized question-answer pair data may also include metadata identifiers pointing to the details of the original question-answer pair, so as to obtain complete question-answer information after recall.
[0079] In some embodiments, after generating the first vectorized query statement, the first vectorized query statement can be used as query input to initiate an approximate nearest neighbor retrieval request to the second database in order to obtain a second candidate answer.
[0080] S204. Based on the first candidate answer and the second candidate answer, obtain the answer to the query statement.
[0081] In some embodiments, the query response refers to the final answer determined and output to the user after the system comprehensively analyzes and decides on the first and second candidate responses. The query response is the final output of the entire retrieval process, representing the optimal solution obtained by combining the advantages of both exact matching and semantic generalization strategies, aiming to meet the user's retrieval needs in the best possible way.
[0082] For example, the response to a query may include a final selected best question and answer text; or a merged and rearranged list of questions and answers ordered in descending order of final confidence; or a comprehensive question and answer text resulting from the merging of the question and answer lists.
[0083] In some embodiments, the first candidate answer and the second candidate answer can be deduplicated to obtain the deduplicated candidate answer.
[0084] In some embodiments, deduplication refers to the process of identifying and merging candidate question-and-answer sets from different search paths in information retrieval to eliminate question-and-answer entries that point to the same substantive content or have high semantic repetition. Deduplication aims to remove duplicate candidate questions and answers, ensuring that subsequent ranking and decision-making are based on diverse and non-redundant candidate sets.
[0085] For example, deduplication can include exact matching based on question-and-answer text identifiers, that is, directly removing entries with the same unique identifier from the first and second candidate answers. Deduplication can also include fuzzy matching based on question-and-answer text content, that is, by calculating the string similarity or semantic vector similarity between different question-and-answer texts, merging multiple question-and-answer entries with similarity exceeding a preset threshold into a representative entry, and optionally combining their original scores.
[0086] In some embodiments, after obtaining the first and second candidate answers, the two answers are first merged. Next, a comparison is performed using the unique identifier of each question-and-answer entry as the primary key, removing all entries with duplicate identifiers to complete the initial deduplication. For entries with different identifiers but highly similar question-and-answer text, lightweight text hashing or fast vector similarity calculation can be used to merge entries with text similarity exceeding a certain threshold, retaining only the entry with the highest overall score. For example, the threshold can be set to 0.8~0.95, such as 0.95. Finally, a candidate answer with no duplicate identifiers and no highly repetitive question-and-answer content is obtained.
[0087] In some embodiments, the candidate answers after deduplication are scored, and the answer to the query statement is determined based on the scoring results.
[0088] In some embodiments, after removing duplicate content, the semantic understanding capabilities of a ranking model can be used. After the candidate answers are input into the model, the model can understand and score all candidate answers and the question, ensuring that the final answer presented to the user is both accurate and relevant.
[0089] For example, the original query and each deduplicated candidate answer are submitted to the ranking model. Leveraging its deep semantic understanding capabilities, the ranking model performs a comprehensive analysis of each pair, evaluating the degree of match between the candidate answer and the original query in terms of semantic consistency, factual accuracy, and information completeness, and outputs a quantified semantic relevance score for each candidate answer. Based on this score, all candidate answers are ranked in descending order.
[0090] In some embodiments, the single best answer with the highest score can be directly presented, and the candidate answer text ranked first in the scoring can be output as a response. Alternatively, a list of multiple answers sorted in descending order of scores can be provided, presenting the top several question-and-answer pairs with the highest semantic scores along with their confidence levels, giving users room for comparison and selection. Or, a comprehensive and integrated structured display can be adopted, that is, using the induction ability of the large model to integrate the core information of multiple high-scoring answers, generating a comprehensive answer with the optimal answer as the main body and integrating other relevant key points or different aspects, so as to achieve a balance between the breadth and depth of information.
[0091] In some embodiments, step S201 can be implemented as the following steps a1 to a2.
[0092] a1. Extract keywords from the initial query statement.
[0093] In some embodiments, keywords refer to words or phrases that are identified and extracted from the initial query statement and can represent the core semantic content of the initial query statement, and are the query units for subsequent matching in the first database.
[0094] Exemplarily, keywords can include: independent lexical units segmented from the initial query statement through word segmentation; specific entities identified from the initial query statement through named entity recognition, such as personal names, place names, organization names, product models; or content words such as nouns and verbs screened through词性标注 (not sure what this is in English, should it be "pos tagging"?).
[0095] In some embodiments, keywords can be extracted by integrating a natural language processing toolkit and performing real-time analysis on the initial query statement submitted by the user.
[0096] Exemplarily, the initial query statement input by the user can be received first, and then the statement can be segmented into independent lexical units. After word segmentation, a stop word filtering operation can be performed to remove common but practically valueless function words and auxiliary words such as "的", "呢", "吗". Next, content words such as nouns and verbs can be retained through词性标注 (again, not sure the English), or the named entity recognition technology can be further used to identify and extract specific entities such as personal names, place names, organization names, and proprietary product names. For text mixed with Chinese and English, corresponding word segmentation tools (such as Chinese word segmenters and English morpheme analyzers) can be called to work together.
[0097] In some embodiments, before extracting keywords, the input text can also be preprocessed, using a regular expression pattern matching mechanism to identify and extract English code snippets or program code-like content therein, thereby enabling the positioning and separation of embedded code or English information, avoiding interference with subsequent natural language semantic analysis, and selectively retaining or annotating such structured information for subsequent classification use.
[0098] In some embodiments, regular expression pattern matching is a text search and matching technique based on predefined rule strings. By describing specific patterns of character combinations, regular expression pattern matching allows computers to quickly locate, identify, and extract all text fragments that match a given pattern in the input text.
[0099] a2. Based on keywords, a search is performed on the first database to obtain the first candidate answer. The question-answer pair corresponding to the first candidate answer includes the keywords.
[0100] In some embodiments, a first candidate answer refers to one or more relevant question-and-answer pairs returned from the first database after a search of the first database based on keywords extracted from the initial query. The first candidate answers originate from question-and-answer pair data stored in the first database.
[0101] For example, the first candidate answer may include: the question and answer text selected based on relevance score that is most likely to directly answer the user's question; or a list of question and answer texts sorted in descending order of relevance score.
[0102] In some embodiments, multi-field joint retrieval can be performed based on the inverted index mechanism, combining field weights, query condition matching degree, and document scores to obtain the first candidate answer.
[0103] For example, during a search, documents containing keywords can be found in parallel across multiple preset fields (such as "title," "content," and "tags"). During this process, weights are pre-configured for different fields (i.e., field weights), ensuring that matches in more important fields (such as the title) contribute more to the final relevance. A ranking model (such as BM25) calculates a base score for each matching document, which comprehensively considers the match to the query conditions, such as the frequency of keywords appearing in the document (term frequency) and their prevalence across all documents (inverse document frequency). Finally, the field-weighted scores obtained for each document across different fields are aggregated to calculate the final document score for the current query, and all documents are then sorted in descending order based on this score.
[0104] In some embodiments, step S203 can be implemented as the following steps b1 to b5.
[0105] b1. Semantically expand the initial query statement to obtain the expanded query statement. The expanded query statement is a statement that is semantically similar to the initial query statement but expressed differently.
[0106] In some embodiments, semantic expansion is a natural language generation technique that aims to rewrite, transform, or supplement details of original text while maintaining the core intent. Semantic expansion processes generate new text that is highly semantically similar to the original text but differs in its surface expression through an algorithmic model. For example, semantic expansion may include synonym substitution, hyponymy / hypernymy concept deduction, and logical association expansion, thereby enhancing the semantic coverage of the query statement.
[0107] In some embodiments, an initial query and / or extracted keywords can be submitted as input by calling a locally deployed or cloud-service-based text generation model application programming interface (API), and one or more expanded query statements returned by the model can be received. Alternatively, the inference computation from the initial query to the expanded query statements can be performed locally by loading a pre-trained paraphrasing model.
[0108] b2. Vectorize the extended query statement to obtain the second vectorized query statement.
[0109] In some embodiments, vectorizing extended query statements can overcome the limitations of a single query expression, enabling a more comprehensive and diverse search of the vectorized semantic index. While the extended query statement is semantically similar to the initial query statement, subtle differences may exist in its specific word choices, sentence structure, or emphasis. These surface differences result in the vector generated after encoding through the same semantic model being located in the vector space near, but not identical to, the first vectorized query statement. Using the second vectorized query statement to retrieve documents from the vector database can recall relevant documents that are slightly less similar to the first vectorized query statement but closer to the extended expression. Essentially, this process maps a user's query intent to different regions of the vector space through various possible linguistic expressions, ensuring coverage of more relevant but varied question-and-answer pairs.
[0110] In some embodiments, vectorizing the extended query statement can be done in accordance with the method described above for vectorizing the initial query statement and keywords.
[0111] b3. Perform dense vector retrieval on the second database based on dense vectorized query statements to obtain dense vector retrieval results.
[0112] In some embodiments, a dense vectorized query can be used as input to invoke the vector search interface of a second database. The second database retrieves the top K vectorized data entries with the highest similarity to the query vector using a pre-built approximate nearest neighbor index. Subsequently, the database encapsulates the identifiers, associated content, and similarity scores of these entries into a structured result list and returns it. This list represents the dense vector retrieval results and can be directly used in subsequent fusion and ranking processes.
[0113] In some embodiments, an approximate nearest neighbor index is a specialized index structure designed for high-dimensional data. It efficiently finds data points similar to the query target within an acceptable computation time and with controllable resource consumption. By organizing data and pre-establishing an approximate relationship network or classification structure between data points during index construction, an approximate nearest neighbor index can quickly skip a large number of irrelevant regions during retrieval, performing distance calculations only within a small candidate set. For example, data can be organized using one or more of hashing, graph, tree, or quantization techniques, such as connecting similar points based on a graph structure or quantizing and partitioning the vector space.
[0114] In some embodiments, the results returned by the second database may also include scores corresponding to dense vector retrieval results calculated by cosine similarity (e.g., 0.92) or inner product.
[0115] b4. Perform sparse vector retrieval on the second database based on sparse vectorized query statements to obtain sparse vector retrieval results.
[0116] In some embodiments, a sparse vectorized query can be submitted to a second database to initiate a retrieval. The second database utilizes its sparse vector retrieval capabilities to efficiently calculate relevance matching and select the candidate results with the highest match to the query from the stored data. Subsequently, the second database encapsulates these candidate results and their relevance scores into an ordered list and returns it; this list represents the sparse vector retrieval result.
[0117] In some embodiments, the results returned by the second database may also include a score (e.g., 24.7) of the sparse vector retrieval results calculated by the BM25 algorithm.
[0118] b5. Based on the dense vector retrieval results and the sparse vector retrieval results, the second candidate answer is obtained.
[0119] In some embodiments, a second candidate answer can be obtained by using a weighted sorter, taking dense vector retrieval results and sparse vector retrieval results as input, and performing weighted merging, deduplication, and sorting calculations.
[0120] In some embodiments, a weighted sorter may be used to determine the weights of dense vector retrieval results and sparse vector retrieval results. The weights reflect the importance of either the dense or sparse vector retrieval results.
[0121] In some embodiments, a weighted ranking unit is a component in a retrieval system used to integrate and harmonize results from different retrieval paths. The weighted ranking unit receives result sets from multiple independent retrieval channels and their original relevance scores. It quantifies the relative importance of each channel in the current retrieval task by assigning a configurable weight coefficient to each channel (e.g., 0.8 for dense result sets and 0.2 for sparse result sets), and then performs weighted fusion of the scores and reorders the results accordingly.
[0122] In some embodiments, a second candidate answer can be obtained based on the weights of the dense vector retrieval results and the weights of the sparse vector retrieval results.
[0123] For example, such as Figure 3 As shown. First, S1 is executed to collect the results and scores of dense vector retrieval and sparse vector retrieval (score_1, score_2). Each search may use different similarity metrics, resulting in different score distributions. For example, using "inner product" as the similarity type may produce scores in the range [-∞, +∞], while using "Euclidean distance" will produce scores in the range [0, +∞]. Since the score ranges of different searches are different and cannot be directly compared, step S2, normalization, is performed. The score of each search path is normalized. For example, the arctan function is used to convert the scores to the range [0, 1], resulting in (score_1_normalized, score_2_normalized). The closer the score is to 1, the higher the similarity.
[0124] Next, step S3 is executed: weight allocation. Based on the importance assigned to different vector fields, weights are allocated to the normalized scores (score_1_normalized, score_2_normalized) (e.g., 0.2 for sparse vectors and 0.8 for dense vectors). The weight for each path can range from [0, 1]. The resulting weighted scores are score_1_weighted and score_2_weighted. For example, if score_1_normalized = 0.9 and score_2_normalized = 0.8, the weight allocated to score_1_normalized is 0.2, and the weight allocated to score_2_normalized is 0.8, resulting in the final score. .
[0125] Finally, step S4 is executed to merge the result sets. The weighted scores (score_1_weighted, score_2_weighted) are sorted from high to low to obtain a final score (score_final). The second candidate answer is the corresponding question-answer pair sorted by score.
[0126] In some embodiments, the database may be expanded and updated before performing step S201.
[0127] In some embodiments, raw question-and-answer data may be collected from external data sources. For example, external data sources may include user consultation records, knowledge bases, etc.
[0128] In some embodiments, the collected raw question-and-answer data can be preprocessed, including rich text data cleaning, table conversion to HTML or Markdown format, and attachment conversion. For example, resources such as images can be converted into link tags to ensure data quality and facilitate model recognition and processing, providing a clean data source for subsequent vectorization and indexing. The preprocessed data can also be organized into question-and-answer pairs and stored in a first database.
[0129] In some embodiments, a deep learning model can be used to transform the processed question-answer pairs into high-dimensional semantic vectors. The format of the transformed vectors can be the same as that used for vectorizing the original query statements. This process can capture deep semantic information in the text, eliminate scale differences in the vectors, and make subsequent similarity calculations (such as cosine similarity) more efficient and stable. The converted vector data can also be stored in a second database.
[0130] For example, such as Figure 4 As shown. First, enter S1, External Data, to find external data. Next, enter the Data Processing module and execute step S2, Data Acquisition, to collect external data. Then, enter the Data Cleaning module and execute step S3, Rich Text Cleaning, Table Format Conversion, and Attachment Resource Conversion to HTML, converting the rich text data into text data for easier subsequent processing. Then, execute step S4, Vectorization Processing, to vectorize the cleaned data. Finally, enter the S5, Storage module, to store the cleaned data and the vectorized data in the first database and the second database, respectively.
[0131] Then, the system enters the retrieval module, proceeding to step S6, API entry, and then step S7, query processing module, to search for data stored in the storage module. Next, step S8, question-and-answer pair weight allocation, uses a weighted sorter to pre-determine the weights. Following this, step S9, vector retrieval, searches the vectorized question-and-answer data stored in the second database. Simultaneously, step S10, thelexicon and weight allocation, uses an algorithm to calculate weights for the question-and-answer data in the first database and extracts keywords from the user's query. Then, step S11, keyword retrieval, performs keyword retrieval on the question-and-answer data in the first database. Next, step S12, model scoring and sorting, inputs the two types of retrieval results into the large model, scores the results, and sorts them according to the scores. Finally, step S13, client-side, displays the final answer to the user on the client.
[0132] In some embodiments, when performing the above retrieval method, the database may be updated first. For example, such as... Figure 5 As shown. First, step S1, data acquisition, collects raw question-and-answer data from the data source. Next, step S2, data cleaning, converts the collected rich text data into text-based question-and-answer data for easier subsequent processing. Then, step S3, vectorization, converts the cleaned data into vectors. Next, step S4, data storage, stores the cleaned data and the vectorized data. Next, step S5, query processing, queries the stored data. Then, step S6, lexicon configuration and weight allocation, pre-configures the data in the database using an algorithm, calculates scores for corresponding words, and assigns weights accordingly. Finally, step S7, result set model scoring and sorting, inputs the search results into the large model and sorts them according to the scores provided by the model.
[0133] As can be seen, the above mainly describes the solutions provided by the embodiments of this application from a methodological perspective. To achieve the above functions, the embodiments of this application provide corresponding hardware structures and / or software modules for executing each function. Those skilled in the art should readily recognize that, in conjunction with the modules and algorithm steps of the various examples described in the embodiments disclosed herein, the embodiments of this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed by hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this invention.
[0134] This application embodiment can divide the retrieval device into functional modules according to the above method example. For example, each function can be divided into its own functional module, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware or as a software functional module. Optionally, the module division in this application embodiment is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.
[0135] In some embodiments, this application also provides a retrieval device. The retrieval device may include one or more functional modules for implementing the retrieval methods described in the above embodiments.
[0136] For example, Figure 6 This is a schematic diagram illustrating the composition of a retrieval device 800 provided in an embodiment of this application. Figure 6 As shown, the retrieval device includes a retrieval module 801 and a processing module 802.
[0137] The retrieval module 801 is used to retrieve the first database based on the initial query statement input by the user and obtain the first candidate answer; the processing module 802 is used to perform vectorization processing on the initial query statement to obtain the first vectorized query statement; the retrieval module 801 is also used to retrieve the second database based on the first vectorized query statement and obtain the second candidate answer; the processing module 802 is also used to obtain the answer to the query statement based on the first candidate answer and the second candidate answer.
[0138] In some embodiments, the processing module 802 is further configured to extract keywords from the initial query statement; search the first database based on the keywords to obtain a first candidate answer; the question-answer pair corresponding to the first candidate answer includes keywords.
[0139] In other embodiments, the first vectorized query statement includes a dense vectorized query statement and a sparse vectorized query statement; the retrieval module 801 is further configured to perform dense vector retrieval on the second database based on the dense vectorized query statement to obtain dense vector retrieval results; perform sparse vector retrieval on the second database based on the sparse vectorized query statement to obtain sparse vector retrieval results; and obtain a second candidate answer based on the dense vector retrieval results and the sparse vector retrieval results.
[0140] In some other embodiments, the processing module 802 is further configured to use a weighted sorter to determine the weights of the dense vector retrieval results and the sparse vector retrieval results; the weights are used to reflect the importance of the dense vector retrieval results or the sparse vector retrieval results; and based on the weights of the dense vector retrieval results and the sparse vector retrieval results, a second candidate answer is obtained.
[0141] In some other embodiments, the processing module 802 is further configured to extract keywords from the initial query statement; vectorize the keywords; and search the second database based on the vectorized keywords and the first vectorized query statement to obtain a second candidate answer.
[0142] In some other embodiments, the processing module 802 is further configured to perform semantic expansion processing on the initial query statement to obtain an expanded query statement; the expanded query statement is a statement that is semantically similar to the initial query statement but expressed differently; the expanded query statement is vectorized to obtain a second vectorized query statement; based on the first vectorized query statement and the second vectorized query statement, the second database is searched to obtain a second candidate answer.
[0143] In some other embodiments, the processing module 802 is further configured to perform deduplication processing on the first candidate answer and the second candidate answer to obtain a deduplicated candidate answer; score the deduplicated candidate answer; and determine the answer to the query statement based on the scoring results.
[0144] In the case of implementing the functions of the integrated modules described above in hardware, this embodiment of the invention provides a possible structural schematic diagram of the electronic device involved in the above embodiments. For example... Figure 7 As shown, the electronic device 900 includes: a processor 902, a communication interface 903, and a bus 904. Optionally, the electronic device 900 may also include a memory 901.
[0145] Processor 902 may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 902 may be a central processing unit, a general-purpose processor, a digital signal processor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 902 may also be a combination that implements computing functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.
[0146] The communication interface 903 is used to connect to other devices via a communication network. This communication network can be Ethernet, wireless access network, wireless local area network (WLAN), etc.
[0147] The memory 901 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but is not limited thereto.
[0148] In one possible implementation, the memory 901 can exist independently of the processor 902. The memory 901 can be connected to the processor 902 via a bus 904 and is used to store instructions or program code. When the processor 902 calls and executes the instructions or program code stored in the memory 901, it can implement the retrieval method provided in this embodiment of the invention.
[0149] In another possible implementation, the memory 901 can also be integrated with the processor 902.
[0150] The 904 bus can be an extended industry standard architecture (EISA) bus, etc. The 904 bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 7 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0151] Through the above description of the implementation methods, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the service calling device can be divided into different functional modules to complete all or part of the functions described above.
[0152] This application also provides a computer-readable storage medium. All or part of the processes in the above method embodiments can be executed by computer instructions instructing related hardware. The program can be stored in the aforementioned computer-readable storage medium, and when executed, it can include the processes of the above method embodiments. The computer-readable storage medium can be any of the foregoing embodiments or memory. The aforementioned computer-readable storage medium can also be an external storage device of the aforementioned service invocation device, such as a plug-in hard drive, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the aforementioned service invocation device. Further, the aforementioned computer-readable storage medium can include both internal storage units of the aforementioned service invocation device and external storage devices. The aforementioned computer-readable storage medium is used to store the aforementioned computer program and other programs and data required by the aforementioned service invocation device. The aforementioned computer-readable storage medium can also be used to temporarily store data that has been output or will be output.
[0153] This application also provides a computer program product comprising a computer program that, when run on a computer, causes the computer to execute any of the retrieval methods provided in the above embodiments.
[0154] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A retrieval method, characterized in that, The method includes: The first database is searched based on the initial query statement input by the user to obtain the first candidate answer. The first database includes multiple question-answer pairs. The initial query statement is vectorized to obtain the first vectorized query statement; The second database is searched based on the first vectorized query statement to obtain a second candidate answer, which includes multiple vectorized question-answer pairs. The answer to the query statement is obtained based on the first candidate answer and the second candidate answer.
2. The method according to claim 1, characterized in that, The process of retrieving a first candidate answer from the first database based on an initial query input by the user includes: Extract keywords from the initial query statement; The first database is searched based on the keywords to obtain the first candidate answer; the question-answer pair corresponding to the first candidate answer includes the keywords.
3. The method according to claim 1, characterized in that, The first vectorized query statement includes dense vectorized query statements and sparse vectorized query statements; the step of retrieving the second database based on the first vectorized query statement to obtain a second candidate answer includes: Based on the dense vectorized query statement, a dense vector retrieval is performed on the second database to obtain dense vector retrieval results; Based on the sparse vectorized query statement, a sparse vector retrieval is performed on the second database to obtain sparse vector retrieval results; Based on the dense vector retrieval results and the sparse vector retrieval results, the second candidate answer is obtained.
4. The method according to claim 3, characterized in that, The process of obtaining the second candidate answer based on the dense vector retrieval results and the sparse vector retrieval results includes: A weighted sorter is used to determine the weights of the dense vector retrieval results and the sparse vector retrieval results; the weights are used to reflect the importance of the dense vector retrieval results or the sparse vector retrieval results. The second candidate answer is obtained based on the weights of the dense vector retrieval results and the sparse vector retrieval results.
5. The method according to claim 1, characterized in that, The step of retrieving the second database based on the first vectorized query statement to obtain the second candidate answer includes: Extract keywords from the initial query statement; The keywords are vectorized. The second database is searched based on the vectorized keywords and the first vectorized query statement to obtain a second candidate answer.
6. The method according to claim 1, characterized in that, The step of retrieving the second database based on the first vectorized query statement to obtain the second candidate answer includes: The initial query statement is semantically expanded to obtain an extended query statement; the extended query statement is a statement that is semantically similar to the initial query statement but expressed differently. The extended query statement is vectorized to obtain a second vectorized query statement; Based on the first and second vectorized query statements, the second database is searched to obtain the second candidate answer.
7. The method according to claim 1, characterized in that, The step of obtaining the answer to the query statement based on the first candidate answer and the second candidate answer includes: The first candidate answer and the second candidate answer are deduplicated to obtain the deduplicated candidate answer; The candidate answers after deduplication are scored, and the answer to the query statement is determined based on the scoring results.
8. An electronic device, characterized in that, It includes a processor and a memory, the processor being coupled to the memory; the memory is used to store computer instructions, which are loaded and executed by the processor to enable the computer device to implement the retrieval method as described in any one of claims 1 to 7.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes computer-executable instructions that, when executed on a computer, cause the computer to perform the retrieval method according to any one of claims 1 to 7.
10. A computer program product, characterized in that, The computer program product includes a computer program that, when run on an electronic device, causes the electronic device to perform the retrieval method as described in any one of claims 1 to 7.