Prompt word generation method, electronic equipment and storage medium

By calculating the similarity between query information and knowledge fragments and mining deep logical relationships in the RAG system, accurate prompt words are generated, which solves the problems of chaotic logic and low accuracy in the generated answers in the RAG system, and achieves high consistency and accuracy of query results.

CN121722871APending Publication Date: 2026-03-24CHINA UNITED NETWORK COMM GRP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-03
Publication Date
2026-03-24

AI Technical Summary

Technical Problem

Existing Retrieval Augmentation (RAG) systems suffer from logical inconsistencies, low accuracy in summarizing results, and difficulty in effectively capturing deep logical relationships between discontinuous knowledge fragments, leading to generated results that do not match the context.

Method used

By calculating the similarity between user query information and knowledge segments in the knowledge base, initial knowledge segments are obtained. Supplementary segments are determined based on the relationships between other segments in the knowledge base. A graph database is constructed to mine deep logical relationships and generate accurate prompts to improve the consistency and accuracy of the generated results.

Benefits of technology

It significantly improves the consistency, accuracy, and reliability of generated query results with contextual content, and solves the problems of logical confusion and low precision in the RAG system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121722871A_ABST
    Figure CN121722871A_ABST
Patent Text Reader

Abstract

The invention provides a cue word generation method, electronic equipment and a storage medium, relates to the technical field of natural language processing, and is used for determining an accurate cue word according to query information of a user so as to generate a query result conforming to context content. The method comprises the steps of obtaining at least one initial knowledge fragment from a knowledge base based on query information of a user; wherein the similarity between the at least one initial knowledge fragment and the query information is greater than or equal to a preset threshold value; determining supplementary knowledge fragments; the supplementary knowledge fragment is used for reflecting an association relationship between the initial knowledge fragment and other knowledge fragments in the knowledge base; determining prompt words based on the initial knowledge fragments and the supplementary knowledge fragments; the prompt word is used for generating a query result corresponding to the query information.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of natural language processing technology, and in particular to a method for generating prompt words, an electronic device, and a storage medium. Background Technology

[0002] Retrieval-Augmented Generation (RAG) technology, which combines information retrieval systems with large language models (LLMs), has become a mainstream technique for improving the factual accuracy of LLM-generated content. The RAG process typically includes steps such as text segmentation, vectorized retrieval, contextual assembly, and LLM generation. Its core is that before generating an answer, the LLM can retrieve relevant information from an external knowledge base to generate the response.

[0003] Currently, the optimization focus of the RAG system is on improving the quality and relevance of the retrieved context fragments. The size of knowledge blocks is dynamically scaled according to the specific needs of user queries. Furthermore, the complex relationships between knowledge blocks are understood through manual annotation of their connections.

[0004] However, the results generated by the above-mentioned existing technologies are often logically confused, have low summarization accuracy, or even contradict the provided context. Summary of the Invention

[0005] This application provides a method, electronic device, and storage medium for generating prompt words, used to determine accurate prompt words based on user query information, thereby generating query results that conform to the context.

[0006] In a first aspect, this application provides a method for generating prompt words, comprising: obtaining at least one initial knowledge segment from a knowledge base based on user query information; wherein the similarity between at least one initial knowledge segment and the query information is greater than or equal to a preset threshold; determining supplementary knowledge segments; the supplementary knowledge segments are used to reflect the association between the initial knowledge segments and other knowledge segments in the knowledge base; determining prompt words based on the initial knowledge segments and supplementary knowledge segments; and the prompt words are used to generate query results corresponding to the query information.

[0007] The technical solution provided in this application brings at least the following beneficial effects: by calculating the similarity between the user's query information and the knowledge segments in the knowledge base, the initial knowledge segment is accurately obtained; then, based on the association between other knowledge segments in the knowledge base and the initial knowledge segment, supplementary knowledge segments related to the initial knowledge segment are determined; subsequently, based on the initial knowledge segment and the supplementary knowledge segments, accurate prompt words are determined, thereby significantly improving the consistency, accuracy and reliability of the generated query results and the context content.

[0008] One possible implementation involves determining supplementary knowledge pieces, including: obtaining the encoding of at least one initial knowledge piece; the encoding of the initial knowledge piece is used to reflect the location information of the initial knowledge piece; based on the encoding of at least one initial knowledge piece, obtaining the context anchor file corresponding to the initial knowledge piece from a graph database; the graph database is used to reflect the logical relationships between different knowledge pieces; the context anchor file is used to reflect the encoding of knowledge pieces that have a logical relationship with the initial knowledge piece; and based on the context anchor file, determining supplementary knowledge pieces.

[0009] Another possible implementation involves determining supplementary knowledge fragments, including: determining the user's query intent based on the user's query information; determining supplementary knowledge fragments from at least one candidate supplementary knowledge fragment based on the query intent, semantic relevance, and context length information; wherein, at least one candidate supplementary knowledge fragment is another knowledge fragment in the knowledge base besides at least one initial knowledge fragment; semantic relevance is used to reflect the similarity between the initial knowledge fragment and each candidate knowledge fragment; context length information is used to reflect the character segment length of at least one initial knowledge fragment and the string length of at least one candidate supplementary knowledge fragment.

[0010] Another possible implementation involves determining supplementary knowledge fragments from at least one candidate supplementary knowledge fragment based on query intent, semantic relevance, and context length information. This includes inputting query intent, semantic relevance, context length information, and at least one candidate supplementary knowledge fragment into a relational identification model, and then filtering supplementary knowledge fragments from at least one candidate supplementary knowledge fragment through the relational identification model.

[0011] Another possible implementation is that the knowledge base is constructed as follows: each sentence in the original knowledge text is converted into a sentence vector; the similarity between adjacent sentence vectors is calculated; sentence vectors with similarity greater than a preset threshold are merged into the same knowledge segment to obtain multiple knowledge segments; and encoding is configured for each knowledge segment to obtain the knowledge base.

[0012] Another possible implementation is that the encoding of knowledge segments includes at least one of the document identifier of the original knowledge text in which the knowledge segment is located, the chapter identifier, paragraph identifier, and sentence identifier of the knowledge segment in the original knowledge text.

[0013] Another possible implementation is that the graph database is constructed based on the following steps: determining the entity type of each knowledge fragment in the knowledge base; determining the logical relationships between knowledge fragments in the knowledge base; wherein the logical relationships include explicit connections and implicit connections; and constructing the graph database based on the entity types of the knowledge fragments and the logical relationships between the knowledge fragments.

[0014] Another possible implementation method of this application includes: inputting prompt words into a large language model, and generating query results corresponding to the query information based on the prompt words through the large language model.

[0015] Secondly, this application provides a prompt word generation apparatus, comprising: an acquisition module and a processing module; the acquisition module is configured to acquire at least one initial knowledge segment from a knowledge base based on user query information; wherein the similarity between at least one initial knowledge segment and the query information is greater than or equal to a preset threshold; the processing module is configured to determine supplementary knowledge segments; the supplementary knowledge segments are used to reflect the association between the initial knowledge segments and other knowledge segments in the knowledge base; the processing module is configured to determine prompt words based on the initial knowledge segments and supplementary knowledge segments; the prompt words are used to generate query results corresponding to the query information.

[0016] One possible implementation involves a processing module specifically configured to obtain the encoding of at least one initial knowledge segment; the encoding of the initial knowledge segment is used to reflect the location information of the initial knowledge segment; based on the encoding of at least one initial knowledge segment, a context anchor file corresponding to the initial segment is obtained from a graph database; the graph database is used to reflect the logical relationships between different knowledge segments; the context anchor file is used to reflect the encoding of knowledge segments that have a logical relationship with the initial knowledge segment; and based on the context anchor file, supplementary knowledge segments are determined.

[0017] Another possible implementation involves a processing module that, based on the user's query information, determines the user's query intent; and, based on the query intent, semantic relevance, and context length information, determines supplementary knowledge fragments from at least one candidate supplementary knowledge fragment. Here, at least one candidate supplementary knowledge fragment is any other knowledge fragment in the knowledge base besides at least one initial knowledge fragment; semantic relevance reflects the similarity between the initial knowledge fragment and each candidate knowledge fragment; and context length information reflects the character segment length of at least one initial knowledge fragment and the string length of at least one candidate supplementary knowledge fragment.

[0018] Another possible implementation involves a processing module that inputs the query intent, semantic relevance, context length information, and at least one candidate supplementary knowledge fragment into the association relationship identification model, and then uses the association relationship identification model to filter out supplementary knowledge fragments from at least one candidate supplementary knowledge fragment.

[0019] Another possible implementation involves a processing module that converts each sentence in the original knowledge text into a sentence vector; calculates the similarity between adjacent sentence vectors; merges sentence vectors with similarity greater than a preset threshold into the same knowledge segment to obtain multiple knowledge segments; and configures encoding for each knowledge segment to obtain a knowledge base.

[0020] Another possible implementation is a processing module, specifically used for encoding knowledge segments, which includes at least one of the following: the document identifier of the original knowledge text where the knowledge segment is located, the chapter identifier, paragraph identifier, and sentence identifier of the knowledge segment in the original knowledge text.

[0021] Another possible implementation involves a processing module, specifically used to determine the entity type of each knowledge fragment in the knowledge base; determine the logical relationships between knowledge fragments in the knowledge base; wherein the logical relationships include explicit connection relationships and implicit connection relationships; and construct a graph database based on the entity types of the knowledge fragments and the logical relationships between the knowledge fragments.

[0022] Another possible implementation involves a processing module that inputs prompt words into a large language model, which then generates query results based on the prompt words.

[0023] 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.

[0024] 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.

[0025] Fifthly, this application provides a computer program product comprising a computer program; when the computer program is run in an electronic device, the electronic device performs the method described in the first aspect.

[0026] 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

[0027] Figure 1 A schematic diagram illustrating the application environment of the prompt word generation method provided in this application; Figure 2 A flowchart illustrating a method for generating prompt words provided in this application; Figure 3 A flowchart illustrating another method for generating prompt words provided in this application; Figure 4 A flowchart illustrating yet another method for generating prompt words provided in this application; Figure 5 A flowchart illustrating yet another method for generating prompt words provided in this application; Figure 6 A schematic diagram illustrating the composition of a prompt word generation device provided in this application; Figure 7 This is a schematic diagram of the structure of an electronic device provided in this application. Detailed Implementation

[0028] The following is a detailed description, with reference to the accompanying drawings, of a method for generating prompt words, an electronic device, and a storage medium provided in this application.

[0029] 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.

[0030] 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.

[0031] 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.

[0032] 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.

[0033] 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.

[0034] In the description of this application, unless otherwise stated, "a plurality of" means two or more.

[0035] With the continuous evolution of intelligent question-answering technology, its application value in professional fields such as enterprise knowledge management, education, and healthcare is becoming increasingly prominent. By deeply integrating domain knowledge, it enhances the accuracy, reliability, and personalization of information services. In enterprise knowledge management scenarios, it can integrate related clauses scattered across different documents (such as contracts and reports), generating well-structured summary reports for legal or financial analysis, significantly improving the reliability of professional document processing. In personalized tutoring scenarios in the education field, it can dynamically link core knowledge points and extended cases in textbooks based on student questions, generating logically clear learning guidance, effectively solving the problem of disjointed answers caused by static context splicing in traditional RAG (Research-Based Question Answering). Furthermore, in healthcare, it generates accurate answers to medical consultations based on the latest medical guidelines and clinical cases, avoiding misleading responses caused by fragmented information.

[0036] Currently, RAG systems primarily employ retrieval strategies based on physical proximity and shallow semantic similarity for contextual association. These methods typically rely on vectorized retrieval techniques, obtaining relevant information fragments by calculating metrics such as cosine similarity between the query and document blocks. In practice, the system segments the knowledge base documents and then returns text blocks similar to the query through semantic vector retrieval. To improve retrieval performance, one optimization method dynamically scales and recombines the size of the physical text blocks based on the specific needs of the user query after the initial retrieval; another optimization approach attempts to store and manage the complex relationships between knowledge fragments using a graph database by manually annotating the logical relationships between them.

[0037] However, the above methods have drawbacks: First, the contextual association is rigid, and retrieval relies solely on physical adjacency or shallow semantic similarity, making it difficult to capture the deep logical relationships between discontinuous knowledge fragments (such as the inability to effectively link definitions and cases scattered across different chapters); second, noise interference is severe, and simply returning multiple fragments can lead to irrelevant information diluting the core content, causing logical confusion or factual errors in LLM generation. Although RAG attempts to optimize retrieval quality through reordering or dynamic chunking, it still fundamentally fails to overcome the limitations of physical order.

[0038] To address the aforementioned technical issues, this application provides a method for generating prompt words. The method involves: accurately obtaining initial knowledge segments by calculating the similarity between the user's query information and knowledge segments in the knowledge base; then, determining supplementary knowledge segments related to the initial knowledge segments based on the associations between other knowledge segments in the knowledge base and the initial knowledge segments; finally, determining precise prompt words based on the initial and supplementary knowledge segments, thereby significantly improving the consistency, accuracy, and reliability of the generated query results with the context.

[0039] The embodiments provided in this application will now be described in detail with reference to the accompanying drawings.

[0040] The prompt word generation method provided in this application can be applied to, for example... Figure 1 The application environment shown. For example... Figure 1 As shown, the application environment includes a data acquisition device 10 and a processing device 20. The data acquisition device 10 and the processing device 20 are interconnected.

[0041] In some embodiments, the data acquisition device 10 synchronously acquires two types of data information through an input interface: one is structured or unstructured document content used as a basis for knowledge, and the other is query information initiated by the user. This provides a data foundation for subsequent intelligent retrieval and knowledge generation.

[0042] In some embodiments, the data acquisition device 10 can be a device with wireless transceiver capabilities, such as a mobile phone, tablet computer, wearable device, in-vehicle device, augmented reality (AR) / virtual reality (VR) device, laptop computer, ultra-mobile personal computer (UMPC), netbook, personal digital assistant (PDA), etc. This application does not limit the specific device form of the data acquisition device 10.

[0043] In some embodiments, the processing device 20, as the core processing unit of the system, first receives the original document content and user query information transmitted from the acquisition device 10. It then performs intelligent segmentation of the received document content based on semantic similarity, converting sentences in the document into high-dimensional vectors. Semantic boundaries are detected by calculating the cosine similarity of adjacent sentence vectors, thereby segmenting the document into semantically coherent knowledge fragments. After completing the knowledge fragmentation, the processing device 20 calculates the similarity between the vector representation of the user query information and the vectors of each knowledge fragment. Fragments with similarity exceeding a preset threshold are identified as initial knowledge fragments directly related to the query. The processing device 20 further mines knowledge fragments from other knowledge fragments that have a strong logical or semantic relationship with the initial knowledge fragments as supplementary knowledge fragments. Finally, the processing device 20 determines prompt words from the initial and supplementary knowledge fragments. These prompt words are input into the LLM (Local Management Module) to obtain accurate query results.

[0044] In some embodiments, the processing device 20 may be a server cluster consisting of multiple servers, a single server, a computer, or a processor or processing chip in a server or computer. This application does not limit the specific device form of the processing device 20.

[0045] 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.

[0046] See Figure 2 This is a flowchart illustrating a method for generating prompt words according to an embodiment of this application. Figure 2 As shown, the method for generating prompt words provided in this application specifically includes the following steps S201 to S203.

[0047] S201. Based on the user's query information, obtain at least one initial knowledge fragment from the knowledge base.

[0048] Among them, at least one initial knowledge fragment has a similarity to the query information that is greater than or equal to a preset threshold.

[0049] In some embodiments, the query information is an information request submitted by the user, such as a technical question, a definition inquiry, or a consultation on operating procedures.

[0050] In some embodiments, the received query information is preprocessed to improve the accuracy and efficiency of subsequent retrieval. The preprocessing includes basic natural language processing operations such as spell correction, word segmentation, and keyword extraction. Subsequently, a deep learning model is used to convert the preprocessed query information into a high-dimensional vector representation, i.e., the query vector.

[0051] For example, when a user enters the query "the development history of artificial intelligence", the system detects and corrects possible spelling errors, segments the query into "artificial intelligence", "development", and "history", and identifies the core keywords "artificial intelligence" and "development history". Using a pre-trained embedding model, the processed query is converted into a query vector representation.

[0052] In some embodiments, the knowledge base transforms the original document into a structured knowledge network rich in semantic relationships and coordinate information, which can be retrieved by the computing engine, through a series of processing procedures (such as semantic segmentation, coordinate mapping, and anchor point construction).

[0053] In some embodiments, the knowledge base is constructed as follows: each sentence in the original knowledge text is converted into a sentence vector; the similarity between adjacent sentence vectors is calculated; sentence vectors with similarity greater than a preset threshold are merged into the same knowledge segment to obtain multiple knowledge segments; and encoding is configured for each knowledge segment to obtain the knowledge base.

[0054] As an approach, a dynamic segmentation algorithm based on semantic boundaries can be used to segment the original knowledge text into knowledge segments and generate a unique code for each knowledge segment.

[0055] For example, each sentence in the original knowledge text is vectorized and converted into a high-dimensional sentence vector representation using a pre-trained embedding model; by calculating the cosine similarity between adjacent sentence vectors, a similarity sequence is generated and local minima (similarity troughs) are identified to detect semantic boundaries; then, consecutive sentences are merged based on a dynamic similarity threshold, while a rule-based post-processing step is introduced to ensure semantic integrity in scenarios such as enumeration items or step descriptions, ultimately forming knowledge fragments with consistent internal semantics.

[0056] In some embodiments, the encoding of a knowledge segment includes at least one of the document identifier of the original knowledge text in which the knowledge segment is located, the chapter identifier, paragraph identifier, and sentence identifier of the knowledge segment in the original knowledge text.

[0057] For example, a unique code with a hierarchical structure (such as "document ID_chapter ID_paragraph ID_sentence ID") is generated for each knowledge segment. A global index service is established to achieve bidirectional parsing mapping between the encoded string and structured key-value pairs (such as {doc_id: "DOC001", sec_id: "1.2", para_id: 3, sent_id: 1}). At the same time, a hierarchical title recognizer based on rules and statistical models is used to automatically analyze text features (such as prefix numbering, font features, keywords, etc.), construct a document hierarchy tree, and assign coordinate identifiers to each node, thereby giving the knowledge segment a globally locatable semantic coordinate.

[0058] In some embodiments, the query vector is input into a pre-built global index service to perform an Approximate Nearest Neighbor (ANN) search. This search process locates and returns the Top-K initial knowledge fragments with the highest semantic similarity to the query vector. The output includes not only the text content of the initial knowledge fragments but also the unique encoding corresponding to each initial knowledge fragment.

[0059] S202, Determine the supplementary knowledge segments.

[0060] Among them, supplementary knowledge fragments are used to reflect the relationship between the initial knowledge fragments and other knowledge fragments in the knowledge base.

[0061] One feasible approach is to determine supplementary knowledge fragments through queries in a graph database. This involves using the unique code corresponding to the initial knowledge fragment as the query node and performing a multi-hop traversal query in the graph database. Based on predefined logical relationship types (such as "background knowledge," "preconditions," "contrasting concepts," "supporting evidence," etc.), this query can discover and return other knowledge fragments that have direct or indirect logical relationships with the initial node, serving as supplementary knowledge fragments.

[0062] In some embodiments, the construction of the graph database is based on the semantic association mining and structured mapping between knowledge fragments in the knowledge base. It uses knowledge fragments as nodes and logical relationships (such as belonging, preconditions, etc.) between knowledge fragments as edges.

[0063] For example, graph databases can be used for deep association mining: taking one knowledge fragment as a starting point, other knowledge fragments that have direct or indirect logical connections with it can be quickly located along the relation edges through graph traversal queries and identified as supplementary knowledge fragments.

[0064] In some embodiments, the graph database is constructed based on the following: determining the entity type of each knowledge fragment in the knowledge base; determining the logical relationships between knowledge fragments in the knowledge base; wherein the logical relationships include explicit connection relationships and implicit connection relationships; and constructing the graph database based on the entity types of the knowledge fragments and the logical relationships between the knowledge fragments.

[0065] For example, the construction of a graph database involves sequentially extracting semantic nodes and mining logical relationships from knowledge fragments to form a directed graph structure. The specific steps are as follows: First, semantic node extraction is performed, including determining entity types and extracting topic sentences, and knowledge fragments are organized into structured data with clear attributes (entity labels, topic summaries).

[0066] Determine entity types: Use a sequence labeling model (such as a Transformer-based model) to perform reasoning on the text of the knowledge pieces, automatically identifying and labeling entities belonging to predetermined categories (such as PERSON, ORG, TECH_CONCEPT, etc.). This is equivalent to tagging the knowledge pieces with content tags.

[0067] Topic sentence extraction: A deep learning model is used to calculate the saliency score of each sentence within a knowledge segment. This score comprehensively considers sentence position features (e.g., the first and last sentences of a paragraph have higher weights), semantic features (cosine similarity between the sentence vector and the entire knowledge segment vector), and statistical features (whether it contains high-frequency keywords from the document or segment). Finally, the top 1 to 2 sentences with the highest scores are marked as the topic sentences of that knowledge segment, serving as its core semantics.

[0068] Secondly, logical relationship mining is carried out, including parsing sentence relationships within knowledge segments and mining relationships between knowledge segments, connecting individual knowledge segments into a knowledge system with rich semantic relationships.

[0069] Sentence Relationship Analysis within Knowledge Pieces: Performs complete syntactic analysis and semantic role labeling on knowledge piece texts to identify keywords that represent logical relationships (such as "because" indicating cause, "therefore" indicating result) and their associated arguments.

[0070] Knowledge fragment relationship mining: When an argument is found to be incomplete (for example, a concluding sentence mentions "the above method", but the definition of "method" is not in this knowledge fragment), the reference resolution and entity linking module is activated. The target knowledge fragment containing the most matching entity definition or description is searched in the global knowledge base, and a logical edge with a clear type (such as "background knowledge" or "preconditions") is automatically established from the current knowledge fragment to the target knowledge fragment.

[0071] In addition, to capture non-explicit but semantically relevant connections, the system calculates the cosine similarity between the core semantic vector of the current knowledge segment and the topic vectors of all other knowledge segments in the knowledge base. For knowledge segments with similarity exceeding an adaptive threshold (e.g., two standard deviations above the average similarity), a logical edge of type "semantically relevant" is established, indicating that the two are highly semantically related.

[0072] As another possible approach, determining supplementary knowledge segments can be achieved through secondary retrieval using reinforcement learning. This includes: converting the user's query information and initial knowledge segments into vector representations, identifying the user's query intent, calculating the similarity between the initial knowledge segments and candidate supplementary knowledge segments, continuously calculating the character segment length of the initial knowledge segments and the string length of the candidate supplementary knowledge segments, and determining the supplementary knowledge segments through an association recognition model.

[0073] S203. Based on the initial knowledge fragments and supplementary knowledge fragments, determine the prompt words.

[0074] The prompt words are used to generate query results corresponding to the query information.

[0075] In some embodiments, prompt words are generated through a multi-stage structured processing. First, the system logically sorts the initial knowledge fragments and supplementary knowledge fragments according to their corresponding codes, restoring the logical reading order of the initial and supplementary knowledge fragments in the original knowledge text. Then, metadata is added to each knowledge fragment by injecting semantically meaningful XML tags. Finally, the sorted and tagged knowledge fragments and user query information are filled into a preset template, which contains explicit instructions, resulting in prompt words rich in semantic guidance.

[0076] For example, the initial knowledge fragments and supplementary knowledge fragments are merged. The fragments are then sorted according to their internal logic based on their corresponding codes (e.g., document ID, chapter ID, paragraph ID).

[0077] For example, to guide LLM to focus on the importance of different knowledge pieces, each knowledge piece is wrapped with semantically meaningful XML tags. For instance: <directlyretrieved rank="1"> [Initial Knowledge Fragment Content]< / directlyretrieved> #Guidelines for prioritizing the use of this section in LLM model development <contextual relation="Definition"> [Supplementary Knowledge Segmentation Content]< / contextual> # Provide the definition when the query involves technical terms. <contextual relation="Supporting_Evidence"> [Supplementary Knowledge Segmentation Content]< / contextual> #Provide factual support for LLM's answer In some embodiments, the prompt words are input into a large language model, and the large language model generates query results corresponding to the query information based on the prompt words.

[0078] For example, “Please answer the question strictly based on the tagging context provided below. Prioritize comprehensive citations.” <directlyretrieved>The content within the tag, and can be used <contextual>The information in the tags is used to supplement the explanation. This ensures the accuracy and completeness of the answer. By guiding the LLM generation process with comprehensive knowledge segmentation, structured tags, and clear instructional prompts, the accuracy, relevance, and factual consistency of query results are effectively improved.

[0079] Based on the above embodiments, the initial knowledge segment is accurately obtained by calculating the similarity between the user's query information and the knowledge segments in the knowledge base; then, supplementary knowledge segments related to the initial knowledge segment are determined based on the association between other knowledge segments in the knowledge base and the initial knowledge segment; subsequently, accurate prompt words are determined based on the initial knowledge segment and the supplementary knowledge segments, thereby significantly improving the consistency, accuracy and reliability of the generated query results and the context content.

[0080] In some embodiments, such as Figure 3 As shown, step S202 above, which determines the supplementary knowledge fragments, can be specifically implemented as the following steps S301~S303: S301. Obtain the encoding of at least one initial knowledge segment.

[0081] The encoding of the initial fragment is used to reflect the location information of the initial knowledge fragment.

[0082] For example, the initial knowledge fragment is encoded as DOC001_2.3.1_4_1. By parsing this encoding, the location information of the initial knowledge fragment is obtained. Here, DOC001 indicates that the knowledge fragment originates from the original knowledge text with the ID DOC001 in the knowledge base; 2.3.1 indicates that the knowledge fragment is located in Chapter 2, Section 3, and Subsection 1 of the document; 4 indicates that the knowledge fragment is the 4th paragraph within that subsection; and 1 indicates that the fragment is the 1st knowledge fragment divided within that paragraph.

[0083] S302. Based on the encoding of at least one initial knowledge segment, obtain the context anchor file corresponding to the initial segment from the graph database.

[0084] The graph database is used to reflect the logical relationships between different knowledge pieces; the context anchor file is used to reflect the encoding of knowledge pieces that have logical relationships with the initial knowledge piece.

[0085] In some embodiments, the encoding of the retrieved Top-K initial knowledge chunks is used to initiate a batch query to the graph database (e.g., SELECT content FROM chunks WHERE encoding IN ( ... )). The query result is a structured list, i.e., a context anchor file.

[0086] For example, the encoding of the initial knowledge fragment (e.g., DOC001_2.3.1_4_1) is used as the query key to initiate a targeted traversal query to the graph database. The graph database treats these encodings as specific nodes in the graph and traverses along pre-established relational edges (e.g., "background knowledge," "supporting evidence," "technical details") to find all directly or indirectly related nodes. The resulting context anchor file records in detail the encodings that have logical relationships with the initial knowledge fragment and the specific relationship types between them and the initial knowledge fragment (e.g., definition, example, etc.).

[0087] S303. Determine supplementary knowledge fragments based on context anchor files.

[0088] In some embodiments, the anchor file is parsed to extract the encoding of all associated knowledge pieces. The encoding directly locates the unique corresponding piece content in the knowledge base, forming a "set of encodings to be acquired". Based on the "set of encodings to be acquired", a batch query request is sent to the graph database (e.g., SELECT content FROM chunksWHERE encoding IN (...)) to obtain the supplementary knowledge piece content corresponding to all these encodings. Deduplication is performed to ensure that existing knowledge pieces are not added repeatedly.

[0089] In some embodiments, such as Figure 4 As shown, the above step S202, which determines the supplementary knowledge fragments, can also be specifically implemented as the following steps S401~S402: S401. Determine the user's query intent based on the user's query information.

[0090] In some embodiments, the user's query information is input into a pre-trained multi-class text classifier (such as using a neural network model), which outputs a probability distribution vector on a predefined intent category.

[0091] For example, when a user enters query information, the system inputs the query text into a classifier. The classifier vectorizes the query information and performs multi-classification calculations, ultimately outputting a probability distribution vector on predefined intent categories (such as fact query, analysis query, definition query, and comparison query), for example: {"Comparison query": 0.92, "Analysis query": 0.06, "Fact query": 0.01, "Definition query": 0.01}. The system determines the intent category with the highest probability (here, "comparison query") as the user's query intent.

[0092] S402. Based on query intent, semantic relevance, and context length information, determine supplementary knowledge fragments from at least one candidate supplementary knowledge fragment.

[0093] Among them, at least one candidate supplementary knowledge segment is another knowledge segment in the knowledge base besides at least one initial knowledge segment; semantic relevance is used to reflect the similarity between the initial knowledge segment and each candidate knowledge segment; context length information is used to reflect the character segment length of at least one initial knowledge segment and the string length of at least one candidate supplementary knowledge segment.

[0094] In some embodiments, a pre-trained semantic embedding model is used to convert the initial knowledge fragments and candidate supplementary knowledge fragments into high-dimensional vector representations. The vectors represent the deep semantic information of the text, and the degree of semantic association is obtained by calculating the cosine similarity between the two vectors.

[0095] In some embodiments, context length information is used to manage the total length of prompts to be entered into the LLM in real time (typically calculated in terms of token count or character count). This prevents subsequent prompts from exceeding the maximum context window limit of the LLM and ensures that the most relevant information is prioritized within the limited space.

[0096] In some embodiments, query intent, semantic relevance, context length information, and at least one candidate supplementary knowledge fragment are input into the association relationship identification model, and supplementary knowledge fragments are selected from at least one candidate supplementary knowledge fragment through the association relationship identification model.

[0097] In some embodiments, the decision-making process for determining the final supplementary knowledge piece from candidate supplementary knowledge pieces is performed by a relation recognition model trained by reinforcement learning. This model integrates multiple dimensions of features, such as query intent, semantic relevance, and context length information, into a state vector, and independently calculates the probability of each candidate piece being included in the context, dynamically filtering supplementary knowledge pieces.

[0098] For example, an association recognition model (such as a deep policy network) outputs an action probability P(include) independently for each candidate supplementary knowledge slice based on the current state vector. A dynamic decision threshold θ is set; when P(include) > θ, the candidate supplementary knowledge slice is included in the supplementary knowledge slice. The threshold θ itself can be fine-tuned based on the currently accumulated context length information to achieve length control.

[0099] In some embodiments, the decision-making ability of the association recognition model is acquired through training, and the training process is designed as follows:

[0100] in, This indicates an encouragement for the model to generate a final answer that matches the reference answer in terms of content; This means that a specialized evaluation model is used to penalize answers that cannot be traced back to the provided context, which is key to suppressing model "illusions". This indicates a slight penalty for generating overly long or redundant answers or using too much context.

[0101] Based on historical dialogue data, the parameters of the association recognition model are iteratively updated using policy gradient methods (such as REINFORCE or PPO). By continuously trying different screening decisions, receiving reward feedback, and adjusting the strategy, the model eventually learns how to select supplementary knowledge fragments.

[0102] The following describes a specific embodiment of the prompt word generation method of this application. The specific implementation process of this method is as follows: Figure 5 As shown.

[0103] S501. Based on the user's query information, obtain at least one initial knowledge fragment from the knowledge base.

[0104] S502. Determine supplementary knowledge fragments from the graph database or through the association relationship identification model.

[0105] S503. Based on the initial knowledge fragments and supplementary knowledge fragments, determine the prompt words.

[0106] S504: The large language model generates query results corresponding to the query information based on the prompt words.

[0107] 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.

[0108] This application embodiment can divide the prompt word generation device into functional modules according to the above method example. For example, each function can be divided into a separate 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.

[0109] In some embodiments, this application also provides a prompt word generation apparatus. The prompt word generation apparatus may include one or more functional modules for implementing the prompt word generation method of the above method embodiments.

[0110] For example, Figure 6 This is a schematic diagram illustrating the composition of a prompt word generation device provided in an embodiment of this application. For example... Figure 6 As shown, the prompt word generation device 600 includes an acquisition module 601 and a processing module 602.

[0111] The acquisition module 601 is used to acquire at least one initial knowledge segment from the knowledge base based on the user's query information; wherein the similarity between at least one initial knowledge segment and the query information is greater than or equal to a preset threshold; the processing module 602 is used to determine supplementary knowledge segments; the supplementary knowledge segments are used to reflect the association between the initial knowledge segments and other knowledge segments in the knowledge base; the processing module 602 is used to determine prompt words based on the initial knowledge segments and supplementary knowledge segments; the prompt words are used to generate query results corresponding to the query information.

[0112] In some embodiments, the processing module 602 is specifically used to obtain the encoding of at least one initial knowledge segment; the encoding of the initial knowledge segment is used to reflect the location information of the initial knowledge segment; based on the encoding of at least one initial knowledge segment, the context anchor file corresponding to the initial segment is obtained from the graph database; the graph database is used to reflect the logical relationship between different knowledge segments; the context anchor file is used to reflect the encoding of knowledge segments that have a logical relationship with the initial knowledge segment; based on the context anchor file, supplementary knowledge segments are determined.

[0113] In other embodiments, the processing module 602 is specifically configured to determine the user's query intent based on the user's query information; and to determine supplementary knowledge fragments from at least one candidate supplementary knowledge fragment based on the query intent, semantic relevance, and context length information; wherein, at least one candidate supplementary knowledge fragment is another knowledge fragment in the knowledge base besides at least one initial knowledge fragment; the semantic relevance is used to reflect the similarity between the initial knowledge fragment and each candidate knowledge fragment; and the context length information is used to reflect the character segment length of at least one initial knowledge fragment and the string length of at least one candidate supplementary knowledge fragment.

[0114] In some other embodiments, the processing module 602 is specifically used to input the query intent, semantic relevance, context length information and at least one candidate supplementary knowledge fragment into the association relationship recognition model, and to filter out supplementary knowledge fragments from at least one candidate supplementary knowledge fragment through the association relationship recognition model.

[0115] In some other embodiments, the processing module 602 is specifically used to convert each sentence in the original knowledge text into a sentence vector; calculate the similarity between adjacent sentence vectors; merge sentence vectors with similarity greater than a preset threshold into the same knowledge segment to obtain multiple knowledge segments; and configure encoding for each knowledge segment to obtain a knowledge base.

[0116] In some other embodiments, the processing module 602 is specifically used for encoding knowledge segments, including at least one of the document identifier of the original knowledge text in which the knowledge segment is located, the chapter identifier, paragraph identifier, and sentence identifier of the knowledge segment in the original knowledge text.

[0117] In some other embodiments, the processing module 602 is specifically used to determine the entity type of each knowledge piece in the knowledge base; determine the logical relationships between knowledge pieces in the knowledge base; wherein the logical relationships include explicit connection relationships and implicit connection relationships; and construct a graph database based on the entity type of the knowledge pieces and the logical relationships between the knowledge pieces.

[0118] In some other embodiments, the processing module 602 is specifically used to input the prompt words into the large language model, and generate query results corresponding to the query information based on the prompt words through the large language model.

[0119] 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 700 includes: a processor 702, a communication interface 703, and a bus 704. Optionally, the electronic device 700 may also include a memory 701.

[0120] Processor 702 may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 702 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 702 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.

[0121] The communication interface 703 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.

[0122] The memory 701 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 medium or other magnetic storage device, 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.

[0123] As one possible implementation, the memory 701 can exist independently of the processor 702. The memory 701 can be connected to the processor 702 via a bus 704 and is used to store instructions or program code. When the processor 702 calls and executes the instructions or program code stored in the memory 701, it can implement the prompt word generation method provided in this embodiment of the invention.

[0124] In another possible implementation, the memory 701 can also be integrated with the processor 702.

[0125] The 704 bus can be an extended industry standard architecture (EISA) bus, etc. The 704 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.

[0126] 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.

[0127] 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.

[0128] 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 prompt word generation methods provided in the above embodiments.

[0129] 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.< / contextual> < / directlyretrieved>

Claims

1. A method of generating a prompt word, characterized by, The method comprises: obtaining at least one initial knowledge slice from a knowledge base based on user query information; wherein the similarity between the at least one initial knowledge slice and the query information is greater than or equal to a preset threshold; determining a supplementary knowledge slice; the supplementary knowledge slice is used to reflect the association relationship between the initial knowledge slice and other knowledge slices in the knowledge base; determining a prompt word based on the initial knowledge slice and the supplementary knowledge slice; the prompt word is used to generate a query result corresponding to the query information.

2. The method of claim 1, wherein, The method of determining a supplementary knowledge slice comprises: obtaining the encoding of the at least one initial knowledge slice; the encoding of the initial slice is used to reflect the position information of the initial knowledge slice; obtaining a context anchor file corresponding to the initial slice from a graph database based on the encoding of the at least one initial knowledge slice; the graph database is used to reflect the logical relationship between different knowledge slices; the context anchor file is used to reflect the encoding of the knowledge slice that has a logical relationship with the initial knowledge slice; determining the supplementary knowledge slice based on the context anchor file.

3. The method of claim 1, wherein, The method of determining a supplementary knowledge slice comprises: determining the query intention of the user based on the query information of the user; determining the supplementary knowledge slice from at least one candidate supplementary knowledge slice based on the query intention, semantic correlation degree and context length information; wherein the at least one candidate supplementary knowledge slice is other knowledge slices in the knowledge base except the at least one initial knowledge slice; the semantic correlation degree is used to reflect the similarity between the initial knowledge slice and each candidate knowledge slice; the context length information is used to reflect the character segment length of the at least one initial knowledge slice and the string length of the at least one candidate supplementary knowledge slice.

4. The method of claim 3, wherein, The method of determining the supplementary knowledge slice from at least one candidate supplementary knowledge slice based on the query intention, semantic correlation degree and context length information comprises: inputting the query intention, the semantic correlation degree, the context length information and the at least one candidate supplementary knowledge slice into an association relationship identification model, and screening the supplementary knowledge slice from the at least one candidate supplementary knowledge slice through the association relationship identification model.

5. The method of claim 1, wherein, The knowledge base is constructed in the following way: convert each sentence in the original knowledge text into a sentence vector; calculate the similarity between adjacent sentence vectors; merge the sentence vectors with a similarity greater than a preset threshold into the same knowledge slice to obtain multiple knowledge slices; configure the encoding for each knowledge slice to obtain the knowledge base.

6. The method of claim 5, wherein, The encoding of the knowledge slice comprises at least one of the document identifier of the original knowledge text where the knowledge slice is located, the chapter identifier, the paragraph identifier and the sentence identifier of the original knowledge text.

7. The method of claim 2, wherein, The graph database is constructed in the following way: determine the entity type of each knowledge slice in the knowledge base; determine the logical relationship between the knowledge slices in the knowledge base; wherein the logical relationship comprises a display connection relationship and an implicit connection relationship; Construct the graph database based on the entity types of the knowledge shards and the logical relationships between the knowledge shards.

8. The method of claim 1, wherein, The method further includes: inputting the prompt word into a large language model, and generating a query result corresponding to the query information based on the prompt word through the large language model.

9. An electronic device, comprising: A computer device includes a processor and a memory, the processor is coupled with the memory; the memory is used to store computer instructions, the computer instructions are loaded and executed by the processor to enable the computer device to implement the prompt word generation method according to any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that, The computer readable storage medium includes computer execution instructions, when the computer execution instructions run on the computer, make the computer execute the prompt word generation method according to any one of claims 1 to 8.