Rag and knowledge graph-based dual-channel knowledge retrieval and answer generation method

By constructing a hybrid knowledge base and introducing service document knowledge into knowledge graph reasoning, an intent path that integrates structure and text is generated, solving the problem of inaccurate answer generation in cultural and tourism information services, achieving accuracy and personalization of answers, and improving user experience.

CN122489705APending Publication Date: 2026-07-31BEIJING YUETU TRAVEL TECH (GRP) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING YUETU TRAVEL TECH (GRP) CO LTD
Filing Date
2026-05-08
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

In existing cultural and tourism information services, the integration of structured knowledge and unstructured information is insufficient, resulting in inaccurate answer generation and difficulty in meeting users' personalized needs.

Method used

A hybrid knowledge base is constructed, which integrates user queries and real-time context. Service document knowledge is introduced into the knowledge graph reasoning process through semantic bridging to generate intent paths that integrate structural knowledge and textual knowledge. Confidence is calculated on the structural knowledge and text fragments in the intent paths, and finally, the enhanced context input is used to generate answers from a large language model.

Benefits of technology

It achieves a deep integration of structured knowledge and textual knowledge, improves the accuracy and reliability of answers, meets users' personalized needs, and enhances user experience through multimodal output.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122489705A_ABST
    Figure CN122489705A_ABST
Patent Text Reader

Abstract

This invention discloses a dual-channel knowledge retrieval and answer generation method based on RAG and knowledge graph, belonging to the field of machine learning technology. The method includes: constructing a hybrid knowledge base comprising service documents and a knowledge graph; fusing user queries and real-time context to form a context-aware query; parsing the context-aware query to initialize a graph reasoning task; introducing service document knowledge during the reasoning task execution process through semantic bridging to generate an intent path that integrates structural and textual knowledge; retrieving text fragments from the service documents based on the intent path; calculating the confidence of the structural knowledge and text fragments in the intent path; and reconstructing the evaluated and filtered information into a logically coherent enhanced context using the intent path as the narrative thread; and inputting the enhanced context into a large language model to generate the final answer. This invention can significantly improve the accuracy of answer generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of machine learning technology, specifically relating to a dual-channel knowledge retrieval and answer generation method based on RAG and knowledge graph. Background Technology

[0002] Large language models have demonstrated powerful capabilities in natural language understanding and generation, and are finding increasingly widespread application in the cultural and tourism industry. By interacting with users through natural language, large language models can understand the complex and personalized needs of users in scenarios such as travel planning, information retrieval, and service booking, and provide users with services such as itinerary planning, attraction introductions, and real-time Q&A, thereby improving the intelligence level of cultural and tourism information services and the user experience.

[0003] Existing technologies for handling such tasks typically employ Retrieval Augmentation Generation (RAG) frameworks or knowledge graph-based question-answering methods. When using RAG, the system first converts the user's query into a vector, then performs a similarity search on a pre-built vector database composed of unstructured documents such as travel guides and user reviews to retrieve relevant text fragments. These text fragments, along with the original query, are then fed into a large language model as context to generate the final answer. Knowledge graph-based methods, on the other hand, parse the user's natural language query into a structured query statement, perform a precise search within a knowledge graph containing entities such as attractions, hotels, and restaurants and their relationships, and use the factual results from the query to generate the answer.

[0004] However, methods that solely rely on retrieval-enhanced generation, whose retrieval process is based solely on semantic similarity, may lack logical connections between the obtained text fragments, resulting in cluttered and unreliable contextual information provided to large language models. Methods that solely rely on knowledge graphs, while ensuring answer accuracy, struggle to store and represent the rich subjective descriptions and detailed experiences found in guides and reviews, failing to meet users' personalized information needs. When these two technologies are combined, the interaction is typically superficial, making it difficult to deeply integrate the structured reasoning advantages of knowledge graphs with the rich semantic information of text. Therefore, the inaccurate answer generation also suffers from insufficient integration of structured knowledge and unstructured information. Summary of the Invention

[0005] To address the aforementioned problems, this invention provides a dual-channel knowledge retrieval and answer generation method based on RAG and knowledge graph, thereby resolving the issues present in the background technology.

[0006] To achieve the aforementioned objectives, this invention proposes a dual-channel knowledge retrieval and answer generation method based on RAG and knowledge graphs, comprising: Build a hybrid knowledge base, which includes service documents and knowledge graphs; Integrate user queries with real-time context to form context-aware queries, and parse context-aware queries to initialize graph reasoning tasks; Perform reasoning tasks on the knowledge graph, and introduce service document knowledge during the reasoning task execution process through semantic bridging to generate intent paths that integrate structural knowledge and textual knowledge; Based on the intent path, text fragments are retrieved from the service document. Confidence is calculated on the structural knowledge and text fragments in the intent path. Using the intent path as the narrative thread, the evaluated and filtered information is reconstructed into a logically coherent enhanced context. The input context is enhanced to the large language model to generate the final answer, and the output is adapted to a multimodal format.

[0007] Furthermore, generating an intent path that integrates structural knowledge and textual knowledge includes the following steps: Identify location entities in context-aware queries, and use the identified location entities as starting nodes to execute graph reasoning algorithms in the knowledge graph. During the search process of the graph reasoning algorithm, if a search branch is determined to be inefficient, a temporary semantic edge is constructed. During the path evaluation process, the preference weights applied to the current path are temporarily adjusted based on the text fragment content of the final node of the current complete path. The comprehensive score of each path is calculated based on the structural cost of the path and the adjusted preference weights, and the intent path including the comprehensive score is output.

[0008] Furthermore, if the search branch is determined to be inefficient, a temporary semantic edge is constructed, including the following steps: If a branch expands in N consecutive steps and its dynamic evaluation score increases below a preset threshold, or if the path expands to an information hub node, it is determined to be inefficient. The context information of the current path is aggregated to generate descriptive text. The descriptive text is converted into a context vector through a text embedding model. The context vector is used to perform an approximate nearest neighbor search in the service document and return a text fragment. The text discovery node is extracted from the text fragment. Define the last node of the current search branch as the search node, obtain the physical travel cost between the current search node and the text discovery node, calculate the weight of the temporary semantic edge by combining the semantic matching score and the physical travel cost, and establish a connection between the current search node and the text discovery node to construct the temporary semantic edge.

[0009] Furthermore, temporarily adjusting the preference weights applied to the current path branch includes the following steps: Retrieve text fragments related to the final node, perform sentiment analysis on the text fragments, identify descriptions related to user preference entities, and when specific conditions in the text descriptions are met, adjust the preference weights applied to the current path according to preset correction rules.

[0010] Further, retrieving text fragments from the service document based on the intent path includes the following steps: Extract path node entities and path relationship constraints from the intent path, combine the path node entities and path relationship constraints into at least one keyword group, and retrieve text fragments from the service document based on the keyword group.

[0011] Furthermore, confidence is calculated for the structural knowledge and text fragments in the intent path, including the following steps: Assign a first initial score to structural knowledge and a second initial score to text fragments. Connect to an external real-time interface to obtain dynamic data. Compare the structural knowledge and text fragments with the dynamic data respectively. Based on the comparison results, correct the first and second initial scores, and use the corrected scores as the confidence levels of structural knowledge and text fragments respectively.

[0012] Furthermore, using the intention path as the narrative thread, the evaluated and filtered information is reconstructed into a logically coherent enhanced context, including the following steps: The confidence score is used as the initial score. Based on the initial score, the structural knowledge and text fragments are processed to construct a candidate information set. The information items in the candidate information set are weighted and sorted. The weighted and sorted information items are reconstructed into logically coherent text to form a reconstructed enhanced context.

[0013] Further, a candidate information set is constructed, including the following steps: Based on the initial scores of all structural knowledge and text fragments, a screening threshold is calculated, and structural knowledge and text fragments with initial scores not lower than the screening threshold are added to the candidate information set. For text fragments with initial scores below the screening threshold, an attribute extraction model is used to identify and extract attribute clauses describing predefined attributes from the text fragments. The information value score of the attribute clauses is evaluated, and attribute clauses with information value scores not lower than a preset local threshold are retained and added to the candidate information set.

[0014] Furthermore, the weighted and sorted information items are reconstructed into logically coherent text, including the following steps: Each information item in the candidate information set is associated with the corresponding node or edge in the intent path based on the entity or relationship it describes. The highest-scoring intent path is used as the main narrative thread. It is traversed according to its node sequence. During the traversal, for each node in the path, all related information items are integrated, and the content is organized into descriptive statements according to the preset text template. The descriptive statements generated along the path are concatenated and smoothed using conjunctions to ultimately form an enhanced context.

[0015] The beneficial effects of this invention are as follows: This invention first constructs a hybrid knowledge base comprising service documents and a knowledge graph, and initializes the graph reasoning task by integrating user queries and real-time context. During the knowledge graph reasoning process, service document knowledge is dynamically introduced through semantic bridging, thereby generating an intent path that integrates structural and textual knowledge. This merges the structured reasoning advantages of the graph with the rich semantic information of the text. Subsequently, text fragments are retrieved from the service documents based on the intent path, and confidence scores are calculated for the structural knowledge and text fragments within the intent path, thus effectively filtering and verifying multi-source information and improving the accuracy and reliability of the information. By using the intent path as the narrative thread, the evaluated and filtered information is reconstructed into a logically coherent enhanced context, which is then input into a large language model, thereby generating the final answer. This invention solves the problem in existing technologies where insufficient integration of structured and unstructured information leads to inaccurate answer generation. Attached Figure Description

[0016] Figure 1 This is a flowchart illustrating the steps of a dual-channel knowledge retrieval and answer generation method based on RAG and knowledge graph according to the present invention. Detailed Implementation

[0017] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0018] It is understood that the terms "first," "second," etc., used in this application may be used herein to describe various elements, but unless otherwise specified, these elements are not limited by these terms. These terms are used only to distinguish one element from another. For example, without departing from the scope of this application, a first script may be referred to as a second script, and similarly, a second script may be referred to as a first script.

[0019] It should be noted in advance that all data processing in this invention is carried out in accordance with relevant regulations and with the authorization of the authorized administrator.

[0020] like Figure 1 As shown, a dual-channel knowledge retrieval and answer generation method based on RAG and knowledge graph includes: Build a hybrid knowledge base, which includes service documents and knowledge graphs.

[0021] A hybrid knowledge base is a knowledge storage system that integrates two different forms of data. Service documents refer to unstructured text such as travel guides and user reviews obtained through web crawling or customization. Knowledge graphs, on the other hand, are structured knowledge bases built using information extraction techniques. They store core factual information about attractions, restaurants, hotels, etc., in the form of entities, relationships, and attributes, such as geographical location, opening hours, and price range.

[0022] Integrate user queries with real-time context to form context-aware queries, and parse context-aware queries to initialize graph reasoning tasks.

[0023] Users' natural language queries are often concise or even incomplete, making direct processing insufficient to accurately meet their personalized needs. This step combines the user's immediate needs with the dynamic environment to generate queries with more specific intent. Real-time context refers to dynamic information such as the user's current geographical location, device time, and user profiles based on historical behavior. Context-aware query is an internal query representation formed by fusing the user's original query text with real-time context information. Initialization of the graph reasoning task involves parsing the core entities (such as "Forbidden City" and "hot pot") and constraints (such as "nearby" and "few people") from the context-aware query, locating these entities as starting or target nodes in the knowledge graph, thereby initiating the graph search algorithm.

[0024] Perform reasoning tasks on the knowledge graph, and introduce service document knowledge during the reasoning task execution process through semantic bridging to generate intent paths that integrate structural knowledge and textual knowledge.

[0025] Semantic bridging refers to the process of using the contextual information of the current path to perform semantic retrieval from the service document when graph reasoning gets stuck in local optima or inefficient exploration. This allows for the discovery of new entities from the retrieved text, and the dynamic construction of a temporary semantic edge connection in the graph, enabling a jump in the reasoning path. The resulting intent path is a sequence of one or more nodes that not only contains structured entities and relationships from the knowledge graph but also incorporates knowledge from the service document through semantic bridging. The specific implementation of semantic bridging will be discussed in detail later.

[0026] Text fragments are retrieved from service documents based on intent paths. Confidence is calculated on the structural knowledge and text fragments in the intent paths. Using the intent paths as the narrative thread, the evaluated and filtered information is reconstructed into a logically coherent enhanced context.

[0027] Confidence calculation involves cross-validating information points retrieved from service documents and structured facts in the knowledge graph with real-time data obtained from external interfaces, and assessing their credibility based on factors such as the authority and timeliness of the information source. The intent path acts as the narrative thread, ensuring the logical organization of information. Finally, the verified and evaluated high-confidence information is organized and arranged according to the node order of the intent path, forming a logically coherent enhanced context.

[0028] The input context is enhanced to the large language model to generate the final answer, and the output is adapted to a multimodal format.

[0029] Specifically, directly outputting structured data or fragmented text snippets results in a poor user experience. This step leverages the powerful natural language generation capabilities of the large language model to organize the enhanced context built in previous steps into a fluent conversational response. Multimodal output refers to further adapting and packaging the plain text answer into various formats such as graphic cards, map route displays, and voice broadcasts to enhance the user experience, presenting it to the user in a more intuitive and convenient way. The large language model can employ a Transformer-based architecture, which is a current technology and will not be discussed further here.

[0030] In real-world scenarios, users' service needs are often vague and involve multiple conditions. For example, a tourist in location A might want to find a local specialty food restaurant with no queues nearby. Existing map or travel apps typically use location A as the center, searching for nearby restaurants on the map and then filtering out those mentioned in reviews about queues based on the user's preference for avoiding queues. However, this approach leads to a narrow recommendation scope. The app might only recommend shops within a few blocks around location A, but in reality, a local might tell you, "Take a ten-minute taxi ride to B Street; that's where you'll find truly authentic food without waiting." Existing technology, limited to the immediate vicinity on the map, cannot discover such better alternatives. Furthermore, an app might exclude a roast duck restaurant simply because it has a queue, but it cannot understand information like "the taste is amazing, worth the hour-long wait," indicating that users are sometimes willing to sacrifice their preference for no queues for a top-notch specialty experience. Therefore, this embodiment proposes the following technical solution.

[0031] In this embodiment, generating an intent path that integrates structural knowledge and textual knowledge includes the following steps: Identify location entities in context-aware queries, and use the identified location entities as starting nodes to execute graph reasoning algorithms in the knowledge graph. During the search process of the graph reasoning algorithm, if a search branch is determined to be inefficient, a temporary semantic edge is constructed.

[0032] First, the received user query text is processed using a pre-trained named entity recognition model. The named entity recognition model can employ mainstream sequence labeling models, such as the BiLSTM-CRF model. For example, if the query text is: "I am currently in location A and want to find a nearby specialty food stall without a queue," the named entity recognition model identifies: the location entity as location A, the activity entity as "finding food," and the preference entities as "no queue" and "specialty." The system uses the location entity A as the starting node for graph traversal and the food stalls mapped from the activity entity "finding food" as the final node, loading initial preference weights from the user profile, thus incorporating real-time context.

[0033] The following example illustrates a method for determining preference weights. First, preference dimensions are defined corresponding to the preference entity, such as [price], [queue status], [taste characteristics], and [distance]. User profiles are built by continuously analyzing users' historical interaction data, including preference terms used in historical queries, attributes of the final selected or booked service, and user reviews. For each preference dimension, a baseline score is assigned to each positive or negative user action. For example, if a user mentions "no queue, great experience" in a review, N points are added to the user's "no queue" preference in the [queue status] dimension. If a user ultimately chooses a restaurant whose review mentions "one-hour queue" but "amazing taste," M points are added to the "unique" preference in the [taste characteristics] dimension, while P points are deducted from the "no queue" preference in the [queue status] dimension (M>P, indicating the user is willing to sacrifice queuing for uniqueness). The scores of all preference dimensions are periodically aggregated, and a normalization function is used to convert these raw scores into weights ranging from [0, 1]. Using this method, personalized initial preference weights can be generated for the current query. For example, for a user who has repeatedly chosen "less crowded" and "no reservation required" services in the past, the calculation may show that the weight of "no queue" for the preferred entity is 0.9, while the weight of "unique features" is 0.8.

[0034] In particular, for new users with insufficient historical behavior, the average preference weight of similar user groups can be used as the initial value, or the popular preference weight from global statistics or the preset default value weight can be used.

[0035] During the search, the adaptive graph reasoning algorithm is based on a weighted, bidirectional breadth-first search framework. The search process begins with a starting node and iteratively explores neighboring nodes in the knowledge graph. Whenever the algorithm expands from a node to one or more of its neighbors, it creates one or more new paths extending from the starting node; these different paths are called search branches. Each search branch represents a potential solution, and the algorithm continuously evaluates its path dynamics score based on the path's structural cost and its relevance to user preferences.

[0036] However, in complex knowledge graphs, not all search branches are valuable. Unrestricted exploration leads to inefficient algorithms and poor results. Therefore, this embodiment assesses the state of search branches in real-time during the search process. An inefficient state refers to a situation where continuing to expand along the explicit connections of the current graph makes it difficult or impossible to find a better solution. For example, suppose a user starts from a hotel looking for "local specialties," and the algorithm begins exploring surrounding nodes. However, the hotel is located in a commercial area with numerous chain fast-food restaurants nearby. With each step the algorithm takes, the newly discovered nodes do not significantly improve their dynamic evaluation scores on the "specialty" preference dimension.

[0037] Based on the above introduction, the state is determined to be inefficient, which means that simply relying on the graph can no longer meet the user's intentions, and it is necessary to introduce external knowledge to carry out leapfrog exploration.

[0038] When a path expands to an information hub node, or when the dynamic evaluation score of a path stagnates after continuous expansion, the search branch is determined to be inefficient. For example, if the algorithm starts searching from node A and expands to the highly connected information hub node C (business district), the algorithm determines that the current search branch has entered an inefficient state. This is because the number of paths starting from such nodes grows exponentially, and the vast majority of branches are irrelevant to the user's specific intent; continuing to blindly expand is extremely costly. At this point, the algorithm triggers a semantic bridging operation.

[0039] The calculation method for dynamic evaluation scores is basically the same as that for comprehensive scores. The only difference is that comprehensive scores are calculated using adjusted preference weights, while dynamic evaluation scores are calculated using initial preference weights. The comprehensive score can be calculated based on the following formula: Comprehensive Score = λ Path structure score + (1-λ) The path preference score is calculated by summing the weights of all edges in the path and matching the attributes of the path's endpoint entities with their preference weights. For example, if a user's initial preference weight for "no queue" is 0.9, and the attribute of the path's endpoint entity D (a snack shop) is "no waiting," then the path receives a 0.9 bonus in preference score. Conversely, if another path endpoint, F (a restaurant), requires "a one-hour wait," a base penalty (e.g., -0.9) will be incurred. If this penalty is dynamically reduced due to textual evidence (e.g., a 50% reduction in the penalty coefficient, becoming -0.45), the penalty used to calculate the path preference score will be adjusted, thus affecting the final score. The final path preference score is formed by adding the scores of all relevant preferences to the penalty items. λ is a preset balancing coefficient, ranging from [0, 1], used to adjust the importance of structural efficiency and user preference in the final score. For example, when the user's intention is clear and efficiency is prioritized, the value of λ can be increased to emphasize the path structure score. When user intent is ambiguous and the focus is on exploration and experience, the λ value can be lowered to emphasize path preference score.

[0040] During the semantic bridging operation, the algorithm aggregates the contextual information of the current path to form descriptive text, such as "Starting from point A, go to the C business district to find local snacks without queues," and inputs this text into a text embedding model to generate a context vector. Using this context vector, the algorithm performs an approximate nearest neighbor search in the document vector library. For example, if a high-scoring text fragment is found: "Locals recommend going from point A to street B, where snack shop D has authentic flavors and fewer tourists, so there's no need to wait," and this text fragment has a semantic matching score of 0.95, the algorithm extracts a new text discovery node, "Street B," from this text fragment. A temporary semantic edge is then constructed by connecting the C business district node and the Street B node.

[0041] During the path evaluation process, the preference weights applied to the current path are temporarily adjusted based on the text fragment content of the final node of the current complete path. The comprehensive score of each path is calculated based on the structural cost of the path and the adjusted preference weights, and the intent path including the comprehensive score is output.

[0042] For the path to the final node, the algorithm performs a dynamic preference correction operation. The final node includes the final node found by the graph reasoning algorithm for all paths. Suppose the retrieved text fragment for the final node is "The taste is amazing, worth queuing for an hour." The algorithm performs sentiment analysis and fact extraction on this text fragment, identifying the positive description "amazing taste" corresponding to the preferred entity "features," and the negative description "queuing for an hour" which contradicts the preferred entity "no queue." At this point, the algorithm, according to a preset correction rule, reduces the preference weight of "no queue" by Y%.

[0043] The adaptive graph reasoning algorithm calculates a comprehensive score for each path from the starting node to the ending node. This comprehensive score combines the path's structural cost and preference weights, the calculation method of which has been previously introduced. For example, the algorithm might find two paths: Path 1 is (location A) -> [:neighborhood] -> (commercial area C) -> [:semantic bridge] -> (street B) -> [:owned merchants] -> (snack shop D), with a comprehensive score of 0.92. Path 2 is (location A) -> [:neighborhood] -> (snack street E) -> [:owned merchants] -> (restaurant F), with a comprehensive score of 0.75. The score of 0.75 is the result after the base penalty due to queuing is reduced by the dynamic preference correction operation. These paths, ranked according to their comprehensive scores, are output as candidate intent paths.

[0044] The above steps, through semantic bridging operations, discovered Path 1, which was inaccessible by traditional methods, thus solving the problem of an overly narrow search scope. Meanwhile, Path 2 was not directly excluded simply because restaurant F required queuing; instead, by analyzing textual sentiment, the complex intention of users willing to sacrifice their preference for not queuing for a top-notch, unique experience was understood, thus resolving the problem of overly rigid preference processing.

[0045] In this embodiment, if the search branch is determined to be inefficient, a temporary semantic edge is constructed, including the following steps: If a branch expands for N consecutive steps and its dynamic evaluation score improves below a preset threshold, or if the path expands to an information hub node, it is determined to be inefficient. The context information of the current path is aggregated to generate descriptive text. The descriptive text is converted into a context vector through a text embedding model. The context vector is used to perform an approximate nearest neighbor search in the service document and return a text fragment. The text discovery node is extracted from the text fragment.

[0046] In a graph reasoning algorithm, starting from node A, when the path expands to the information hub node C (business district), the algorithm determines that the current search branch has entered an inefficient state. Alternatively, during path expansion, the algorithm records dynamic evaluation scores in real time. If, after the path has expanded for a preset three steps, the increase in its dynamic evaluation score is lower than a preset score increase threshold of 0.05, the algorithm also determines that this search branch has entered an inefficient state. Once determined to be inefficient, the algorithm uses a preset text generation template to aggregate the node information already included in the current path with the user's preference entities to form descriptive text, such as the text "Starting from point A, find a non-queueing specialty snack near business district C". The algorithm inputs the descriptive text generated in the previous steps into a pre-trained text embedding model, such as the BERT model, to convert the descriptive text into a 768-dimensional context vector.

[0047] Specifically, the score improvement threshold can be determined by conducting offline experiments on historical search data to select a value that balances search breadth and convergence speed.

[0048] Using context vectors, an approximate nearest neighbor search is performed in a pre-built document vector library. The approximate nearest neighbor search returns the text fragment with the highest cosine similarity to the context vector in the vector space. For example, the returned text fragment might be a local's recommendation to go from location A to street B, where snack shop D offers authentic food and has fewer tourists, so there's no waiting. Simultaneously, the cosine similarity value returned by the approximate nearest neighbor search is used as a semantic matching score, for example, a semantic matching score of 0.95. Finally, the algorithm applies named entity recognition technology to extract the location entity "street B" from the returned text fragments and identifies "street B" as the text discovery node.

[0049] Define the last node of the current search branch as the search node, obtain the physical travel cost between the current search node and the text discovery node, calculate the weight of the temporary semantic edge by combining the semantic matching score and the physical travel cost, and establish a connection between the current search node and the text discovery node to construct the temporary semantic edge.

[0050] The algorithm calls an external map service application interface to query the physical travel cost between the current search node C (commercial area) and the text discovery node B (street), for example, obtaining an estimated travel time of 15 minutes. The algorithm calculates the weight of temporary semantic edges according to a preset weight calculation formula, for example, the formula is weight = (α...). Semantic matching score)-(β) The physical travel cost is calculated based on the estimated travel time using an exponential function, mapping it to a value between 0 and 1. The idea behind the exponential function is that the longer the estimated travel time, the closer the calculated physical travel cost is to 1, where α and β are preset adjustment coefficients. Substituting the semantic matching score of 0.95 and the physical travel cost of 15 minutes into the formula, the weight of the temporary semantic edge is calculated. Finally, a connection is established between the current search node C (commercial area) and the text discovery node B (street), and the calculated weight is assigned to this connection, thus constructing the temporary semantic edge.

[0051] In this embodiment, temporarily adjusting the preference weights applied to the current path branch includes the following steps: Retrieve text fragments related to the final node, perform sentiment analysis on the text fragments, identify descriptions related to user preference entities, and when specific conditions in the text descriptions are met, adjust the preference weights applied to the current path according to preset correction rules.

[0052] Specifically, when the graph reasoning algorithm evaluates the path to the final node F (restaurant entity), the algorithm uses the final node F (restaurant entity) as the index key to retrieve all related text fragments in the document corpus. For example, it retrieves a user review text fragment that reads "The taste is amazing and it's worth queuing for an hour."

[0053] The algorithm first identifies descriptions in the text fragments that are relevant to user preferences. For example, the description "amazing taste" is identified as related to the user's preferred entity "uniqueness," and the description "waiting in line for an hour" is identified as related to the user's preferred entity "not queuing." Subsequently, the algorithm applies a sentiment analysis model to qualitatively and quantitatively characterize the identified descriptions. For example, the model determines that the description "amazing taste" is a positive sentiment and outputs a sentiment score of 0.95. The description "waiting in line for an hour" is determined to be a negative fact, contradicting the preference for not queuing. The sentiment analysis model is also a pre-trained language model or classification model, which is existing technology and will not be described further here.

[0054] Based on preset correction rules, the preference weights applied to the current path are adjusted. For example, the correction rule is defined as follows: when the positive sentiment score related to the unique preference exceeds the threshold of 0.9, the preference weight is reduced by 50%. In this embodiment, since the sentiment score of 0.95 is greater than the threshold of 0.9, the algorithm triggers this rule. This adjustment improves the overall score of this path, which might otherwise be downgraded due to queuing, thus reflecting the real decision-making scenario where users might accept queuing for the ultimate unique experience.

[0055] After generating intent paths using graph reasoning algorithms and semantic bridging, the system obtains multiple logical chains representing users' deep-seated needs. However, these intent paths are mainly composed of entity nodes and relationships in the knowledge graph. While the structure is clear, it lacks descriptive information. For example, a knowledge graph can provide a restaurant's address and cuisine, but it cannot tell users how its signature dishes taste, the service attitude, or the specific consumption experience. Therefore, this embodiment also proposes the following technical solution to obtain detailed information that may be missed during the path exploration phase. First, text retrieval is performed, which includes the following steps.

[0056] Retrieving text fragments from a service document based on an intent path includes the following steps: Extract path node entities and path relationship constraints from the intent path, combine the path node entities and path relationship constraints into at least one keyword group, and retrieve text fragments from the service document based on the keyword group.

[0057] Specifically, the system identifies and extracts all entities that serve as nodes in the path, and extracts the connections between these entities. Based on the nature of the path nodes, it matches query keywords of different dimensions. For example, for entities representing final service points (such as restaurants and attractions), it prioritizes combining keywords directly related to the consumer experience, such as "reviews," "features," "prices," and "queue status." For entities representing regions or collections (such as commercial districts and parks), it tends to combine keywords related to planning and exploration, such as "guides," "must-visit spots," and "travel routes." For combinations of entities involving two or more geographical locations (such as the starting point and the destination), it matches keywords related to the itinerary, such as "transportation," "route," "how to get there," and "how long it takes."

[0058] All generated keyword groups are aggregated to construct a keyword set. For example, for the path (Location A) -> [:neighborhood] -> (Snack Street B) -> [:ownership] -> (Snack Main Store D), the path node entity list is extracted to include [Location A, Snack Street B, Snack Main Store D], and the path relationship constraint list includes [:neighborhood, :ownership]. Next, strategy rules are applied for combination. For example, for "Snack Main Store D", keyword group one is selected: taste and reviews. For "Snack Street B", keyword group two is selected: travel guide. For the starting point "Location A" and the ending point "Snack Main Store D", keyword group three is selected: transportation. Finally, the generated keyword group one, keyword group two, keyword group three, etc., are combined into a targeted instruction set, and this targeted instruction set is used as the retrieval input of the retrieval module to drive it to retrieve relevant text fragments in the service document library. The service document is a constantly updated database, such as continuously crawling user comments from various platforms. Therefore, through this step, more timely and comprehensive text fragments can be obtained from the service document.

[0059] While the aforementioned intent path generation and instruction retrieval methods solve the problems of discovering the optimal path, obtaining relevant descriptive information, and ensuring its accuracy, they also generate diverse and fragmented information items (e.g., structured facts from knowledge graphs, various types of internet text crawled from service documents). Although each of these information items possesses a certain degree of credibility, they lack a unified narrative logic. Directly piecing together these fragmented pieces of information as context will result in the input content to the large language model lacking a clear narrative structure and logical coherence, affecting the quality and readability of the final generated answer. To address this issue, this invention proposes the following steps, the first of which involves confidence calculation.

[0060] In this embodiment, confidence calculation is performed on the structural knowledge and text fragments in the intent path, including the following steps: Assign a first initial score to structural knowledge and a second initial score to text fragments. Connect to an external real-time interface to obtain dynamic data. Compare the structural knowledge and text fragments with the dynamic data respectively. Based on the comparison results, correct the first and second initial scores, and use the corrected scores as the confidence levels of structural knowledge and text fragments respectively.

[0061] First, a first initial score is assigned to the structural knowledge, and a second initial score is assigned to the text fragment. Since the structural knowledge originates from a knowledge graph, its data is more reliable, while the text fragment comes from service documents, which have relatively lower reliability. Therefore, the second initial score is set lower than the first initial score; for example, the first initial score is 1, and the second initial score is 0.9. Next, entities are extracted directly from the structural knowledge. For the text fragment, named entity recognition technology is used to identify the entity surrounding the text fragment, such as the snack shop in the previous example. Subsequently, for this entity, an information extraction model is used to extract content describing its specific attributes from the text. The information extraction model can be a sequence labeling model or a relation extraction model based on a pre-trained language model; these models are existing technologies in this field and will not be described further here. For example, from "A famous snack shop is open all year round, and there aren't many people there now," two entities can be extracted: (A famous snack shop, operating status, open all year round) and (A famous snack shop, queuing situation, not many people).

[0062] After extracting entities, their corresponding structural attributes, such as fixed business hours or addresses, are retrieved from an external real-time interface using the entities as indexes. This external real-time interface is a relatively authoritative third-party database, such as announcements from an official website. After acquiring dynamic data, a dynamic conflict score is calculated. Specifically, for categorical attributes, if the text "Sichuan cuisine" completely contradicts the map "Japanese cuisine," a dynamic conflict score of 1.0 is assigned. For numerical attributes, the deviation is quantified using the normalized relative error formula min(1.0, |entity value - dynamic data value| / dynamic data value). For example, a per capita consumption of 105 yuan versus a dynamic data value of 100 yuan results in a conflict score of only 0.05. For queuing, queuing conditions are divided into multiple levels, from "no waiting" (level 0) to "severe congestion" (level 3). If the text description of "no queuing" contradicts the dynamic data's "moderate waiting" (level 2), the dynamic conflict score is calculated as the level difference divided by the maximum level difference, i.e., |0-2| / 3, approximately equal to 0.67. For critical information such as business status, if a functional contradiction arises, such as "operating normally" versus "permanently closed," a maximum dynamic conflict score of 1.0 will be assigned. The calculation methods for other dimensions can be set by those skilled in the art based on actual circumstances, and will not be described here.

[0063] Finally, the average of all dynamic conflict scores is used to obtain the comprehensive conflict score. Based on the following calculation formula, the confidence of structural knowledge or text fragment is calculated. For structural knowledge, the calculation formula is: Confidence = First Initial Score - Comprehensive Conflict Score of Structural Knowledge. For text fragment, the calculation formula is, for example: Confidence = Second Initial Score - Comprehensive Conflict Score of Text Fragment.

[0064] In this embodiment, the intent path is used as the narrative thread, and the evaluated and filtered information is reconstructed into a logically coherent enhanced context, including the following steps: The confidence score is used as the initial score. Based on the initial score, the structural knowledge and text fragments are processed to construct a candidate information set. The information items in the candidate information set are weighted and sorted. The weighted and sorted information items are reconstructed into logically coherent text to form a reconstructed enhanced context.

[0065] In this embodiment, constructing the candidate information set includes the following steps: Based on the initial score distribution of all structural knowledge and text fragments, a screening threshold is calculated, and structural knowledge and text fragments with an initial score not lower than the screening threshold are added to the candidate information set.

[0066] First, define the current batch and calculate the initial score. For example, after responding to a user's query "find a local specialty snack without a queue," 10 structural knowledge points and text fragments are obtained through targeted retrieval, constituting the current batch. After calculating the initial score (confidence level) for each structural knowledge point or text fragment, an initial score list is formed, for example: [0.95, 0.92, 0.88, 0.85, 0.75, 0.72, 0.65, 0.60, 0.55, 0.48]. Then, calculate the mean and standard deviation of this score list. In this example, the mean is 0.735, and the standard deviation is approximately 0.155. The filtering threshold is calculated using the formula "Filtering threshold = mean + k × standard deviation." The adjustment coefficient can be manually set according to the required accuracy of the response. Assuming the preset adjustment coefficient k is 0.5, substituting the values, we get: Filtering threshold = 0.735 + 0.5 × 0.155 = 0.8125.

[0067] Finally, each piece of structural knowledge and text fragment in the current batch is iterated, and its initial score is compared with the filtering threshold of 0.8125. Four pieces of structural knowledge or text fragments with initial scores of 0.95, 0.92, 0.88, and 0.85 are deemed highly reliable because their scores are not lower than the filtering threshold; therefore, the complete content of these four pieces is included as candidate information items. The remaining six text fragments with initial scores below 0.8125 are then transferred to the subsequent attribute-level information extraction process for processing.

[0068] For text fragments with initial scores below the screening threshold, an attribute extraction model is used to identify and extract attribute clauses describing predefined attributes from the text fragments. The information value score of the attribute clauses is evaluated, and attribute clauses with information value scores not lower than a preset local threshold are retained and added to the candidate information set.

[0069] For text fragments with initial scores below the filtering threshold, the system performs attribute extraction. Taking a text fragment with an initial score of 0.65 from the aforementioned filtering as an example, its content is: "Last week I went to D Snacks' main branch. The queue was incredibly long, but their signature grilled fish was absolutely delicious, and the price was very reasonable, about 80 yuan per person. The only downside was that the waiters were a bit overwhelmed, and their attitude was so-so. Oh, by the way, it seems like they've just been renovated; the environment is nice." First, the text fragment is processed using an attribute extraction model. The attribute extraction model is a pre-trained sequence labeling model used to identify and extract attribute clauses related to predefined attributes (such as [price], [environment], [service], [taste], [queue status]). For the example text fragment above, the model identifies and extracts the following attribute clauses: "The queue is extremely long" for [queue status], "The signature grilled fish is absolutely delicious" for [taste], "The average price is about 80 yuan per person" for [price], "The service attitude is so-so" for [service], and "The environment is nice" for [environment].

[0070] Next, the information value score of each extracted attribute clause is evaluated. This score quantifies the specificity and reference value of the information contained in the clause. Scoring can be done by setting scoring rules or using a pre-trained language model. For example, clauses containing specific numerical values ​​(such as "about 80 yuan per person") are given a high score (e.g., 0.9) because they provide precise quantitative information; clauses containing strong emotions or explicit descriptions (such as "the signature grilled fish tastes amazing") are given a slightly higher score (e.g., 0.85) because they express a clear viewpoint; while vague clauses (such as "the environment is nice") are given a low score (e.g., 0.75) because of their low information density. Subsequently, an information value threshold (e.g., 0.8) is set, and only attribute clauses with scores not lower than this threshold are considered high-value information items and added to the final candidate information set, while clauses with lower scores are discarded. Through this refinement process, this invention, while ensuring the accuracy of the information source facts, further extracts clear and valuable key content, thereby avoiding providing vague or useless information to a large language model.

[0071] In this embodiment, reconstructing the text into logically coherent text includes the following steps: Each information item in the candidate information set is associated with the corresponding node or edge in the intent path based on the entity or relationship it describes.

[0072] Using the highest-scoring intent path as the narrative thread, the system traverses its node sequence. During the traversal, for each node in the path, all related information items are integrated, and the content is organized into descriptive statements based on a preset text template.

[0073] The descriptive statements generated along the path are concatenated and smoothed using conjunctions to ultimately form an enhanced context.

[0074] After obtaining the candidate information set through the aforementioned steps, this step aims to deeply integrate this structured knowledge with unstructured text fragments to generate a logically clear and human-readable enhanced context, which serves as the final input to the large language model. Unlike traditional methods that simply splice information together, this invention utilizes the previously generated intent path as a skeleton, ensuring that the logical thread of the generated text remains consistent with the user's deep intent, and avoiding redundant computation caused by reconstructing the graph to organize information.

[0075] First, the system associates each information item in the candidate information set with the corresponding node or edge in the intent path. The system iterates through each item in the candidate information set, using named entity recognition technology or its own metadata to determine the core entity or relationship described by the information item. Then, the system maps the information item to the corresponding node in the intent path. For example, suppose the intent path with the highest score is (Area A) -> [:neighborhood] -> (C business district) - [:semantic bridge] -> (B street) -> [:owning merchants] -> (D snack shop), and the candidate information set contains the following five information items: Information item 1 (structural knowledge: D snack shop, category, local specialty snack), Information item 2 (text fragment: D snack shop has authentic taste and few tourists, so there is no need to wait), Information item 3 (attribute clause: about 80 yuan per person), Information item 4 (attribute clause: the signature grilled fish tastes amazing), Information item 5 (structural knowledge: B snack street, contains, D snack shop). System analysis revealed that information items 1, 2, 3, and 4 all describe the entity "D Snack Shop," and therefore, they are all associated with the endpoint node (D Snack Shop) of the intent path. Information item 5 explicitly indicates the inclusion relationship between "B Snack Street" and "D Snack Shop," and thus it is associated with the contextual logic connecting these two nodes. Through this process, all scattered information is organized systematically within the unified logical framework of the intent path.

[0076] Next, the system uses the highest-scoring intent path as the narrative thread and organizes the text according to its node sequence, employing a combination of template-based filling and dynamic generation. The system prioritizes the core final node of the path, i.e., the service entity that the user cares about most. In this example, it is the "D Snack Shop" node. The system loads one or more preset text templates related to the "recommended service entity" scenario. These templates contain multiple placeholders, corresponding to different attribute dimensions of the entity, such as [Advantages], [Category], [Taste], [Price], [Location], etc.

[0077] Then, the system iterates through all information items associated with the final node (D snack shop) and fills their content into placeholders in the corresponding templates. The filling process is not a simple string replacement, but rather an intelligent selection based on the type and confidence level of the information item. For example, for the [Advantages] placeholder, the system prioritizes text fragments highly relevant to user preferences (such as "no queues"), such as "few tourists, no need to wait" in information item 2. For the [Category] placeholder, it fills in structured data from the knowledge graph, such as "local specialty snacks" in information item 1. For specific attributes such as [Taste] and [Price], it fills in high-confidence attribute clauses extracted from the text, such as "the signature grilled fish is absolutely delicious" in information item 4 and "about 80 yuan per person" in information item 3. For [Location] information, it traces the preceding nodes of the intent path and, combined with the content of information item 5, determines that it is located in "B Snack Street".

[0078] Finally, the descriptive sentences generated along the path are concatenated and smoothed using conjunctions or transition sentences to generate the final enhanced context. After all placeholders are filled, the system combines these fragmented contents according to the template's preset sentence structure. For example, the system might generate sentence fragments such as: "D Snack Shop is a good choice," "One of its significant advantages is that there are fewer tourists and no waiting," "This shop specializes in local snacks," "In terms of taste, its signature grilled fish is absolutely delicious," "In terms of price, the average price per person is about 80 yuan," and "You can find this shop at B Snack Street." The system further uses conjunctions (such as "and," "in addition") and transition sentences to merge these independent sentences into a natural and fluent text. For example, the final enhanced context might be: "Regarding the snacks you're looking for, D Snack Shop is a good choice. One significant advantage is that it's less crowded and you don't have to wait in line. This shop specializes in local snacks, and its signature grilled fish is absolutely delicious. In terms of price, the average cost per person is around 80 yuan. You can find this shop on B Snack Street." This logically coherent text is the final enhanced context.

[0079] It should be noted that the specific implementation details described in the embodiments of the present invention involve multiple configurable parameters and thresholds, which can be adjusted and optimized by those skilled in the art according to the data characteristics and performance requirements of the actual application scenario. Specifically: In the calculation of temporary semantic edge weights, the coefficients α and β are used to balance the importance of semantic relevance and physical accessibility, and their sum can be set to 1. When the user's intention is more inclined to explore novel locations, the value of α can be increased; when the user pays more attention to travel efficiency, the value of β can be increased. Among them, the normalization of physical travel cost can adopt an S-shaped function or a piecewise function to map the original travel time (minutes) to the interval [0,1]. The core idea is that the cost increases slowly within a certain range of travel time (such as within 30 minutes), and the cost increases sharply after exceeding this range, so as to effectively punish physically unreasonable "jumps".

[0080] In the calculation of the overall score, the balancing coefficient λ (ranging from [0,1]) is used to weigh the structural cost of the path against the user's preference score. The system can dynamically adjust the value of λ based on the explicit intent of the user's query. For example, for queries containing keywords such as "fastest" or "shortest route", the value of λ can be increased to emphasize the path structure score; for queries containing keywords such as "unique" or "good reviews", the value of λ can be decreased to emphasize the path preference score.

[0081] In calculating the screening threshold, a higher k value results in a higher average credibility of the screened information, but may lead to the loss of some valuable details; a lower k value results in richer information, but may introduce noise. An optimal k value can be determined by conducting offline experiments on a validation set to evaluate the impact of different k values ​​on the accuracy and information content of the final generated answer. For example, the range of k is [0, 1.5].

[0082] In inefficient state determination, the number of consecutive expansion steps N is usually set to a small integer. This value is set to balance search depth and efficiency, giving the algorithm enough opportunities to discover potential paths while stopping in time to avoid wasting too much computational resources on invalid branches that do not significantly improve the score.

[0083] The setting and optimization of these parameters are all conventional technical means that can be implemented by those skilled in the art after understanding the core idea of ​​the present invention, and their specific values ​​do not constitute a substantial limitation of the present invention.

[0084] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0085] The above embodiments merely illustrate several implementation methods of the present invention, and their descriptions are relatively specific and detailed, but they should not be construed as limiting the scope of the present invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the protection scope of the present invention. Therefore, the protection scope of this patent should be determined by the appended claims.

[0086] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for dual-channel knowledge retrieval and answer generation based on RAG and knowledge graph, characterized in that, include: Build a hybrid knowledge base, which includes service documents and knowledge graphs; Integrate user queries with real-time context to form context-aware queries, and parse context-aware queries to initialize graph reasoning tasks; Perform reasoning tasks on the knowledge graph, and introduce service document knowledge during the reasoning task execution process through semantic bridging to generate intent paths that integrate structural knowledge and textual knowledge; Based on the intent path, text fragments are retrieved from the service document. Confidence is calculated on the structural knowledge and text fragments in the intent path. Using the intent path as the narrative thread, the evaluated and filtered information is reconstructed into a logically coherent enhanced context. The input context is enhanced to the large language model to generate the final answer, and the output is adapted to a multimodal format.

2. The method of claim 1, wherein, Generating an intent path that integrates structural knowledge and textual knowledge includes the following steps: Identify location entities in context-aware queries, and use the identified location entities as starting nodes to execute graph reasoning algorithms in the knowledge graph. During the search process of the graph reasoning algorithm, if a search branch is determined to be inefficient, a temporary semantic edge is constructed. During the path evaluation process, the preference weights applied to the current path are temporarily adjusted based on the text fragment content of the final node of the current complete path. The comprehensive score of each path is calculated based on the structural cost of the path and the adjusted preference weights, and the intent path including the comprehensive score is output.

3. The method of claim 2, wherein, If the search branch is determined to be inefficient, a temporary semantic edge is constructed, including the following steps: If a branch expands in N consecutive steps and its dynamic evaluation score increases below a preset threshold, or if the path expands to an information hub node, it is determined to be inefficient. The context information of the current path is aggregated to generate descriptive text. The descriptive text is converted into a context vector through a text embedding model. The context vector is used to perform an approximate nearest neighbor search in the service document and return a text fragment. The text discovery node is extracted from the text fragment. Define the last node of the current search branch as the search node, obtain the physical travel cost between the current search node and the text discovery node, calculate the weight of the temporary semantic edge by combining the semantic matching score and the physical travel cost, and establish a connection between the current search node and the text discovery node to construct the temporary semantic edge.

4. The method according to claim 2, characterized in that, Temporarily adjust the preference weights applied to the current path branch, including the following steps: Retrieve text fragments related to the final node, perform sentiment analysis on the text fragments, identify descriptions related to user preference entities, and when specific conditions in the text descriptions are met, adjust the preference weights applied to the current path according to preset correction rules.

5. The method according to claim 1, characterized in that, Retrieving text fragments from a service document based on an intent path includes the following steps: Extract path node entities and path relationship constraints from the intent path, combine the path node entities and path relationship constraints into at least one keyword group, and retrieve text fragments from the service document based on the keyword group.

6. The method according to claim 1, characterized in that, Calculating confidence scores for structural knowledge and text fragments within the intent path includes the following steps: Assign a first initial score to structural knowledge and a second initial score to text fragments. Connect to an external real-time interface to obtain dynamic data. Compare the structural knowledge and text fragments with the dynamic data respectively. Based on the comparison results, correct the first and second initial scores, and use the corrected scores as the confidence levels of structural knowledge and text fragments respectively.

7. The method according to claim 1, characterized in that, Using the intent path as the narrative thread, the evaluated and filtered information is reconstructed into a logically coherent enhanced context, including the following steps: The confidence score is used as the initial score. Based on the initial score, the structural knowledge and text fragments are processed to construct a candidate information set. The information items in the candidate information set are weighted and sorted. The weighted and sorted information items are reconstructed into logically coherent text to form a reconstructed enhanced context.

8. The method according to claim 7, characterized in that, Constructing a candidate information set includes the following steps: Based on the initial scores of all structural knowledge and text fragments, a screening threshold is calculated, and structural knowledge and text fragments with initial scores not lower than the screening threshold are added to the candidate information set. For text fragments with initial scores below the screening threshold, an attribute extraction model is used to identify and extract attribute clauses describing predefined attributes from the text fragments. The information value score of the attribute clauses is evaluated, and attribute clauses with information value scores not lower than a preset local threshold are retained and added to the candidate information set.

9. The method according to claim 8, characterized in that, Reconstructing weighted and sorted information items into logically coherent text includes the following steps: Each information item in the candidate information set is associated with the corresponding node or edge in the intent path based on the entity or relationship it describes. The highest-scoring intent path is used as the main narrative thread. It is traversed according to its node sequence. During the traversal, for each node in the path, all related information items are integrated, and the content is organized into descriptive statements according to the preset text template. The descriptive statements generated along the path are concatenated and smoothed using conjunctions to ultimately form an enhanced context.