Query method and device, electronic equipment and readable storage medium
By detecting the generated target content in real time and adding reference numbers in order, the problems of confusion and faults in the prior art are solved, ensuring the logical clarity of the generated text and the reliability of the information source.
Patent Information
- Application Number
- CN202510193702.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-21
- Publication Date
- 2025-07-18
AI Technical Summary
In the prior art, when generating text with reference numbers, there are problems such as confusing numbering, incorrect numbering and faulty numbering.
By real-time detection of the generated target content, if the preset statement ending condition is met, sequential reference numbers are added to the initial query results cited by the target statement and the target statement to ensure that the reference number is closely combined with the text content.
The accuracy and continuity of reference numbers are achieved, and the numbering chaos and faults are avoided, ensuring that the generated text content is logically clear and the information source is reliable.
Smart Images

Figure CN120336518A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular, to a query method, device, electronic device, and readable storage medium. Background Art
[0002] With the development of the field of large language models, more and more text tasks can be completed with the help of large language models to improve the processing efficiency of text tasks. For example, when a large language model generates text according to actual needs, the large language model can add citation numbers after generating the text to clarify the citation source of the text, so that users can know the origin of the generated text, thereby improving the credibility of the generated text. However, in the prior art, when generating text with citation numbers, there are problems such as chaotic numbers, incorrect numbers, and number breaks. Summary of the Invention
[0003] In view of this, the embodiments of this application provide a query method, device, electronic device, and readable storage medium to solve the problems of chaotic numbers, incorrect numbers, and number breaks in the prior art when generating text with citation numbers.
[0004] In the first aspect of the embodiments of this application, a query method is provided, and the method includes:
[0005] In response to the received query text, determining an initial query result corresponding to the query text; generating target content according to the initial query result, and if the target content meets a preset statement end condition, obtaining a target statement including the target content corresponding to the statement end condition; adding citation numbers to the target statement and the initial query result cited by the target statement, where the citation number represents the citation relationship between the target statement and the initial query result, and the citation numbers are added in sequence; generating a target query result corresponding to the query text according to the target statement corresponding to the citation number.
[0006] In the second aspect of the embodiments of this application, a query device is provided, and the device includes:
[0007] A determination module configured to determine an initial query result corresponding to the query text in response to the received query text; an acquisition module configured to generate target content according to the initial query result, and if the target content meets a preset statement end condition, obtain a target statement including the target content corresponding to the statement end condition; a citation module configured to add citation numbers to the target statement and the initial query result cited by the target statement, where the citation number represents the citation relationship between the target statement and the initial query result, and the citation numbers are added in sequence; a generation module configured to generate a target query result corresponding to the query text according to the target statement corresponding to the citation number.
[0008] In a third aspect of the embodiments of the present application, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the above method are implemented.
[0009] In a fourth aspect of the embodiments of the present application, a readable storage medium is provided. The readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0010] The beneficial effects of the embodiments of the present application compared with the prior art are as follows:
[0011] According to the technical solution provided by the embodiments of the present application, in response to the received query text, an initial query result corresponding to the query text is determined, which can ensure the accuracy of the subsequent generated target content. The target content is generated according to the initial query result. If the target content meets the preset statement end condition, a target statement including the target content corresponding to the statement end condition is obtained. Reference numbers are added to the target statement and the initial query result cited by the target statement. The reference number represents the reference relationship between the target statement and the initial query result, and the reference numbers are added in sequence. In this way, when the target statement is generated, reference numbers can be added to the target statement and the initial query result cited by the target statement, ensuring the accuracy of the reference numbers while ensuring the continuity and rationality of the reference numbers, and avoiding the problems of chaotic numbering, number breaks, and incorrect numbering in the prior art when generating text with reference numbers. Finally, the target query result corresponding to the query text is generated according to the target statement corresponding to the reference number, so that the target query result not only has a complete and clear content logic, but also can clearly show the reliability and relevance of its information source through the reference number. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for use in the embodiments or the description of the prior art. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0013] Figure 1 is a flowchart of a query method provided by an embodiment of the present application;
[0014] Figure 2 is a structural diagram of a query device provided by an embodiment of the present application;
[0015] Figure 3 is a structural diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0016] In the following description, specific details such as specific system structures and technologies are presented for the purpose of illustration rather than limitation, in order to thoroughly understand the embodiments of the present application. However, those skilled in the art should clearly understand that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from interfering with the description of the present application.
[0017] In the process of generating response text content according to prompt text by generative artificial intelligence (such as large language models), it usually involves the retrieval and citation of relevant documents to enhance the credibility of the generated content. This citation function is particularly important in scenarios such as academic content generation, legal consultation, and medical Q&A.
[0018] However, current large language models usually rely on retrieval-augmented generation technology, and the generation of citations usually occurs after the generation of content and cannot be integrated with the generation process in real time. Some technical solutions attempt to let the large model output citation numbers by itself through prompts (Prompts), but the number formats are often unstable and do not support dynamic updating of cited documents. This leads to problems such as citation numbers possibly starting from non-consecutive numbers or having discontinuous numbers, especially in large-scale retrieval scenarios, these problems are more serious.
[0019] In view of this, the present application proposes a query method, device, electronic device, and readable storage medium. To solve the problems of chaotic numbers, incorrect numbers, and duplicate numbers that exist in the prior art when generating text with citation numbers.
[0020] A query method, device, electronic device, and readable storage medium according to an embodiment of the present application will be described in detail below with reference to the accompanying drawings.
[0021] Figure 1 It is a schematic flowchart of a query method provided by an embodiment of the present application. As Figure 1 shown, the method includes:
[0022] S101, in response to the received query text, determine the initial query result corresponding to the query text;
[0023] S102, generate target content according to the initial query result. If the target content meets the preset statement end condition, obtain the target statement including the target content corresponding to the statement end condition;
[0024] S103, add citation numbers to the target statement and the initial query result cited by the target statement; where the citation number represents the citation relationship between the target statement and the initial query result, and the citation numbers are added in sequence;
[0025] S104. Generate a target query result corresponding to the query text based on the target statement corresponding to the citation number.
[0026] Specifically, the query method of this embodiment can be executed by the client or the server, or jointly executed by the client and the server. Hereinafter, an example where the execution entity is the client will be used for illustration. The input received by the execution entity can be voice, image, or text. After receiving the corresponding input, the input can be converted into a query text through computer algorithms.
[0027] It can be understood that after receiving the query text, an initial query result corresponding to the query text will be determined. The initial query result represents document data, web page data, or paper data that has a certain similarity to the query text. In this way, during the process of generating the target content based on the initial query result, it can be ensured that the target statement is related to the query text, improving the accuracy of the generated target statement.
[0028] It can be understood that since the existing citation numbers are generated after the generation of the query result text by the large language model or generated by prompting the large language model through Prompt, there may be certain defects in the relevance between the citation numbers and the text content. Because these two steps are relatively independent, when generating the text, the model does not organize the content based on the planning of the citation numbers. The subsequent addition of numbers is only a formal supplement and not part of the internal logic construction of the text. Therefore, when the text content is complex or involves multiple viewpoints intersecting, the citation numbers cannot correctly reflect the relationship between the generated content and the citation sources, resulting in incorrect citation numbers, making it difficult for readers to establish a close and accurate corresponding connection when tracing back to the reference materials based on the numbers. In addition, this generation method will also lead to an unreasonable distribution of citation numbers, problems such as chaotic and discontinuous citation numbers. Since the citation numbers are not generated synchronously during content creation, the model may not comprehensively consider the text structure and information density, resulting in a situation where some paragraphs are overly densely cited, while some important content lacks corresponding citation numbers.
[0029] It can be understood that during the process of generating the target content based on the initial query result in this application, the generated target content is detected in real time. If the target content meets the preset statement end condition, the target statement containing the target content corresponding to the statement end condition is obtained; at the same time, citation numbers are added to the target statement and the initial query result cited by the target statement.
[0030] It can be understood that the solution of the present application can generate reference numbers through independent coding logic without relying on a large language model to output reference numbers, completely avoiding potential errors caused by relying on the large model to output reference numbers by itself. In this way, it can be ensured that during the generation of the target content, every time a sentence end condition appears, a reference number is added to the target sentence and the initial query result referred to by the target sentence, ensuring the close combination of the reference number and the text content. This way of synchronously adding reference numbers unifies the text generation logic and the reference number planning, and can ensure the accuracy of the reference relationship between the target sentence and the reference source. And because the reference numbers are added in sequence, it can avoid the situation of chaotic and discontinuous numbers. Finally, the target query result corresponding to the query text is generated according to the target sentence corresponding to the reference number, so that the target query result not only has a complete and clear content logic, but also can clearly show the reliability and relevance of its information source through the reference number.
[0031] According to the technical solution provided by the embodiment of the present application, in response to the received query text, determine the initial query result corresponding to the query text; it can ensure the accuracy of the subsequent generated target content. Generate the target content according to the initial query result. If the target content meets the preset sentence end condition, obtain the target sentence including the target content corresponding to the sentence end condition; add reference numbers to the target sentence and the initial query result referred to by the target sentence; where the reference number represents the reference relationship between the target sentence and the initial query result, and the reference number is obtained by adding in sequence; in this way, when the target sentence is generated, reference numbers can be added to the target sentence and the initial query result referred to by the target sentence, ensuring the accuracy of the reference number while ensuring the continuity and rationality of the reference number, and avoiding the problems of chaotic numbers, discontinuous numbers and incorrect numbers existing in the prior art when generating text with reference numbers. Finally, the target query result corresponding to the query text is generated according to the target sentence corresponding to the reference number, so that the target query result not only has a complete and clear content logic, but also can clearly show the reliability and relevance of its information source through the reference number.
[0032] In some embodiments, the number of initial query results is multiple. In response to the received query text, determining the initial query result corresponding to the query text includes: retrieving multiple initial query results from a pre-set document database according to the query text.
[0033] Specifically, the document database includes multiple query results, and the similarity between each initial query result and the query text is greater than a first preset threshold.
[0034] It can be understood that a text retrieval model can be used to retrieve multiple initial query results from a document database. The text retrieval model can be a spatial vector model, a Boolean model, etc. The document database includes multiple query results, and the query results can be contents such as web pages, papers, and documents. The presentation forms of the query results include, but are not limited to, images, texts, and audios.
[0035] In some examples, the similarity between each initial query result and the query text is greater than a first preset threshold, and the first preset threshold can be set according to actual needs. For example, the similarity is greater than 70%, 75%, or 80%. The specific value is not specifically limited in this implementation.
[0036] According to the technical solution provided by the embodiment of the present application, multiple initial query results are retrieved from a preset document database according to the query text. The similarity between each initial query result and the query text is greater than a first preset threshold, that is, there is a high similarity between the multiple initial query results and the query text, ensuring that only data related to the query text can be cited to generate the target content, improving the generation efficiency of the subsequent target content, and improving the accuracy of the subsequently generated target content.
[0037] In some embodiments, retrieving multiple initial query results from a preset document database according to the query text includes:
[0038] Performing a vector representation on the query text to obtain a query text vector; calculating the similarity between the query text vector and each query result vector to obtain a similarity calculation result, where the query result vector is a vector representation of multiple query results in the document database; and selecting the query results corresponding to the query result vectors with a similarity calculation result greater than the first preset threshold as the multiple initial query results.
[0039] Specifically, text vector representation refers to representing the semantics of a text with a numerical vector, representing text information in a numerical form that can be understood and processed by a machine for subsequent calculation and processing.
[0040] In some examples, the methods for text vector representation include a word vector model, a sentence vector model, etc. Specifically, it can include methods such as the Bag of Words Model, Term Frequency - Inverse Document Frequency (TF-IDF), Word2vec, Doc2vec, etc. The method for vector representation is not limited herein.
[0041] It can be understood that in this embodiment, the query text is vectorized to obtain a query text vector, and multiple query results in the document database are vectorized to obtain query result vectors. Since the method of calculating vector similarity is used to determine multiple initial query results corresponding to the query text, it can be ensured that the multiple initial query results are relevant to the query text, avoiding directly generating query results corresponding to the query text from a large amount of text data and ensuring the processing efficiency of the data. In addition, the calculation methods of similarity can include Euclidean distance, Manhattan distance, cosine similarity, etc., which are not specifically limited in this embodiment.
[0042] In some examples, for multiple query results of the document database, first, the HuggingFace embedding model can be used to convert the text information in each query result into a vector representation. At the same time, FAISS or Pinecone is used to construct a vectorized index, and multiple query result vectors are stored in a structure similar to an index table through FAISS or Pinecone for subsequent quick lookup and retrieval through this index table. Then, after receiving the query text, it is also converted into a query text vector through the same HuggingFace embedding model to ensure that it is used in the same vector space as the previous document vectors to construct a vectorized document index. The similarity between the query text vector and each of the previously stored query result vectors in the FAISS or Pinecone index is calculated using a similarity formula, and the query result vectors with similarity greater than the first preset threshold are selected as the initial query results, and at the same time, the metadata information of these documents, such as index_id (the unique identifier of the document in the index) and source (the source of the document), is returned. This can provide the user with the documents that best match their query text and some basic information about these documents, helping the user obtain the required information.
[0043] According to the technical solution provided by the embodiment of the present application, the similarity between the query text vector and each query result vector is calculated to obtain a similarity calculation result, and the query results corresponding to the query result vectors with similarity calculation results greater than the first preset threshold are selected as multiple initial query results, thereby ensuring a high similarity between the initial query results and the query text and ensuring the efficiency and accuracy of the subsequent generated target content.
[0044] In some embodiments, if the target content meets the preset statement end condition, obtaining the target statement including the target content corresponding to the statement end condition includes: monitoring the target content using a callback function and a regular expression; if a statement end identifier is detected, obtaining the target statement including the target content corresponding to the statement end symbol.
[0045] Specifically, a callback function is a function that is passed as an argument to another function. When the called function completes a specific task (such as an event occurring, an operation ending, etc.), the callback function passed as an argument will be called.
[0046] The statement terminator is a specific character, character sequence, or pattern used to mark the end of a statement. In text processing scenarios, some characters or patterns can be customized as statement end identifiers, such as specific punctuation marks (period., exclamation mark!, question mark?, etc.) or specific string combinations.
[0047] It can be understood that for the process of generating target content, a large language model that supports streaming generation (such as ChatTongyi, etc.) can be used to stream generate the target content, and a callback function and regular expression are used to monitor the target content during the content generation process.
[0048] In some examples, first write a callback function whose role is to monitor the generated content. This callback function will be called during the content generation process. Each time a part of the content is generated, the callback function will receive this newly generated part of the content. The callback function uses a regular expression for pattern matching inside. It should be noted that the corresponding regular expression needs to be defined according to the specific form of the statement terminator.
[0049] It can be understood that during the process of generating target content, whenever new content is generated, the callback function will be triggered and the newly generated content will be passed in as an argument. The callback function uses the defined regular expression to match in the newly generated content. If the statement terminator is matched, it means the end of a complete statement is detected, and at this time, the target statement containing the target content is obtained. In this way, the generated content can be effectively monitored and processed sentence by sentence to ensure that the corresponding content can be accurately obtained at the end of a specific statement.
[0050] According to the technical solution provided by the embodiments of the present application, a callback function and a regular expression are used to monitor the target content; if the statement terminator is detected, the target statement corresponding to the statement terminator and containing the target content is obtained, which can effectively monitor and process the generated content sentence by sentence to ensure that the corresponding content can be accurately obtained at the end of a specific statement.
[0051] In some embodiments, reference numbers are added to the target statement and the initial query results referred to by the target statement, including: sequentially assigning numbers to the initial query results referred to by the target statement; adding the numbers as reference numbers to the target statement to represent the reference relationship between the target statement and multiple initial query results.
[0052] Specifically, since the target statement is generated based on multiple initial query results, after obtaining the target statement, the initial query results referred to by the target statement can be determined, and numbers are assigned to these initial query results. Exemplarily, for example, if the initial query result referred to by the target statement is A, the number of A is set to (1). If the initial query results referred to by the target statement are A and B, then the number of A is set to (1) and the number of B is set to (2). In this way, numbers can be assigned to the initial query results according to the generated target statement, avoiding the disorder of the number sequence and ensuring the rationality of the numbers.
[0053] It can be understood that after adding numbers to the initial query results referred to by the target statement, the numbers are added to the target statement as reference numbers. Continuing with the above example, if the initial query result referred to by the target statement is A, the corresponding number (1) of A is added to the end of the target statement. For example, "target statement (1) " to clarify the reference relationship between the target statement and the initial query result A. If the initial query results referred to by the target statement are A and B, then the corresponding number (1) of A and the corresponding number (2) of B are added to the end of the target statement. For example, "target statement (1)(2) " to clarify the reference relationship between the target statement and the initial query results A and B.
[0054] It should be noted that the forms of the above numbers and reference numbers are not limited to digital numbers, and can also be English numbers, Roman numerals, etc. This embodiment does not specifically limit this. In addition, the position where the number is added to the target statement can be not only at the end, but also at the beginning, in the middle or any position of the target statement. This embodiment also does not specifically limit this.
[0055] In some examples, if the initial query results referred to by the target statement are at least two, after adding reference numbers to the target statement and the initial query results referred to by the target statement, it further includes: determining the correspondence between the target statement and the at least two initial query results referred to, and according to the correspondence, the same color is assigned to each of the initial query results referred to and its corresponding part in the target statement for display, and the colors assigned to each initial query result are different.
[0056] As an example, if the target statement simultaneously refers to multiple initial query results, such as C, D, and E, then in the target statement, the part corresponding to C is marked in red, the part corresponding to D is marked in blue, and the part corresponding to E is marked in green; and for the initial query results C, D, and E, the corresponding red, blue, and green colors are also marked respectively. Through this way of color identification, it can present a distinct and intuitive visual effect, enabling readers to quickly identify the reference relationship between each part of the target statement and the initial query results.
[0057] In addition, the target text type of the initial query result can be determined, and then the target type identifier corresponding to the target text type can be determined from the preset text types and type identifiers, and the target type identifier is added to the target statement and the initial query result referred to by the target statement. For example, a book icon (target type identifier) is used to represent the initial query result from an academic paper (text type), and a web page icon (target type identifier) is used to represent the initial query result sourced from a web page (text type). In such a complex information environment, users can quickly distinguish the types of information sources through intuitive icons, and at the same time, the credibility of the target statement can be determined through the target type identifier. Since the authority of academic papers is generally higher than that of query results sourced from web pages, users can also determine the credibility of the target statement through the target type identifier.
[0058] According to the technical solution provided by the embodiments of the present application, numbers are added to the initial query results referred to by the target statement; the numbers are added as reference numbers to the target statement to represent the reference relationship between the target statement and multiple initial query results. In this way, when the target statement is generated, numbers are sequentially assigned to the initial query results, ensuring the continuity and rationality of number assignment, avoiding the situation of chaotic numbering, and at the same time synchronously adding the number as a reference number to the target statement to ensure that the reference relationship between the target statement and the initial query result is correct.
[0059] In some embodiments, before adding numbers to the initial query results referred to by the target statement, it further includes: determining whether the initial query results referred to by the target statement have already been numbered; if it is determined that the initial query results referred to by the target statement have already been numbered, then the already added numbers are used as the numbers of the initial query results referred to by the target statement.
[0060] Specifically, before adding numbers to the initial query results referred to by the target statement, it is also necessary to determine whether the initial query results referred to by the target statement have already been numbered among the initial query results that have already been assigned numbers. If the initial query results referred to by the target statement have not been numbered, then numbers are assigned to the initial query results referred to by the target statement in the order of the numbers. If it is determined that the initial query results referred to by the target statement have already been assigned numbers, then the already assigned numbers are used as the numbers of the initial query results referred to by the target statement, avoiding the situation of assigning different numbers to the same initial query result, that is, avoiding the situation of duplicate numbers for the initial query results.
[0061] Continuing with the previous example, if the initial query results referred to by the target statement are A and B, then after setting the number of A to (1) and the number of B to (2), if the initial query results referred to by the target statement after this target statement are A and C, and it is determined from the initially query results with assigned numbers that the number (1) has already been assigned to the initial query result A, then no new number will be assigned to the initial query result A. At this time, the already assigned number (1) of the initial query result A will be directly used, and only a new number (3) will be assigned to the initial query result C and added as a reference number to the corresponding target statement, that is, "target statement (1)(3) ".
[0062] In addition, after adding the number as a reference number to the target statement, it also includes: displaying the target statement corresponding to the reference number through a visual interface; continuing to execute the preset statement end condition monitoring step and reference number adding step until the target query result corresponding to the query text is obtained.
[0063] Specifically, since the existing method of adding reference numbers adds reference numbers to statements or paragraphs in the query result after obtaining the complete query result corresponding to the text, this makes it so that users can only see the reference sources of some statements when seeing the complete query result. This will increase the cognitive burden on users. Users need to remember the reference numbers at different positions in the text and then go to centrally search for the corresponding reference documents, increasing the workload of memory and search. Especially for query results with a long length and many references, users may feel tired due to repeated searching, reducing the effective absorption of information. In addition, since the background information cannot be understood synchronously when seeing the content, it is difficult for users to quickly expand reading based on references, restricting the further exploration of the knowledge system.
[0064] It can be understood that in this embodiment, the target statement corresponding to the reference number is displayed through a visual interface in real time, enabling users to directly click on the reference number of the target statement to see the initial query result referred to by the target statement when seeing the target statement, improving the user experience. After the display, the preset statement end condition monitoring step and reference number adding step are continued to obtain the target statement corresponding to the next statement end condition and the initial query result referred to by this target statement until the target query result corresponding to the query text is obtained.
[0065] According to the technical solution provided by the embodiment of the present application, it is determined whether a number has been added to the initial query result referred to by the target statement; if it is determined that a number has been added to the initial query result referred to by the target statement, the added number is used as the number of the initial query result referred to by the target statement; this avoids problems such as number chaos and unreasonableness caused by assigning multiple numbers to the same initial query result. In addition, adding the number as a reference number after the target statement further includes: displaying the target statement corresponding to the reference number through a visual interface; continuing to execute the preset statement end condition monitoring step and reference number adding step until the target query result corresponding to the query text is obtained. In this way, pushing the target statement with the reference number to the user in real time can reduce the user's reading burden and improve the user's usage experience.
[0066] In some embodiments, after obtaining the target statement including the target content corresponding to the statement end condition, it further includes:
[0067] Semantic analysis processing and keyword extraction processing are respectively performed on the target statement to obtain a first statement semantic feature vector and a first statement keyword set; for each initial query result, semantic analysis processing and keyword extraction processing are respectively performed to obtain a second statement semantic feature vector and a second statement keyword set; the semantic similarity between the first statement semantic feature vector and the second statement semantic feature vector is calculated, and the coincidence number of the first statement keyword set and the second statement keyword set is determined; if the semantic similarity is greater than a second preset threshold and the coincidence number is greater than a preset number, the corresponding initial query result is used as the initial query result referred to by the target statement.
[0068] Specifically, for the target statement, in the semantic analysis processing link, based on a deep learning word vector model, such as methods like Word2Vec, GloVe, etc., semantic analysis processing is performed on the target statement to obtain a first statement semantic feature vector. In the keyword processing link, the TF-IDF algorithm or TextRank can be used to extract the first statement keyword set from the target statement.
[0069] It can be understood that for each initial query result, the above methods such as Word2Vec, GloVe, etc. can also be used for semantic analysis processing to obtain a second statement semantic feature vector; and the TF-IDF algorithm or TextRank is used for keyword extraction processing to obtain a second statement keyword set.
[0070] Further, calculate the semantic similarity between the semantic feature vector of the first statement and the semantic feature vector of the second statement. At the same time, determine the number of overlaps between the keyword set of the first statement and the keyword set of the second statement, that is, count the number of identical keywords in the two sets. Screen the results according to the set conditions. There are two preset conditions here, and both must be satisfied simultaneously to use the corresponding initial query result as the initial query result cited by the target statement: one is that the semantic similarity must be greater than the second preset threshold, and this threshold can be set according to the actual application scenario. For example, set the threshold to 0.8. Only when the semantic similarity is higher than this value can it be initially considered that the two statements are relatively similar semantically; the other is that the number of overlaps in the keyword set should be greater than the preset number, and this preset number can also be set according to actual needs. This embodiment does not specifically limit it here. When these two conditions are satisfied simultaneously, it can be determined that the corresponding initial query result is used as the initial query result cited by the target statement. In this way, it is ensured that the initial query result has a high degree of relevance to the target statement in terms of semantics and key information.
[0071] According to the technical solution provided by the embodiment of the present application, perform semantic analysis processing and keyword extraction processing on the target statement respectively to obtain the semantic feature vector of the first statement and the keyword set of the first statement; for each initial query result, perform semantic analysis processing and keyword extraction processing respectively to obtain the semantic feature vector of the second statement and the keyword set of the second statement; calculate the semantic similarity between the semantic feature vector of the first statement and the semantic feature vector of the second statement, and determine the number of overlaps between the keyword set of the first statement and the keyword set of the second statement; if the semantic similarity is greater than the second preset threshold and the number of overlaps is greater than the preset number, then use the corresponding initial query result as the initial query result cited by the target statement. In this way, it can be ensured that the initial query result has a high degree of relevance to the target statement in terms of semantics and key information, improve the accuracy of the citation source, and avoid errors in the citation relationship between the target statement and the initial query result.
[0072] It should be understood that the magnitudes of the sequence numbers of the steps in the above embodiments do not mean the order of execution. The execution order of each process should be determined according to its function and internal logic, and should not constitute any limitation to the process of the embodiment of the present application.
[0073] All the above optional technical solutions can be combined arbitrarily to form optional embodiments of the present application, which will not be elaborated here one by one.
[0074] The following is an embodiment of the device of the present application, which can be used to execute the method embodiment of the present application. For the details not disclosed in the embodiment of the device of the present application, please refer to the method embodiment of the present application.
[0075] Figure 2It is a schematic structural diagram of a query device provided by an embodiment of the present application. As Figure 2 shown, the device includes:
[0076] A determination module 201, configured to determine an initial query result corresponding to the received query text;
[0077] An acquisition module 202, configured to generate target content according to the initial query result, and if the target content meets a preset statement end condition, acquire a target statement including the target content corresponding to the statement end condition;
[0078] A reference module 203, configured to add reference numbers to the target statement and the initial query result referred to by the target statement, where the reference number represents the reference relationship between the target statement and the initial query result, and the reference numbers are added in sequence;
[0079] A generation module 204, configured to generate a target query result corresponding to the query text according to the target statement corresponding to the reference number.
[0080] In some embodiments, the determination module 201 is further configured to retrieve multiple initial query results from a pre-set document database according to the query text, where the document database includes multiple query results, and the similarity between each initial query result and the query text is greater than a first preset threshold.
[0081] In some embodiments, the determination module 201 is further configured to perform vectorization representation on the query text to obtain a query text vector; calculate the similarity between the query text vector and each query result vector to obtain a similarity calculation result, where the query result vector is a vectorization representation of multiple query results in the document database; select the query results corresponding to the query result vectors with similarity calculation results greater than the first preset threshold as multiple initial query results.
[0082] In some embodiments, the acquisition module 202 is further configured to monitor the target content by using a callback function and a regular expression; if a statement end identifier is detected, acquire a target statement including the target content corresponding to the statement end symbol.
[0083] In some embodiments, the reference module 203 is further configured to sequentially assign numbers to the initial query results referred to by the target statement; add the numbers as reference numbers to the target statement for representing the reference relationship between the target statement and multiple initial query results.
[0084] In some embodiments, the reference module 203 is further configured to determine whether a number has been assigned to the initial query result referred to by the target statement; if it is determined that a number has been assigned to the initial query result referred to by the target statement, the assigned number is used as the number of the initial query result referred to by the target statement; adding the number as a reference number after the target statement further includes: displaying the target statement corresponding to the reference number through a visual interface; continuing to execute the preset statement end condition monitoring step and the reference number adding step until the target query result corresponding to the query text is obtained.
[0085] In some embodiments, the acquisition module 202 is further configured to perform semantic analysis processing and keyword extraction processing on the target statement respectively to obtain a first statement semantic feature vector and a first statement keyword set; for each initial query result, perform semantic analysis processing and keyword extraction processing respectively to obtain a second statement semantic feature vector and a second statement keyword set; calculate the semantic similarity between the first statement semantic feature vector and the second statement semantic feature vector, and determine the coincidence number of the first statement keyword set and the second statement keyword set; if the semantic similarity is greater than a second preset threshold and the coincidence number is greater than a preset number, the corresponding initial query result is used as the initial query result referred to by the target statement.
[0086] According to the device provided by the embodiments of the present application, in response to the received query text, the initial query result corresponding to the query text is determined; the accuracy of the subsequent generated target content can be guaranteed. The target content is generated according to the initial query result. If the target content meets the preset statement end condition, the target statement including the target content corresponding to the statement end condition is obtained; a reference number is added to the target statement and the initial query result referred to by the target statement; wherein the reference number represents the reference relationship between the target statement and the initial query result, and the reference number is added in sequence; in this way, when the target statement is generated, a reference number can be added to the target statement and the initial query result referred to by the target statement, ensuring the accuracy of the reference number while ensuring the continuity and rationality of the reference number, and avoiding the problems of number confusion, number break, and incorrect number in the prior art when generating text with reference numbers. Finally, the target query result corresponding to the query text is generated according to the target statement corresponding to the reference number, so that the target query result not only has a complete and clear content logic, but also can clearly show the reliability and relevance of its information source through the reference number.
[0087] Figure 3 is a schematic diagram of the electronic device 3 provided by the embodiments of the present application. As Figure 3As shown, the electronic device 3 of this embodiment includes: a processor 301, a memory 302, and a computer program 303 stored in the memory 302 and executable on the processor 301. When the processor 301 executes the computer program 303, the steps in the above-mentioned method embodiments are implemented. Alternatively, when the processor 301 executes the computer program 303, the functions of the various modules / units in the above-mentioned device embodiments are implemented.
[0088] The electronic device 3 can be a desktop computer, a notebook, a palm computer, a cloud server and other electronic devices. The electronic device 3 may include but is not limited to the processor 301 and the memory 302. Those skilled in the art can understand that Figure 3 merely examples of the electronic device 3, which do not constitute a limitation to the electronic device 3, may include more or fewer components than those shown in the figure, or different components.
[0089] The processor 301 can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0090] The memory 302 can be an internal storage unit of the electronic device 3, for example, the hard disk or memory of the electronic device 3. The memory 302 can also be an external storage device of the electronic device 3, for example, a plug-in hard disk equipped on the electronic device 3, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. The memory 302 can also include both the internal storage unit and the external storage device of the electronic device 3. The memory 302 is used to store the computer program and other programs and data required by the electronic device.
[0091] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above division of each functional unit and module is used as an example. In actual applications, the above functions can be assigned to different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated into a processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
[0092] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on such an understanding, to implement all or part of the processes in the above embodiment methods of this application, it can also be completed by instructing relevant hardware through a computer program. The computer program can be stored in the readable storage medium. When the computer program is executed by a processor, the steps of the above various method embodiments can be implemented. The computer program can include computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The readable storage medium can include: any entity or device that can carry the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium, etc.
[0093] The above embodiments are only used to illustrate the technical solutions of this application, rather than to limit it; although this application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the various embodiments of this application, and should all be included in the protection scope of this application.
Claims
1. A query method, characterized in that, Including: In response to the received query text, determining an initial query result corresponding to the query text; Generating target content according to the initial query result. If the target content meets a preset sentence end condition, obtaining a target sentence including the target content corresponding to the sentence end condition; Adding reference numbers to the target sentence and the initial query result cited by the target sentence, where the reference number represents the reference relationship between the target sentence and the initial query result, and the reference numbers are added in sequence; Generating a target query result corresponding to the query text according to the target sentence corresponding to the reference number.
2. The method according to claim 1, wherein The number of the initial query results is multiple. The step of determining an initial query result corresponding to the query text in response to the received query text includes: Retrieving the multiple initial query results from a pre-set document database according to the query text, where the document database includes multiple query results, and the similarity between each initial query result and the query text is greater than a first preset threshold.
3. The method according to claim 2, wherein The step of retrieving the multiple initial query results from a pre-set document database according to the query text includes: Performing vector representation on the query text to obtain a query text vector; Calculating the similarity between the query text vector and each query result vector to obtain a similarity calculation result, where the query result vector is the vector representation of the multiple query results in the document database; Selecting the query results corresponding to the query result vectors with similarity calculation results greater than the first preset threshold as the multiple initial query results.
4. The method according to claim 2, wherein The step of obtaining a target sentence including the target content corresponding to the sentence end condition if the target content meets the preset sentence end condition includes: Monitoring the target content by using a callback function and a regular expression; If a sentence end identifier is detected, obtaining a target sentence including the target content corresponding to the sentence end symbol.
5. The method according to claim 4, characterized in that, The step of adding reference numbers to the target sentence and the initial query result cited by the target sentence includes: Sequentially assigning numbers to the initial query results cited by the target sentence; Adding the number as a reference number to the target sentence to represent the reference relationship between the target sentence and the multiple initial query results.
6. The method according to claim 5, wherein Before sequentially assigning numbers to the initial query results cited by the target sentence, it further includes: Determining whether the initial query results cited by the target sentence have been assigned numbers; If it is determined that the initial query results cited by the target sentence have been assigned numbers, using the already assigned numbers as the numbers of the initial query results cited by the target sentence; After adding the number as a reference number to the target sentence, it further includes: Displaying the target sentence corresponding to the reference number through a visualization interface; Continuing to execute the preset sentence end condition monitoring step and reference number adding step until a target query result corresponding to the query text is obtained.
7. The method according to claim 2, wherein After obtaining the target statement corresponding to the statement end condition and including the target content, the following steps are further included: Performing semantic analysis processing and keyword extraction processing on the target statement respectively to obtain a first statement semantic feature vector and a first statement keyword set; For each of the initial query results, performing semantic analysis processing and keyword extraction processing respectively to obtain a second statement semantic feature vector and a second statement keyword set; Calculating the semantic similarity between the first statement semantic feature vector and the second statement semantic feature vector, and determining the coincidence number of the first statement keyword set and the second statement keyword set; If the semantic similarity is greater than a second preset threshold and the coincidence number is greater than a preset number, then using the corresponding initial query result as the initial query result cited by the target statement.
8. A query device, characterized in that, Including: A determination module configured to determine an initial query result corresponding to the query text in response to the received query text; An acquisition module configured to generate target content according to the initial query result, and if the target content meets a preset statement end condition, acquiring the target statement corresponding to the statement end condition and including the target content; A citation module configured to add citation numbers to the target statement and the initial query result cited by the target statement, where the citation number represents the citation relationship between the target statement and the initial query result, and the citation numbers are added in sequence; A generation module configured to generate a target query result corresponding to the query text according to the target statement corresponding to the citation number.
9. An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
UML (Unified Modeling Language) model search method and device based on regularized expression and storage medium
CN121029831A
Method, device and storage medium for searching uml model based on regularized expression
CN121029831B