A venue intelligent retrieval method based on vector retrieval and knowledge graph
Patent Information
- Application Number
- CN202611134344.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-29
- Publication Date
- 2026-10-23
AI Technical Summary
[0004]为解决以上问题,本发明通过整合领域自适应纠错、向量检索与知识图谱混合检索、本地化部署、结构化提示约束及后处理核查关键技术手段,系统性地解决了专业场馆智能问答中的输入容错、信息碎片化、数据安全、模型幻觉及答案纯净度核心问题,实现了从查询输入到答案生成全流程的准确性、安全性、可靠性与用户体验的全面提升
1、针对用户查询中常见的专业术语拼写错误、同音字或字形混淆等问题,通过引入领域自适应的纠错机制,能够对输入进行智能化的清洗与规范化处理,有效提升了系统对非规范输入的容错能力,保障了后续处理流程的输入质量,从而显著增强了系统的易用性和可靠性;
Smart Images

Figure CN122964222A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence and natural language processing, and in particular to a method for intelligent venue retrieval based on vector retrieval and knowledge graph. Background Technology
[0002] With the widespread application of large language model technology, its introduction into the field of intelligent venue navigation and question answering has become a new trend in the industry. However, when directly using general-purpose large language models to process professional venue scenarios, their limitations are becoming increasingly apparent, and existing technical solutions face multiple challenges. The inherent "illusion" problem of large language models is further amplified in the highly professional environment of venues. The content generated by the model often appears reasonable on the surface but lacks factual support, especially when dealing with specific queries involving details of cultural relics, historical dates, author biographies, etc., resulting in a high rate of factual errors and seriously affecting the accuracy and authority of the navigation service. At the same time, single retrieval enhancement generation technology also has obvious shortcomings. Although traditional vector retrieval can recall semantically related text fragments, it is difficult to effectively connect discrete information to form a complete and accurate answer when dealing with scenarios that require complex logical reasoning or multi-hop relational queries, resulting in fragmented information presentation and affecting the reliability and completeness of the answer.
[0003] Furthermore, data privacy and security issues are particularly prominent. The museum's collections, archives, internal research materials, and unpublished exhibition information are largely sensitive data. Uploading user queries and related data to a cloud-based big data model for processing poses a significant risk of data breaches, failing to meet the museum's stringent information security management requirements. On the other hand, the existing system is not robust enough to handle user queries. Visitor input often contains spelling errors in technical terms, homophones, and other non-standard expressions. The system lacks effective error tolerance and correction mechanisms, causing subsequent searches to deviate from the user's true intent, severely impacting the search experience and service effectiveness. Summary of the Invention
[0004] To address the above issues, this invention systematically solves the core problems of input error tolerance, information fragmentation, data security, model illusion, and answer purity in intelligent question answering for professional venues by integrating key technologies such as domain adaptive error correction, vector retrieval and knowledge graph hybrid retrieval, localized deployment, structured prompt constraints, and post-processing verification. This achieves a comprehensive improvement in accuracy, security, reliability, and user experience throughout the entire process from query input to answer generation.
[0005] According to an embodiment of the present invention, a method for intelligent venue retrieval based on vector retrieval and knowledge graph is provided.
[0006] In a first aspect of the present invention, a method for intelligent venue retrieval based on vector retrieval and knowledge graph is provided. The method includes: Step S01: Receive the user's original query, perform domain-adaptive error correction on the original query using a pre-trained error type classification model and a sequence error correction generation model, and output a standardized query; Step S02: Based on the canonical query, vector retrieval and graph retrieval are executed in parallel. Vector retrieval is based on the vector database to retrieve text fragments semantically related to the canonical query, and graph retrieval is based on the domain knowledge graph to retrieve entities and relational paths related to the canonical query. Step S03: Weighted fusion of the text fragments returned by vector retrieval and the entities and relational paths returned by graph retrieval to form an enhanced context; Step S04: Receive the canonical query, text fragments, and entity and relation paths, integrate them to construct enhanced hints, input them into the large language model, perform post-processing to generate the final answer, and return it to the user.
[0007] Furthermore, the error type classification model described in step S01 uses a pre-trained TextCNN model to predict the error type of user input, defining common input errors in the museum field as: character shape, character pronunciation, disorder, repetition, and missing characters.
[0008] Furthermore, the specific steps of the error correction generation model in step S01 to perform domain-adaptive error correction on the original query are as follows: After obtaining the error type, the system converts it into a natural language prompt through a mapping function, and concatenates it with the original text to construct a template input with error correction instructions; The sequence error correction generation model adopts a pre-trained language model based on an encoder-decoder architecture. The prompt template is input into the encoder to obtain the hidden state, and the decoder generates a canonical query autoregressively based on the hidden state.
[0009] Furthermore, the vector retrieval process described in step S02 is based on a retrieval enhancement generation architecture, including: segmenting unstructured domain text into multiple text blocks, encoding each text block into a vector representation using a word embedding model, and storing it in a vector database; encoding the canonical query into a query vector, calculating its similarity to all text block vectors in the vector database, sorting them according to the similarity score, and returning the top results. The most relevant set of text blocks.
[0010] Furthermore, the execution process of graph retrieval described in step S02 includes: searching for entity nodes in the domain knowledge graph that directly match the standard query; starting from the matched entity node, performing one-hop or multi-hop traversal along the predefined relation edges in the knowledge graph to obtain a subgraph structure containing the central entity and its associated attributes and related entities, which serves as the retrieved relation path.
[0011] Furthermore, the specific steps of step S03 are as follows: Convert the entity attributes and relationship paths contained in the graph retrieval results into coherent natural language description fragments; Based on the intent type of the query, dynamically assign fusion weights to the vector retrieval results and the graph retrieval results. and ,in ; Dynamic allocation satisfies the following condition: when the query intent is multi-hop relational reasoning, it enables... > When the query intent is a detailed description or an open-ended statement, make > ; The two weighted search results are then concatenated in sequence to form a unified enhanced context.
[0012] Furthermore, the specific steps for integrating and constructing enhanced prompts as described in step S04 are as follows: designing a structured prompt template, which sequentially includes: system role definition, user specification query after error correction, enhanced context, and instructions requiring the large language model to strictly generate faithful and fluent answers based on the enhanced context.
[0013] In a second aspect of the invention, an apparatus for intelligent venue retrieval based on vector retrieval and knowledge graph is provided. The apparatus includes: Query correction module: It receives the user's original query, performs domain-adaptive error correction on the original query through a pre-trained error type classification model and sequence error correction generation model, and outputs a standardized query. Parallel retrieval module: used to perform vector retrieval and graph retrieval in parallel based on canonical queries. Vector retrieval is based on vector database to retrieve text fragments semantically related to the canonical query, and graph retrieval is based on domain knowledge graph to retrieve entities and relational paths related to the canonical query. Weighted fusion module: Used to weight and fuse the text fragments returned by vector retrieval with the entities and relational paths returned by graph retrieval to form an enhanced context; Answer generation module: It receives standardized queries, text fragments, and entity and relationship paths, integrates them to build enhanced suggestions, inputs them into a large language model, performs post-processing to generate the final answer and returns it to the user.
[0014] In a third aspect of the invention, an electronic device is provided. The electronic device includes a memory and a processor, the memory storing a computer program, the processor executing the program to implement the method according to a first aspect of the invention.
[0015] In a fourth aspect of the invention, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method according to a first aspect of the invention.
[0016] This invention systematically solves the core problems of input error tolerance, information fragmentation, data security, model illusion, and answer purity in intelligent question answering for professional venues by integrating key technologies such as domain adaptive error correction, vector retrieval and knowledge graph hybrid retrieval, localized deployment, structured prompt constraints, and post-processing verification. It achieves a comprehensive improvement in accuracy, security, reliability, and user experience throughout the entire process from query input to answer generation.
[0017] It should be understood that the description in the Summary of the Invention is not intended to limit the key or essential features of the embodiments of the present invention, nor is it intended to restrict the scope of the invention. Other features of the invention will become readily apparent from the following description.
[0018] The beneficial effects of this invention are: 1. To address common issues in user queries such as spelling errors of professional terms, homophones, or character confusion, a domain-adaptive error correction mechanism is introduced. This mechanism enables intelligent cleaning and standardization of input, effectively improving the system's tolerance for non-standard input and ensuring the input quality of subsequent processing flows. Consequently, the system's usability and reliability are significantly enhanced. 2. By integrating the advantages of vector retrieval and knowledge graph, this method achieves broad coverage and deep reasoning of information. It can not only capture semantic-level connections, but also handle queries that require complex logic or multi-hop relationships, thus providing a solid information foundation for generating accurate and complete answers and solving the problem of information fragmentation that may be caused by a single retrieval technology. 3. The adoption of a localized deployment architecture ensures that the entire data processing process is completed in the internal network environment. This approach completely eliminates the risk of sensitive data being transmitted to the external cloud, meets the venue's strict requirements for data security, and ensures that the system does not depend on external networks and cloud services, thus guaranteeing stability. 4. By constructing prompts containing strict instructions and limiting the generation basis to the retrieved context, the output range of the large language model is effectively constrained. This prompts the model to play the role of information relayer and organizer rather than free creator, thereby significantly suppressing the model's tendency to produce factual errors or illusions in professional fields and ensuring extremely high accuracy of the generated answers. 5. After the results are generated, post-processing steps including deduplication, format optimization, and irrelevant assertion verification are added. This step can identify and filter out information that may be privately introduced by the model but does not appear in the trusted context, providing a final guarantee for the purity and fidelity of the answer and further reducing the risk of residual erroneous information. Attached Figure Description
[0019] The above and other features, advantages, and aspects of the various embodiments of the present invention will become more apparent from the accompanying drawings and the following detailed description. Wherein: Figure 1 A flowchart of a venue intelligent retrieval method based on vector retrieval and knowledge graph according to an embodiment of the present invention is shown; Figure 2 A schematic diagram of the physical relationships of a Yuan Dynasty blue-and-white porcelain jar depicting Guiguzi descending the mountain, according to an embodiment of the present invention, is shown. Figure 3 A schematic diagram illustrating the document completion slicing and vectorization results according to an embodiment of the present invention is shown; Figure 4 The illustration shows a museum intelligent question-and-answer diagram based on an embodiment of the present invention, which asks for an introduction to the Yuan Dynasty blue and white porcelain jar depicting Guiguzi descending the mountain. Figure 5 This illustration shows a museum-based intelligent question-and-answer system based on an embodiment of the present invention, which asks the question "Want to see the Guiguzi Descending the Mountain jar?". Figure 6 A block diagram of a device for intelligent venue retrieval based on vector retrieval and knowledge graph according to an embodiment of the present invention is shown; Figure 7 A schematic diagram of a device for intelligent venue retrieval based on vector retrieval and knowledge graph according to an embodiment of the present invention is shown. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] According to an embodiment of the present invention, a method for intelligent venue retrieval based on vector retrieval and knowledge graph is proposed. By integrating key technologies such as domain adaptive error correction, hybrid retrieval of vector retrieval and knowledge graph, localized deployment, structured prompt constraints, and post-processing verification, the method systematically solves the core problems of input error tolerance, information fragmentation, data security, model illusion, and answer purity in intelligent question answering for professional venues. This achieves a comprehensive improvement in accuracy, security, reliability, and user experience throughout the entire process from query input to answer generation.
[0022] The principles and spirit of the present invention will be explained in detail below with reference to several representative embodiments.
[0023] Figure 1This is a schematic flowchart of a venue intelligent retrieval method based on vector retrieval and knowledge graph according to an embodiment of the present invention. The method includes: Step S01: Receive the user's original query, perform domain-adaptive error correction on the original query using a pre-trained error type classification model and a sequence error correction generation model, and output a standardized query; Step S02: Based on the canonical query, vector retrieval and graph retrieval are executed in parallel. Vector retrieval is based on the vector database to retrieve text fragments semantically related to the canonical query, and graph retrieval is based on the domain knowledge graph to retrieve entities and relational paths related to the canonical query. Step S03: Weighted fusion of the text fragments returned by vector retrieval and the entities and relational paths returned by graph retrieval to form an enhanced context; Step S04: Receive the canonical query, text fragments, and entity and relation paths, integrate them to construct enhanced hints, input them into the large language model, perform post-processing to generate the final answer, and return it to the user.
[0024] It should be noted that although the operation of the method of the present invention has been described in a specific order in the above embodiments and figures, this does not require or imply that the operations must be performed in that specific order, or that all the operations shown must be performed to achieve the desired result. Additionally or alternatively, certain steps may be omitted, multiple steps may be combined into one step, and / or one step may be broken down into multiple steps.
[0025] To provide a clearer explanation of the above-mentioned intelligent venue retrieval method based on vector retrieval and knowledge graph, a specific embodiment will be used for illustration below. However, it is worth noting that this embodiment is only for better illustrating the present invention and does not constitute an improper limitation of the present invention.
[0026] The following example will further illustrate the method of intelligent venue retrieval based on vector retrieval and knowledge graph.
[0027] This example describes a museum scene where visitors inquire about the location and information of specific artifacts.
[0028] Step S01: Receive the user's original query, perform domain-adaptive error correction on the original query using a pre-trained error type classification model and a sequence error correction generation model, and output a standardized query.
[0029] For the corresponding venue scenarios, several corpora containing historical knowledge, descriptions of ancient architecture, and artworks were extracted from the dataset. Several specific error examples for cultural relics were then manually constructed, such as those for the Qingming Shanghe Tu and Qingming Shanghe Tu. The dataset covers five major categories of errors: glyph errors, pronunciation errors, out-of-order characters, duplication, and missing characters. This multi-dimensional annotation provides a foundation for subsequent classification and targeted error correction.
[0030] In this implementation, the system has been loaded with a high-quality knowledge graph containing 450,000 entities and a corresponding vector database constructed using efficient methods.
[0031] The error type classification model uses a pre-trained TextCNN model to classify user input. Error type prediction is performed, and common input errors in the museum field are defined into five categories: ={Glyphics, Pronunciation, Random Order, Repetition, Missing Characters}. TextCNN extracts text features and performs classification through convolutional operations. The classification process is as follows: , in, The error type label is used for prediction; to optimize classification performance, the training objective function uses the cross-entropy loss function: , in, For real labels, The total number of samples.
[0032] Get the error type Then, the system uses a mapping function. This is converted into natural language prompts and concatenated with the original text to construct a template input with error correction instructions. : ; If a user input is detected to contain a pronunciation error, the prompt word to be constructed for subsequent model input is: "A homophone error has been detected. Please correct it in the context of the museum."
[0033] The sequence error correction generation model uses a pre-trained language model based on an encoder-decoder architecture to generate prompt templates. Input encoder to get hidden state The decoder is based on the hidden state. Autoregressive Generates Standard Query , generate the first The conditional probability of each word is .
[0034] In this implementation, the user input system receives the original query input by the visitor. The query request was to see a large blue-and-white porcelain jar from the Yuan Dynasty depicting Guiguzi descending the mountain, where Guiguzi was mistakenly written as the homophone Guiguzi. The query text was fed into a pre-trained TextCNN model for feature extraction and classification inference. The TextCNN model captured the local phonetic anomaly of Guiguzi through its multi-sized convolutional kernels. The model's output layer predicted the probabilities of five defined error categories. Calculations showed that the text had the highest probability in the phonetic error category, therefore the model output the error type label. =Pronunciation error.
[0035] System calls built-in mapping functions The system automatically converts pronunciation errors in tags into targeted natural language guidance instructions: "A homophone error has been detected; please correct it in the context of the museum." Subsequently, the error correction suggestion building unit combines this natural language instruction with the original query. By combining and assembling elements, a prompt template with explicit intent guidance can be dynamically generated. I'd like to see a large blue-and-white porcelain jar from the Yuan Dynasty depicting Guiguzi descending the mountain. (A homophone error has been detected; please correct it based on the museum context.)
[0036] The system will use the above-constructed prompt template As text input, it is passed to a locally deployed pre-trained language model based on an encoder-decoder architecture. The prompt words are first transformed into high-dimensional hidden states containing rich semantic features of context by the encoder. Next, the decoder, based on the hidden state... The model calculates the conditional probability of each token using an autoregressive approach and decodes the output. During the generation process, it incorporates strong prior knowledge of the museum's domain context to identify the correct proper noun as "Guiguzi," ultimately generating a fluent, autoregressive, standardized query. I'd like to see a large blue-and-white porcelain jar from the Yuan Dynasty depicting Guiguzi descending the mountain. This standard query will serve as a high-quality starting point for input.
[0037] The system uses the PyTorch framework to build the TextCNN error classifier and combines it with the Transformers library to drive the sequence generation model for adaptive error correction. The relevant code is as follows: import torch import torch.nn as nn import torch.nn.functional as F from transformers import AutoTokenizer, AutoModelForSeq2SeqLM from typing import Dict, Any # ========================================== # 1. Misclassification Model: Implementation Based on TextCNN # ========================================== class TextCNN(nn.Module): def __init__(self, vocab_size: int, embedding_dim: int, num_classes:int, filter_sizes: list = [2, 3, 4], num_filters: int = 128): super(TextCNN, self).__init__() # Word Embedding Layer self.embedding = nn.Embedding(vocab_size, embedding_dim) # Multi-scale convolutional layers jointly extract N-gram features self.convs = nn.ModuleList([ nn.Conv2d(1, num_filters, (k, embedding_dim)) for k in filter_sizes ]) # Fully Connected Classification Output Layer self.fc = nn.Linear(len(filter_sizes) (num_filters, num_classes) def forward(self, x: torch.Tensor) -> torch.Tensor: # x Input shape: [batch_size, seq_len] x = self.embedding(x) # [batch_size, seq_len, embedding_dim] x = x.unsqueeze(1) # Expand channel dimensions: [batch_size, 1, seq_len, embedding_dim] # Multi-scale convolution and max pooling operations pooled_outputs = [] for conv in self.convs: c = F.relu(conv(x)).squeeze(3) # [batch_size, num_filters, seq_len -k + 1] p = F.max_pool1d(c, c.size(2)).squeeze(2) # [batch_size, num_filters] pooled_outputs.append(p) # Feature assembly and classification out = torch.cat(pooled_outputs, 1) # [batch_size, len(filter_sizes) num_filters] logits = self.fc(out) return logits # ========================================== # 2. Core Business Pipeline of User Query and Error Correction Module # ========================================== class UserQueryCorrector: def __init__(self, cnn_model_path: str, seq2seq_model_path: str,vocab_size: int = 5000): "Initializing the error classifier and sequence error correction generation model" self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # Initialize the error type mapping dictionary f(y) self.error_mapping = { 0: "A glyph confusion error was detected. Please correct it in the context of the museum." 1: "A homophone typo was detected. Please correct it based on the museum context." 2: "Word order disorder detected. Please correct it based on the museum context." 3: "Redundant words and phrases have been detected. Please correct them in conjunction with the museum context." 4: "Missing words detected in the ingredient list. Please correct them in the context of the museum." } # Load and initialize the TextCNN classifier self.text_cnn = TextCNN(vocab_size=vocab_size, embedding_dim=128,num_classes=5).to(self.device) try: self.text_cnn.load_state_dict(torch.load(cnn_model_path, map_location=self.device)) except Exception: print("[Hint] No local TextCNN weights detected. Initialize using a model instance without loaded weights (demo mode).") self.text_cnn.eval() # Load the pre-trained Seq2Seq error correction and generation model and word segmenter (such as BART / T5). self.gen_tokenizer = AutoTokenizer.from_pretrained(seq2seq_model_path) self.gen_model = AutoModelForSeq2SeqLM.from_pretrained(seq2seq_model_path).to(self.device) self.gen_model.eval() def _map_label_to_instruction(self, label_idx: int) -> str: """Mapping function f(y): Converts error type labels into natural language instructions"" return self.error_mapping.get(label_idx, "Please use the museum context for intelligent error correction.") def _tokenize_text(self, text: str) -> torch.Tensor: """Auxiliary function: Converts the input text into a Tensor format acceptable to the model (in practice, a tokenizer is used for this)"" # This demonstration uses simplified Tokenizer logic; in actual projects, a corresponding dictionary or character mapping should be used. tokens = [ord(char) % 5000 for char in text[:64]] if len(tokens) < 64: tokens += [0] (64 - len(tokens)) return torch.tensor([tokens], dtype=torch.long).to(self.device) def correct_query(self, original_query: str) -> str: """ Complete error correction pipeline: Receive raw query -> Predict error type -> Build suggestion template -> Generate standardized query from sequence autoregression """ print(f"[Enter the original query Q]: {original_query}") # --- Step 1: TextCNN Error Type Prediction --- input_tensor = self._tokenize_text(original_query) with torch.no_grad(): logits = self.text_cnn(input_tensor) predicted_label_idx = torch.argmax(logits, dim=1).item() error_type = self.error_mapping.get(predicted_label_idx, "Unknown error") print(f"[TextCNN prediction result]: Error type is -> {error_type} (Label ID:{predicted_label_idx})") # ---Error Correction Hint Building Unit--- instruction = self._map_label_to_instruction(predicted_label_idx) # Dynamically construct prompt word template according to the formula P_j = Q + f(y) templated_prompt = f"{original_query}.{instruction}" print(f"[build prompt template P_j]: {templated_prompt}") # ---Sequence Error Correction Generation Unit (Autoregressive Decoding) --- inputs = self.gen_tokenizer(templated_prompt, return_tensors="pt",max_length=128, truncation=True).to(self.device) with torch.no_grad(): outputs = self.gen_model.generate( inputs["input_ids"], max_length=64, num_beams=4, early_stopping=True ) norm_query = self.gen_tokenizer.decode(outputs[0], skip_special_tokens=True) print(f"[output norm_query Q']: {norm_query}\n") return norm_query # ========================================== # 3. Example Data Substitution Test # ========================================== if __name__ == "__main__": # Instantiate the full-process error correction controller corrector = UserQueryCorrector( cnn_model_path=". / models / text_cnn.pth", seq2seq_model_path=". / models / bart_museum_corrector" ) # Verify the entire workflow by substituting data from the example. raw_input = "I want to see a large blue-and-white porcelain jar from the Yuan Dynasty depicting Guiguzi descending the mountain." refined_output = corrector.correct_query(raw_input) Step S02: Based on the canonical query, vector retrieval and graph retrieval are executed in parallel. Vector retrieval is based on the vector database to retrieve text fragments semantically related to the canonical query, and graph retrieval is based on the domain knowledge graph to retrieve entities and relational paths related to the canonical query.
[0038] The execution process of vector retrieval is based on a retrieval-enhanced generative architecture, including: Unstructured domain text is segmented into multiple text blocks. And use a word embedding model to embed each text block Encode the query into a vector representation and store it in a vector database; encode the canonical query into a query vector. Calculate its relationship with all text block vectors in the vector database. The similarity scores are used to sort and return the top results. The most relevant set of text blocks .
[0039] It should be noted that the goal of the chunking process is to chunk large-scale unstructured or semi-structured long texts. The text is segmented into multiple semantically coherent blocks to facilitate subsequent vectorization encoding and information retrieval. To ensure no contextual information is lost, sentence- or paragraph-based segmentation methods are often used, sometimes incorporating sliding window and overlapping segmentation methods. The processing formula is shown below: , Among them, it means Text segmentation function, Indicates the first Each block, This represents the total number of blocks.
[0040] Then, a word embedding model is used to vectorize each segmented text block and store it in a vector database. The processing formula is shown below, where... For vectorized encoding functions, these vectors This represents the semantic information of the blocks.
[0041] .
[0042] During the retrieval process, the goal is to retrieve text chunks pre-stored in the vector database that match the user's query. The set of text blocks that are most semantically relevant. First, the user input query is compared with the formula... The same vectorization encoding process is applied, followed by text matching and ranking based on vector similarity or relevance algorithms. The processing formula is shown below, where... Function for user query vector , with all text blocks Perform similarity calculations to obtain a set of similarity scores. Use... Reorder the scores to obtain the top K text blocks. : ; Blocking process To ensure semantic coherence, overlapping block methods and vectorized functions are often used. The text is mapped to points in a high-dimensional semantic space. During retrieval, the query vector is calculated. With all vectors in the library cosine similarity It retrieves the top-K most similar text blocks and outputs them. This process excels at retrieving semantically relevant descriptive and detailed content from massive amounts of unstructured text (such as long descriptions of exhibits and research papers), providing rich background information for generating answers. In this system, Chinese optimization models such as BGE and the Chroma vector database are commonly used for implementation.
[0043] The execution process of graph retrieval includes: finding entity nodes in the domain knowledge graph that directly match the standard query; starting from the matched entity nodes, performing one-hop or multi-hop traversal along the predefined relation edges in the knowledge graph to obtain the subgraph structure containing the central entity and its associated attributes and related entities, which serves as the retrieved relation path.
[0044] It's important to note that the entity matching unit quickly locates the core entity targeted by the query by precisely or fuzzily matching keywords in the canonical query with attributes such as the name and aliases of entities in the knowledge graph. For example, when querying who the Tang Dynasty painter Yan Liben's teacher was, the system first locates Yan Liben; then, starting from the aforementioned anchor entity, it performs a directed traversal along predefined, semantically rich relational edges in the knowledge graph, such as "student," "creator," and "belongs to." This traversal can be one-hop or multi-hop, thereby extracting a structured related subgraph. This process accurately captures the implicit multi-hop relationships between entities, connecting facts originally scattered in the text into a complete chain of evidence, effectively solving the problem of information fragmentation in single-vector retrieval when handling complex reasoning queries, as mentioned in the background technology. The result of graph retrieval is not loose text, but structured knowledge with clear semantic relationships, providing a logical foundation for generating accurate and rigorous answers.
[0045] In this embodiment, a standard query is received. I want to see a large blue-and-white porcelain jar from the Yuan Dynasty depicting Guiguzi descending the mountain. The system pre-segments the unstructured long text from the museum into multiple semantically coherent text blocks using an overlapping segmentation method. The locally deployed bge-large-zh-v1.5 word embedding model is used as the vectorized encoding function. Each text block is transformed into a 1024-dimensional high-dimensional dense vector. And persistently stored in the Chroma vector database, such as Figure 2 As shown.
[0046] Vector retrieval receives canonical queries Encode it into a query vector using a similar word embedding model. Then, calculations were performed. Compared with all stored text block vectors in the vector database Cosine similarity between The system sorts users by similarity score from highest to lowest and extracts the top-ranked users. The set of the most relevant text blocks, as defined in this embodiment. =2: Text block 1: The Yuan blue and white porcelain jar depicting Guiguzi descending the mountain is a representative work of Yuan dynasty blue and white porcelain. The jar is decorated with the scene of Guiguzi descending the mountain using cobalt blue pigment.
[0047] Text block 2: This blue and white porcelain jar has a full composition, clear layers, and a majestic overall shape, showcasing the superb firing techniques and artistic level of Yuan Dynasty porcelain.
[0048] Entity matching units in graph retrieval will standardize the query. Keywords are extracted and matched with entity names and attributes in a domain knowledge graph built using Neo4j, such as... Figure 3 As shown. The system successfully and accurately located the core anchor entity node: (e1:Artifact {name: "Yuan Dynasty Blue and White Porcelain Jar with Guiguzi Descending the Mountain"}).
[0049] Relationship path expansion: The relationship path expansion unit is activated. Starting from the entity node e1, a one-hop directed traversal expansion is performed along the predefined relationship edges (such as "belongs to" and "located in") in the knowledge graph. The subgraph structure containing the central entity, its associated attributes, and neighboring nodes is successfully extracted. (Yuan Dynasty Blue and White Porcelain Jar with the Design of Guiguzi Descending the Mountain) - [belongs to] -> (Yuan Dynasty) (Yuan Dynasty Blue and White Porcelain Jar with the Scene of Guiguzi Descending the Mountain) - [Located at] -> (Ancient China Exhibition Hall, 2nd Floor, North Zone) The extracted structured knowledge is output in parallel with the text fragments retrieved by vector retrieval.
[0050] The relevant code for this step is as follows: import os from typing import List, Dict, Any import chromadb from neo4j import GraphDatabase # ========================================== #Vector Search (based on ChromaDB) # ========================================== class VectorSearchSubmodule: def __init__(self, db_path: str = ". / vector_store", collection_name:str = "museum_docs"): Initialize the Chroma vector database client. # In actual deployment, this connects to the real persistent vector library. self.chroma_client = chromadb.PersistentClient(path=db_path) self.collection = self.chroma_client.get_or_create_collection(name=collection_name) # Hint: Initialize your local embedding model here, for example, bge-large-zh-v1.5 # from sentence_transformers import SentenceTransformer # self.embedder = SentenceTransformer('BAAI / bge-large-zh-v1.5') def get_query_embedding(self, query: str) -> List[float]: """Transform the canonical query Q' into a dense vector""" # Real-world call: return self.embedder.encode(query).tolist() # The space below is a placeholder to prevent errors. You can delete it after integrating the real model. return [0.0] 1024 def search(self, query: str, top_k: int = 2) -> List[Dict[str, Any]]: "Calculate cosine similarity and return the Top-K related text blocks" query_vec = self.get_query_embedding(query) try: raw_results = self.collection.query( query_embeddings=[query_vec], n_results=top_k ) formatted_results = [] if raw_results['documents'] and raw_results['documents'][0]: for idx, doc in enumerate(raw_results['documents'][0]): formatted_results.append({ "id": raw_results['ids'][0][idx], "text": doc, "distance": raw_results['distances'][0][idx] }) return formatted_results except Exception as e: print(f"[Vector Search Warning] Database not ready or query failed: {e}") return [] # ========================================== #Graph Search (based on Neo4j) # ========================================== class KnowledgeGraphSearchSubmodule: def __init__(self, uri: str, user: str, password: str): Initialize the Neo4j graph database official driver connection. try: self.driver = GraphDatabase.driver(uri, auth=(user, password)) except Exception as e: print(f"[Graph Connection Warning] Please ensure your local Neo4j service is running: {e}") self.driver = None def close(self): Close database connection. if self.driver: self.driver.close() def _extract_entity_from_query(self, query: str) -> str: """ Entity matching unit: Dynamically extracts core entities from Q' using NER (Named Entity Recognition).
[0051] It can be connected to large models for dynamic entity extraction.
[0052] """
[0053] def search(self, norm_query: str) -> Dict[str, Any]:
[0054] """Relational Path Extension Unit: Performs a one-hop directed traversal along the graph""
[0055] matched_entity = self._extract_entity_from_query(norm_query)
[0056] if not matched_entity or not self.driver:
[0057] return {"entity": None, "subgraph_paths": []}
[0058] # Real Cypher query statements
[0059] cypher_query = """
[0060] MATCH (e:Artifact {name: $entity_name})-[r]-(neighbor)
[0061] RETURN e, type(r) AS relation_type, neighbor
[0062] LIMIT 10
[0063] """
[0064] subgraph_paths = []
[0065] try:
[0066] with self.driver.session() as session:
[0067] result = session.run(cypher_query, entity_name=matched_entity)
[0068] For record in result:
[0069] path_str = f"({record['e']['name']})-[{record['relation_type']}]->({record['neighbor']['name']})"
[0070] subgraph_paths.append(path_str)
[0071] except Exception as e:
[0072] print(f"[Cypher execution failed] {e}")
[0073] return {
[0074] "entity": matched_entity, "subgraph_paths": subgraph_paths } # ========================================== # 3. Hybrid Search Fusion Interface (for backend calls such as FastAPI) # ========================================== HybridRetriever class: def __init__(self): self.vector_searcher = VectorSearchSubmodule() # Please replace with your real Neo4j account and password. self.graph_searcher = KnowledgeGraphSearchSubmodule("bolt: / / localhost:7687", "neo4j", "password") def retrieve(self, query: str) -> Dict[str, Any]: print(f"\n[Pipeline Startup] Receive Standard Query: {query}") vec_res = self.vector_searcher.search(query, top_k=2) print(f" └── Vector retrieval recall node count: {len(vec_res)}") kg_res = self.graph_searcher.search(query) print(f" └── Graph search hit entities: {kg_res.get('entity', 'missed')}") return { "vector_context": vec_res, "graph_context": kg_res } Step S03: Weighted fusion of the text fragments returned by vector retrieval and the entities and relational paths returned by graph retrieval to form an enhanced context.
[0075] Convert the entity attributes and relationship paths contained in the graph retrieval results into coherent natural language description fragments; Based on the intent type of the query, dynamically assign fusion weights to the vector retrieval results and the graph retrieval results. and ,in ; Dynamic allocation satisfies the following condition: when the query intent is multi-hop relational reasoning, it enables... > When the query intent is a detailed description or an open-ended statement, make > ; The two weighted search results are then concatenated in sequence to form a unified enhanced context.
[0076] It's important to note that this step consists of two parts: First, format alignment is performed, transforming the structured subgraphs obtained from the graph retrieval into coherent natural language descriptions using predefined templates. This ensures consistency in form with the text fragments obtained from the vector retrieval, facilitating subsequent processing. Second, intelligent weighting, the core innovation of this step, involves real-time analysis of canonical queries using a lightweight intent classifier or keyword-based rules to determine whether they fall into relational reasoning or detailed description categories. This dynamic weighting mechanism enables adaptive optimization of the retrieval strategy: for reasoning questions like "What is B of A?", the system relies on the precise relational paths provided by the graph, assigning higher weight to graph results; for questions like "Please introduce / describe A", the system depends on the rich detailed text provided by the vector retrieval, assigning higher weight to vector results. Finally, the two weighted parts are sequentially concatenated to form an enhanced context that contains both a precise factual skeleton and rich detailed content, providing optimal information raw materials for the generation module.
[0077] In this embodiment, the system receives text fragments about cultural relic craftsmanship retrieved by vector retrieval and structured sub-graphs containing exhibition hall locations and dynasties extracted by graph retrieval. This is then processed using a standardized query formatted from visitor queries. To illustrate this step, let's take a large Yuan Dynasty blue-and-white porcelain jar depicting Guiguzi descending the mountain as an example. The specific processing procedure is as follows: The raw data returned by the knowledge graph retrieval is a structured set of triples: {(Yuan Dynasty Blue and White Porcelain Jar with the Scene of Guiguzi Descending the Mountain) - [: Belongs to] -> (Yuan Dynasty), (Yuan Dynasty Blue and White Porcelain Jar with the Scene of Guiguzi Descending the Mountain) - [: Located at] -> (Ancient China Exhibition Hall, Second Floor, North Zone)}. The fusion unit converts this data into a coherent text segment using built-in natural language mapping rules: "According to the knowledge graph association information, the Yuan Dynasty Blue and White Porcelain Jar with the Scene of Guiguzi Descending the Mountain belongs to the Yuan Dynasty and is currently located in the Ancient China Exhibition Hall, Second Floor, North Zone." The system performs real-time analysis of canonical queries using a lightweight intent classifier. Since the query explicitly includes a complex, multi-hop relationship inference request regarding the specific location of the artifact and its historical dynasty, the system identifies it as a relational inference intent. Based on the adaptive mechanism defined in the patent, the system assigns higher fusion weights to the graph retrieval results and dynamically sets the graph weights. =0.7, vector retrieval weight =0.3, which satisfies > and + =1 is a strong constraint condition.
[0078] The two parts of the search results are weighted and concatenated according to the physical order of factual skeleton first and descriptive details second, forming a unified high-quality enhanced context. The final concatenated text is: [Factual Background]: According to the knowledge graph association information, the Yuan blue and white porcelain jar with the Guiguzi Descending the Mountain picture belongs to the Yuan Dynasty and is currently located in the Ancient China Exhibition Hall on the second floor of the North Zone.
[0079] [Detailed Description]: The Yuan Dynasty blue-and-white porcelain jar depicting Guiguzi descending the mountain is a representative work of Yuan Dynasty blue-and-white porcelain. The jar is decorated with the scene of Guiguzi descending the mountain, using cobalt blue pigment. This large blue-and-white jar has a full composition, clear layers, and a majestic overall shape.
[0080] The core code for this step is as follows: from typing import List, Dict, Any # ========================================== # Search result fusion # ========================================== class ResultFusionModule: def __init__(self): self.tpl_dynasty = "Based on the knowledge graph association information, {subject} belongs to {dynasty}" self.tpl_location = "Currently located at {location}" self.tpl_general_relation = "Based on the knowledge graph association information, {subject} and {target} have a {relation} relationship." def align_graph_data(self, graph_results: Dict[str, Any]) -> str: subject = graph_results.get("entity") if not subject: return "" natural_sentences = [] # 1. Prioritize extracting and transforming structured attributes (such as dynasty, category, etc.) attributes = graph_results.get("attributes", {}) if "dynasty" is in attributes: natural_sentences.append(self.tpl_dynasty.format(subject=subject,dynasty=attributes["dynasty"])) # 2. Dynamically parse subgraph paths to adapt to any one-hop / multi-hop relationship edges (e.g., -[located]->, -[material]->, etc.) subgraph_paths = graph_results.get("subgraph_paths", []) for path in subgraph_paths: if "-[" in path and "]->" in path: try: parts = path.split("-[") src = parts[0].strip("()") rel_target = parts[1].split("]->") rel = rel_target[0].strip() tgt = rel_target[1].strip("()") if rel == "located at": natural_sentences.append(self.tpl_location.format(location=tgt)) else: natural_sentences.append(self.tpl_general_relation.format(subject=src, relation=rel, target=tgt)) except Exception: # When a parsing error occurs, the original path string is used as a fallback. natural_sentences.append(path) else: natural_sentences.append(path) return ",".join(natural_sentences) + "." if natural_sentences else "" def dynamic_weighting(self, intent_type: str) -> tuple: if intent_type == "reasoning": # Multi-hop relationship reasoning intent (e.g., locating artifacts, clarifying dynastic affiliation): to increase the weight of the map. alpha_k = 0.7 alpha_v = 0.3 else: # Detailed description / open browsing intent: Increase the weight of text vectors alpha_k = 0.3 alpha_v = 0.7 return alpha_k, alpha_v def fuse(self, vector_results: List[Dict[str, Any]], graph_results:Dict[str, Any], intent_type: str = "reasoning") -> str: """ The core execution pipeline for fusion of search results """ # 1. Alignment and textification of structured spectral data formats graph_nl = self.align_graph_data(graph_results) # 2. Dynamically calculate fusion weights based on intent alpha_k, alpha_v = self.dynamic_weighting(intent_type) # 3. Extract and merge vector-based text fragments. vector_text_list = [doc.get("text", "") for doc in vector_results if"text" in doc] vector_nl = " ".join(vector_text_list) # 4. Concatenate the components in sequence to form a unified enhanced context. # Note: alpha_k and alpha_v can be passed as metadata to the Prompt building block or directly determine the concatenation priority. enhanced_context = f"[Background Information]: {graph_nl}\n[Detailed Description]: {vector_nl}" print(f"[Intent Determination]: {intent_type} (Dynamic Weight Assignment -> Graph Weight α_k:{alpha_k}, Vector Weight α_v:{alpha_v})") return enhanced_context # ========================================== Example of substitution flow test # ========================================== if __name__ == "__main__": fusion_module = ResultFusionModule() sample_vector_results = [ {"id": "DOC_001", "text": "This artifact has a full and well-defined shape, with clear layers and a robust overall form, showcasing the superb firing techniques and artistic skill of ancient craftsmen."}, {"id": "DOC_002", "text": "The vessel is exquisitely painted with smooth lines and possesses extremely high historical and cultural research value."} ] sample_graph_results = { "entity": "a certain precious cultural relic", "attributes": {"dynasty": "Ming Dynasty", "category": "porcelain"}, "subgraph_paths": [ "(A certain precious cultural relic) - [located] -> (the third exhibition hall of the main exhibition hall)" ] } final_context = fusion_module.fuse( vector_results=sample_vector_results, graph_results=sample_graph_results, intent_type="reasoning" ) print("\n[Enhanced context output by the fusion unit of search results]:") print(final_context) Step S04: Receive the canonical query, text fragments, and entity and relation paths, integrate them to construct enhanced hints, input them into the large language model, perform post-processing to generate the final answer, and return it to the user.
[0081] The specific steps for integrating and building enhanced prompts are as follows: Design a structured prompt template that includes, in sequence: system role definition, corrected user specification query, enhanced context, and instructions requiring the large language model to generate faithful and fluent answers strictly based on the enhanced context.
[0082] It's important to note that this step is the final crucial control point to suppress illusions generated by large language models and ensure the accuracy of answers. It achieves this by constructing structured prompts: First, the system assigns a clear role, such as a meticulous museum guide assistant, to guide the model into the appropriate response mode; second, it corrects and standardizes the user's original query to ensure the model accurately understands the user's intent; finally, it fully integrates the relevant contextual information provided by the graph retrieval into enhanced content, serving as the sole basis for the model to generate answers.
[0083] The core instruction of this step is to require the model to generate answers strictly based on the provided context. This is equivalent to adding factual constraints to the model's creativity, making it focus more on information integration and accurate paraphrasing rather than free interpretation. Through this prompt design, combined with high-quality, highly relevant contextual information, the output of large language models can be effectively limited to the scope of known facts, thereby systematically reducing factual errors in specialized domains.
[0084] In this embodiment, the generation module receives the specification query. I'd like to see a large blue-and-white porcelain jar from the Yuan Dynasty depicting Guiguzi descending the mountain, along with the integrated enhanced context. The module uses a built-in structured prompt template to encapsulate system role definitions, user specification queries, enhanced context from the fusion unit, and strong constraint generation instructions in an orderly manner, assembling them into the final input string submitted to the model. Full text of the structured Prompt: [System Role]: You are a meticulous museum tour guide assistant.
[0085] [Standardized User Query]: I want to see a large blue-and-white porcelain jar from the Yuan Dynasty depicting Guiguzi descending the mountain.
[0086] [Enhanced Context]:
[0087] [Background Information]: According to the knowledge graph association information, the Yuan blue and white porcelain jar with the Guiguzi Descending the Mountain design belongs to the Yuan Dynasty and is currently located in the Ancient China Exhibition Hall on the second floor of the North Zone.
[0088] [Detailed Description]: The Yuan Dynasty blue-and-white porcelain jar depicting Guiguzi descending the mountain is a representative work of Yuan Dynasty blue-and-white porcelain. The jar is decorated with the scene of Guiguzi descending the mountain, using cobalt blue pigment. This large blue-and-white jar has a full composition, clear layers, and a majestic overall shape.
[0089] [Core Instructions]: Please generate a faithful and fluent answer strictly based on the [enhanced context] provided above. If the relevant facts are not mentioned in the context, please answer "I don't know" directly. Subjective interpretation or fabrication of any historical details is strictly prohibited.
[0090] The system uses the locally deployed Ollam framework to stream the structured prompts into an open-source large language model. Due to the strong factual constraints attached to the prompts, the model strictly adheres to the spatial location and artifact characteristics within the context, employing an autoregressive decoding approach based on information integration and accurate paraphrasing to generate a baseline answer: "The Yuan Dynasty blue-and-white porcelain jar depicting Guiguzi descending the mountain is from the Yuan Dynasty and is currently located in the Ancient China Exhibition Hall on the second floor of the North Zone. It is a representative work of Yuan Dynasty blue-and-white porcelain, depicting the scene of Guiguzi descending the mountain, decorated with cobalt blue pigment…". After post-processing to generate the final answer, this text is presented safely and accurately to visitors. The core code for this step is as follows: import os import requests from typing import Dict, Any # ========================================== # Answer generation module # ========================================== class GenerationModule: def __init__(self, ollama_base_url: str = "http: / / localhost:11434",model_name: str = "qwen2.5"): """Initialize the generation module and configure the connection with the local Ollam client"" self.ollama_base_url = ollama_base_url self.model_name = model_name self.prompt_template = ( "[System Role]: {role_definition}\n" "[Standardized User Query]: {norm_query}\n" "[Enhanced Context]:\n{enhanced_context}\n" "[Core Instruction]: Please generate a faithful and fluent answer based strictly on the [enhanced context] provided above." "The location and age of the cultural relics mentioned in the answer must be absolutely consistent with the context; any form of free interpretation or fabrication is strictly prohibited." ) self.role_definition = "You are a meticulous museum guide assistant, designed to provide visitors with absolutely authentic and reliable information about artifacts." def build_structured_prompt(self, norm_query: str, enhanced_context:str) -> str: """ Design structured prompt templates and build enhanced prompts. """ structured_prompt = self.prompt_template.format( role_definition=self.role_definition, norm_query=norm_query, enhanced_context=enhanced_context ) return structured_prompt def call_local_llm_via_ollama(self, prompt: str) -> str: api_url = f"{self.ollama_base_url} / api / generate" payload = { "model": self.model_name, "prompt": prompt, "stream": False, # Simplify to non-streamed output to get the complete answer directly. "options": { "temperature": 0.1, # Reduce randomness and ensure strict adherence to context (factual constraint). "top_p": 0.9 } } try: print(f"[Ollama service status]: Sending a request to the local model ({self.model_name}) and performing inference...") response = requests.post(api_url, json=payload, timeout=60) if response.status_code == 200: result_json = response.json() return result_json.get("response", "The generated result is empty.") else: The Ollama API call failed with status code {response.status_code} and details {response.text}. except requests.exceptions.ConnectionError: The error message "[Error] Unable to connect to the local Ollam service. Please ensure the service is running (ollamarun qwen2.5)" indicates an issue. except Exception as e: return f"[Error] An exception occurred during the generation process: {str(e)}" def generate_answer(self, norm_query: str, enhanced_context: str) ->str: """ The core execution pipeline of the generation step """ final_prompt = self.build_structured_prompt(norm_query, enhanced_context) print("--- [Constructed structured enhancement prompt (Prompt)] ---") print(final_prompt) print("-" 40 + "\n") raw_answer = self.call_local_llm_via_ollama(final_prompt) return raw_answer if __name__ == "__main__": # Instantiate and generate modules gen_module = GenerationModule(ollama_base_url="http: / / localhost:11434", model_name="qwen2.5") # Simulate the canonical query passed from the upstream sample_norm_query = "I want to know the basic information and exhibition location of a key cultural relic in the museum's collection". # Simulate the enhanced context output by the upstream fusion module sample_enhanced_context = ( [Background Information]: According to the knowledge graph, a key artifact in the museum's collection dates back to the Ming Dynasty and is currently located in the third exhibition hall of the main exhibition hall. "[Detailed Description]: This artifact is made with extremely exquisite craftsmanship, has a regular shape, and delicate decorations, possessing extremely high historical research and artistic appreciation value." ) # Execute the generation task final_output = gen_module.generate_answer( norm_query=sample_norm_query, enhanced_context=sample_enhanced_context ) print("\n--- [The final original answer generated by the large language model] ---") print(final_output) The system loads and runs an open-source large language model through the locally deployed Ollam framework, ensuring that all user queries, domain knowledge data, and intermediate processing are stored on the local server, achieving complete data privatization and meeting the security and privacy requirements of the venue scenario.
[0091] It is worth noting that by deploying open-source models such as Llama 2 and Qwen on the venue's servers using the Ollama framework, all data, including user queries, internal knowledge bases, and intermediate results, are processed locally in a closed loop, eliminating the risk of sensitive information leakage. Simultaneously, the venue can update its local knowledge base at any time, enabling the system to instantly perceive the latest information and resolving the issue of knowledge lag in large cloud-based models.
[0092] Post-processing includes deduplicating obvious duplicate content in the answers generated by the large language model, adjusting the paragraph format of the answers to enhance readability, and checking whether the answers contain irrelevant assertions that are outside the scope of the retrieval context.
[0093] Finally, it also includes log generation and evaluation, recording the original query, standardized query, search results, generated answers, and user feedback in each question-and-answer interaction, and automatically analyzing and statistically processing the quality of the questions and answers based on predefined evaluation metrics. It records end-to-end data, enabling operations and maintenance personnel to perform performance analysis, problem tracking, and algorithm iteration. Based on evaluation metrics from the custom test set MuseumQA (such as fidelity and ROUGE-L), it can quantitatively evaluate system performance, providing data-driven decision-making support for optimizing search strategies, adjusting fusion weights, or improving prompt templates.
[0094] like Figure 4 and Figure 5 As shown, when the two question words are inconsistent, the answers obtained are also different.
[0095] Based on the same inventive concept, this invention also proposes a device for intelligent venue retrieval based on vector retrieval and knowledge graphs. The implementation of this device can be found in the implementation of the method described above; repeated details will not be repeated. Figure 6 As shown, the device 100 includes: Query correction module 101: It is used to receive the user's original query, perform domain-adaptive error correction on the original query through a pre-trained error type classification model and sequence error correction generation model, and output a standardized query. Parallel retrieval module 102: used to perform vector retrieval and graph retrieval in parallel based on canonical queries. Vector retrieval is based on vector database to retrieve text fragments semantically related to canonical queries, and graph retrieval is based on domain knowledge graph to retrieve entities and relational paths related to canonical queries. Weighted fusion module 103: Used to perform weighted fusion of text fragments returned by vector retrieval and entities and relational paths returned by graph retrieval to form an enhanced context; Answer generation module 104: It receives standardized queries, text fragments, and entity and relation paths, integrates and constructs enhanced prompts, inputs them into a large language model, performs post-processing to generate the final answer, and returns it to the user.
[0096] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the described module can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0097] like Figure 7 As shown, the device includes a central processing unit (CPU), which can perform various appropriate actions and processes based on computer program instructions stored in read-only memory (ROM) or loaded from storage units into random access memory (RAM). The RAM can also store various programs and data required for device operation. The CPU, ROM, and RAM are interconnected via a bus. Input / output (I / O) interfaces are also connected to the bus.
[0098] Multiple components in the device are connected to the I / O interface, including: input units such as keyboards and mice; output units such as various types of displays and speakers; storage units such as disks and optical discs; and communication units such as network interface cards (NICs), modems, and wireless transceivers. The communication unit allows the device to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0099] The processing unit executes the various methods and processes described above, such as method steps S01 to S04. For example, in some embodiments, method steps S01 to S04 may be implemented as a computer software program tangibly contained in a machine-readable medium, such as a storage unit. In some embodiments, part or all of the computer program may be loaded and / or installed on the device via ROM and / or a communication unit. When the computer program is loaded into RAM and executed by the CPU, one or more steps of method steps S01 to S04 described above may be performed. Alternatively, in other embodiments, the CPU may be configured to execute method steps S01 to S04 by any other suitable means (e.g., by means of firmware).
[0100] The functions described above in this document can be performed at least in part by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: field programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload programmable logic devices (CPLDs), and so on.
[0101] The program code used to implement the methods of the present invention can be written in any combination of one or more programming languages. This program code can be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code can be executed entirely on the machine, partially on the machine, as a standalone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0102] In the context of this invention, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0103] Furthermore, although the operations are described in a specific order, this should be understood as requiring that such operations be performed in the specific order shown or in sequential order, or requiring that all illustrated operations be performed to achieve the desired result. In certain environments, multitasking and parallel processing may be advantageous. Similarly, although several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the invention. Certain features described in the context of individual embodiments may also be implemented in combination in a single implementation. Conversely, various features described in the context of a single implementation may also be implemented individually or in any suitable sub-combination in multiple implementations.
[0104] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.
Claims
1. A method for intelligent venue retrieval based on vector retrieval and knowledge graph, characterized in that, The method includes: Step S01: Receive the user's original query, perform domain-adaptive error correction on the original query using a pre-trained error type classification model and a sequence error correction generation model, and output a standardized query; Step S02: Based on the canonical query, vector retrieval and graph retrieval are executed in parallel. Vector retrieval is based on the vector database to retrieve text fragments semantically related to the canonical query, and graph retrieval is based on the domain knowledge graph to retrieve entities and relational paths related to the canonical query. Step S03: Weighted fusion of the text fragments returned by vector retrieval and the entities and relational paths returned by graph retrieval to form an enhanced context; Step S04: Receive the canonical query, text fragments, and entity and relation paths, integrate them to construct enhanced hints, input them into the large language model, perform post-processing to generate the final answer, and return it to the user.
2. The method for intelligent venue retrieval based on vector retrieval and knowledge graph according to claim 1, characterized in that, The error type classification model described in step S01 uses a pre-trained TextCNN model to predict the error type of user input, defining common input errors in the museum field as: character shape, character pronunciation, disorder, repetition, and missing characters.
3. The method for intelligent venue retrieval based on vector retrieval and knowledge graph according to claim 2, characterized in that, The specific steps of the error correction generation model in step S01 to perform domain-adaptive error correction on the original query are as follows: After obtaining the error type, the system converts it into a natural language prompt through a mapping function, and concatenates it with the original text to construct a template input with error correction instructions; The sequence error correction generation model adopts a pre-trained language model based on an encoder-decoder architecture. The prompt template is input into the encoder to obtain the hidden state, and the decoder generates a canonical query autoregressively based on the hidden state.
4. The method for intelligent venue retrieval based on vector retrieval and knowledge graph according to claim 1, characterized in that, The vector retrieval process described in step S02 is based on a retrieval enhancement generation architecture, including: segmenting unstructured domain text into multiple text blocks, encoding each text block into a vector representation using a word embedding model, and storing it in a vector database; encoding the canonical query into a query vector, calculating its similarity to all text block vectors in the vector database, sorting them according to the similarity score, and returning the top results. The most relevant set of text blocks.
5. The method for intelligent venue retrieval based on vector retrieval and knowledge graph according to claim 1, characterized in that, The execution process of graph retrieval described in step S02 includes: searching for entity nodes in the domain knowledge graph that directly match the standard query; starting from the matched entity node, performing one-hop or multi-hop traversal along the predefined relation edges in the knowledge graph to obtain a subgraph structure containing the central entity and its associated attributes and related entities, which serves as the retrieved relation path.
6. The method for intelligent venue retrieval based on vector retrieval and knowledge graph according to claim 1, characterized in that, The specific steps of step S03 are as follows: Convert the entity attributes and relationship paths contained in the graph retrieval results into coherent natural language description fragments; Based on the intent type of the query, dynamically assign fusion weights to the vector retrieval results and the graph retrieval results. and ,in ; Dynamic allocation satisfies the following condition: when the query intent is multi-hop relational reasoning, it enables... > ; When the query intent is a detailed description or an open-ended statement, make > ; The two weighted search results are then concatenated in sequence to form a unified enhanced context.
7. The method for intelligent venue retrieval based on vector retrieval and knowledge graph according to claim 1, characterized in that, The specific steps for integrating and constructing enhanced prompts as described in step S04 are as follows: design a structured prompt template, which includes, in sequence: system role definition, user specification query after error correction, enhanced context, and instructions requiring the large language model to strictly generate faithful and fluent answers based on the enhanced context.
8. A device for intelligent venue retrieval based on vector retrieval and knowledge graph, characterized in that, The device implements the method as described in any one of claims 1 to 7, comprising: Query correction module: It receives the user's original query, performs domain-adaptive error correction on the original query through a pre-trained error type classification model and sequence error correction generation model, and outputs a standardized query. Parallel retrieval module: used to perform vector retrieval and graph retrieval in parallel based on canonical queries. Vector retrieval is based on vector database to retrieve text fragments semantically related to the canonical query, and graph retrieval is based on domain knowledge graph to retrieve entities and relational paths related to the canonical query. Weighted fusion module: Used to weight and fuse the text fragments returned by vector retrieval with the entities and relational paths returned by graph retrieval to form an enhanced context; Answer generation module: It receives standardized queries, text fragments, and entity and relationship paths, integrates them to build enhanced suggestions, inputs them into a large language model, performs post-processing to generate the final answer and returns it to the user.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1 to 7.