A knowledge base complex query method based on neural symbol enhancement

CN122527337APending Publication Date: 2026-08-07SHANDONG QINGXUN INTELLIGENT TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANDONG QINGXUN INTELLIGENT TECHNOLOGY CO LTD
Filing Date
2026-05-14
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

[0005]针对现有技术的不足,本申请的目的是提供一种基于神经符号增强的知识库复杂查询方法,通过神经模型与符号推理的协同,解决了复杂查询中的语义歧义、多跳推理低效及结果准确率低等问题,从而提升复杂查询的准确性与效率

Benefits of technology

首先,本申请通过神经模型编码识别和符号规则消歧的协同机制,既能发挥神经模型对自然语言的灵活理解能力,又借助符号规则解决语义歧义问题,显著提升核心实体、关系及约束条件的识别准确性。并且采用了神经模型检索候选路径、符号规则筛选和权重融合的多级推理机制,神经模型可快速缩小检索范围,符号规则用于剔除无效路径,权重融合筛选最优路径,避免路径漂移和组合爆炸问题,兼顾推理效率与可靠性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122527337A_ABST
    Figure CN122527337A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of data query and processing, in particular to a knowledge base complex query method based on neural symbol enhancement, which comprises the following steps: constructing a neural symbol hybrid knowledge base; receiving a query text and performing semantic analysis, and converting the query text into a structured query graph in a directed graph structure; retrieving a multi-hop reasoning candidate path similar to the structured query graph vector from the neural symbol hybrid knowledge base, and screening to obtain an effective reasoning path; extracting entity relationship information and text corpus examples corresponding to the effective reasoning path, converting the entity relationship information and the text corpus examples into prompt text in natural language description, combining the prompt text with the query text, forming an optimized input, and inputting the optimized input into a pre-trained language model to generate and output a query result. Through the collaborative mechanism of neural model coding recognition and symbol rule disambiguation, the flexible understanding ability of the neural model for natural language is exerted, and the semantic ambiguity problem is solved with the aid of the symbol rule, so that the identification accuracy of core entities, relationships and constraint conditions is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data query and processing technology, and more specifically, to a complex query method for knowledge bases based on neural symbolic enhancement. Background Technology

[0002] Knowledge base querying is one of the core tasks in the field of natural language processing. Its purpose is to convert users' natural language queries into a form that the knowledge base can understand, and to obtain accurate answers from structured knowledge graphs or unstructured text. As the scale of knowledge bases expands and application scenarios become more complex, user queries are gradually exhibiting complex characteristics such as multi-hop associations, multiple constraints, and semantic ambiguity, making traditional query methods difficult to meet the needs.

[0003] In existing technologies, knowledge base query methods are mainly divided into three categories: pure symbolic methods, pure neural model methods, and simple hybrid methods. Pure symbolic methods parse queries based on manually defined rules or logical language. While the reasoning is rigorous, they rely excessively on manual rules, have poor generalization capabilities, and struggle to handle semantic ambiguity and complex multi-hop scenarios. Pure neural model methods achieve semantic matching and path retrieval through neural networks. They have strong generalization capabilities but lack interpretability. Multi-hop reasoning is prone to path drift, and the logical consistency of query results is difficult to guarantee. Simple hybrid methods attempt to combine neural models and symbolic reasoning, but these are mostly shallow integrations that do not deeply optimize for the core pain points of complex queries, resulting in query accuracy and efficiency still needing improvement.

[0004] Specifically, existing technologies have the following shortcomings: inaccurate semantic parsing, the multi-constraint and ambiguity of complex queries make pure neural models prone to errors in parsing, and pure symbolic methods are difficult to adapt to flexible natural language expressions; inefficient multi-hop reasoning, the multi-hop path retrieval of pure neural models lacks logical constraints, and pure symbolic reasoning faces the combinatorial explosion problem; poor result reliability, the lack of an effective result verification mechanism, and the query results may have logical contradictions or fail to meet the constraints. Summary of the Invention

[0005] To address the shortcomings of existing technologies, the purpose of this application is to provide a complex query method for knowledge bases based on neural symbolic augmentation. By combining neural models with symbolic reasoning, this method solves problems such as semantic ambiguity, inefficiency of multi-hop reasoning, and low accuracy of results in complex queries, thereby improving the accuracy and efficiency of complex queries.

[0006] To achieve the above objectives, this application provides the following technical solution: A complex query method for knowledge bases based on neural symbol enhancement includes the following steps: A neural symbolic hybrid knowledge base is constructed, which includes a structured knowledge graph, an unstructured text corpus, and a weakly supervised mapping relationship between the text corpus and entities and relations in the knowledge graph; The system receives query text and performs semantic parsing, converting it into a structured query graph with a directed graph structure. This includes: extracting core entities as entity nodes, each entity node containing a unique entity identifier, entity type, and entity content; extracting constraints as constraint nodes, each constraint node containing a unique constraint identifier, constraint type, and constraint content; and extracting the relationships between entities and the correspondence between entities and constraints as edges, with the direction of the edges conforming to the logical flow of the relationships. Retrieve multi-hop reasoning candidate paths similar to the structured query graph vector from the neural symbol hybrid knowledge base, and filter the candidate paths using preset symbol rules to obtain effective reasoning paths; Extract the entity relationship information and text corpus examples corresponding to the effective reasoning path, convert them into prompt text describing natural language, combine the prompt text with the query text to form an optimized input, and feed it into a pre-trained language model to generate and output the query results.

[0007] Preferably, constructing a neural symbolic hybrid knowledge base includes: Acquire a domain-related structured knowledge graph and an unstructured text corpus, wherein the structured knowledge graph includes entities, relations, and ontology constraints; Each piece of text in the corpus is segmented, tagged with parts of speech, and labeled with semantic roles to select nouns and verbs as core vocabulary. Semantic alignment results are obtained by mapping core words to entities and relationships in the knowledge graph through semantic graph mapping; Based on the semantic alignment results, a mapping index between text corpus and knowledge graph entity relation pairs is established through weak supervision to form a hybrid knowledge base, in which the text corpus serves as the index key and the corresponding entity relation subgraph serves as the index value.

[0008] Preferably, the semantic parsing includes: semantically encoding the query text, identifying the core entities, relational keywords, and constraints in the query, the constraints including time constraints, location constraints, and attribute constraints; disambiguating the identified ambiguous entities and polysemous relations based on the ontology constraint rules of the knowledge graph, determining the unique identifier of the entity and the relation type, and converting the disambiguated entities, relations, and constraints into a structured query graph with a directed graph structure.

[0009] Preferably, the steps for retrieving and filtering valid reasoning paths include: An embedding model based on contrastive learning optimization is used to retrieve multi-hop paths from the knowledge graph that are similar to the vectors of the structured query graph as candidate paths; Candidate paths are filtered based on preset symbol rules to eliminate invalid paths. The symbol rules include path length constraints, relation type consistency constraints, and ontology level legality constraints. The selected valid paths are weighted and merged to form an optimal inference path set. The weighting is based on path matching degree and entity relevance.

[0010] Preferably, the training process of the embedding model includes: constructing positive and negative sample pairs, where positive samples are multi-hop paths in the knowledge graph that conform to ontology logic, and negative samples are invalid paths; optimizing model parameters by comparing loss functions to improve the discriminative power of path vector representations.

[0011] Preferably, in the symbol rules, the path length constraint is that the number of relations in the path does not exceed 5 hops, the relation type consistency constraint is that the proportion of the number of relations in the candidate path that are consistent with the core relations of the query graph is not less than 70% of the total number of core relations of the query graph, and the ontology level legality constraint is that the path shall not contain a subclass entity as the superior node of the parent entity, and shall not contain the mutually exclusive entity type combination preset by the knowledge graph ontology library.

[0012] Preferably, after the query results are generated, a consistency check is performed on the query results, and the results are output only after the check passes. The consistency check includes verifying that the entity types in the query results are consistent with the type constraints of the structured query graph, that the relationships between entities conform to the ontology logic of the knowledge graph, and that the results satisfy the constraints in the query text.

[0013] Preferably, when mapping core words to knowledge graph entities and relations, the training parameters of the Word2Vec model are: window size 5, vector dimension 300, minimum word frequency ≥ 5, and number of iterations 10 rounds.

[0014] Preferably, the training data of the Word2Vec model consists of a domain text corpus and knowledge graph labeled text in a ratio of 7:3.

[0015] Preferably, the domain relation keyword dictionary used for relation keyword identification contains no less than 100 core relation keywords and synonyms.

[0016] Compared with the prior art, this application has the following advantages: First, this application utilizes a collaborative mechanism of neural model encoding recognition and symbolic rule disambiguation. This leverages the neural model's flexible understanding of natural language while using symbolic rules to resolve semantic ambiguity, significantly improving the accuracy of identifying core entities, relationships, and constraints. Furthermore, it employs a multi-level reasoning mechanism involving neural model retrieval of candidate paths, symbolic rule filtering, and weight fusion. The neural model quickly narrows the search scope, symbolic rules eliminate invalid paths, and weight fusion selects the optimal path, avoiding path drift and combinatorial explosion problems, thus balancing reasoning efficiency and reliability.

[0017] Secondly, this application enables deep knowledge integration, constructing a hybrid neural symbol knowledge base. It establishes an index linking structured knowledge and unstructured text using WordNet semantic graphs, allowing simultaneous access to both types of knowledge during queries. Knowledge complementarity is achieved through prompt text, addressing the issue of insufficient knowledge integration in existing technologies. Furthermore, a consistency verification mechanism is added, comprehensively validating the generated results from three dimensions: entity type, relational logic, and constraints. This effectively avoids logical contradictions and constraint violations, thereby enhancing the credibility of the query results. Attached Figure Description

[0018] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings: Figure 1 This is an exemplary flowchart of a complex query method for a knowledge base based on neural symbolic enhancement, as described in this application. Detailed Implementation

[0019] To enable those skilled in the art to better understand this application, the technical solutions of this application will be clearly and completely described below in conjunction with embodiments. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.

[0020] The following detailed explanation of specific implementation methods further illustrates this application: See Figure 1 A complex query method for knowledge bases based on neural symbolic enhancement includes the following steps: S1) Construct a hybrid neural symbol knowledge base, which includes a structured knowledge graph, an unstructured text corpus, and a weakly supervised mapping relationship between the text corpus and the entities and relations of the knowledge graph.

[0021] In practical implementation, the structured knowledge graph is stored in a graph database, preferably Neo4j 5.0 or later. Entities must include core fields such as unique identifier, name, and type. The unique identifier should be in UUIDv4 format, the name should be a string with a length not exceeding 100 characters, and the type should be a string conforming to the domain ontology definition. Relationships must include relation type, start and end entity identifiers, and confidence fields. The relation type should be a string with a length not exceeding 50 characters, the start and end entity identifiers should be in UUID format, and the confidence score should be a floating-point number with a value between 0 and 1. Ontology constraints are stored in triples, in the format <subject entity type, constraint relation, object entity type>. Unstructured text corpora must undergo standardized preprocessing, including deduplication, denoising, and unified encoding. Deduplication is based on the text's MD5 value, denoising removes text containing more than 30% special characters, and unified encoding is UTF-8. The corpus length is controlled within the range of 50 to 5000 characters. Weakly supervised mapping is achieved through semantic similarity calculation. A Word2Vec model is used to train core vocabulary vectors and knowledge graph entity relation vectors, with a model window size of 5 and a vector dimension of 300. A similarity threshold of 0.8 is set; when the cosine similarity between core vocabulary and entity relations reaches or exceeds 0.8, a mapping relationship is established without manual annotation.

[0022] S2) Receive the query text and perform semantic parsing, converting it into a structured query graph with a directed graph structure, including: extracting core entities as entity nodes, each entity node containing a unique entity identifier, entity type, and entity content; extracting constraints as constraint nodes, each constraint node containing a unique constraint identifier, constraint type, and constraint content; extracting the relationships between entities and the correspondence between entities and constraints as edges, with the direction of the edges conforming to the logical flow of the relationships.

[0023] In practice, the input query text undergoes preprocessing, including removing leading and trailing whitespace, standardizing capitalization for English queries, and removing meaningless special characters (such as @, #, $, and other non-text symbols). Semantic encoding uses a pre-trained language model, such as the BERT-base model with 12 layers and 768 hidden layers. It is fine-tuned using domain-specific labeled data (≥3000 labeled samples covering multi-hop, multi-constraint, and semantically ambiguous scenarios) with the following parameters: learning rate 2e-5, batch size 32, and 8 training epochs. Query intent is identified through the combination pattern of core entities and relationships. A pre-defined intent template library is used, such as "[Entity A]-[Relationship]-[Entity B]" corresponding to the intent "Query the relationship between entity A and entity B". The intent is determined by a combination of template matching and semantic similarity (threshold 0.75). The structured query graph is stored in JSON format. Node fields include "node_id" (string type, formatted as "type prefix_auto-incrementing sequence number", e.g., entity node is "E_001", constraint node is "C_001"), "node_type" (entity or constraint), "content" (node ​​content string), and "data_type" (node ​​data type, e.g., entity type, constraint type). Edge fields include "edge_id" (UUIDv4 format), "start_node_id" (starting node ID), "end_node_id" (ending node ID), and "relation_type" (relation type string).

[0024] The construction of a directed graph follows the principle of prioritizing entity nodes and associating constraint nodes. First, the disambiguated core entities are added to the graph as entity nodes, then the constraints are added as constraint nodes, and finally, edges connect entity nodes with each other and with constraint nodes. First, the core entities obtained after semantic parsing and disambiguation are converted into entity nodes one by one. The unique identifier of each entity node directly uses the UUID of that entity in the knowledge graph. The entity type is the type determined after disambiguation (e.g., "university," "enterprise," "product," etc., strictly matching the knowledge graph ontology definition). The entity content is the standard name or core descriptive information of the entity (e.g., when the entity is "Zhejiang University," the content is "Zhejiang University"; when the entity is "Huawei Mate60," the content is "Huawei Mate60 smartphone"). Second, constraint nodes are created, extracting the time, location, and attributes identified in the query text. Constraints are defined by generating corresponding constraint nodes. The unique identifier for each constraint uses the format "constraint type_auto-incrementing sequence number" (e.g., time constraint "TIME_001", attribute constraint "ATTR_001"). The constraint type is explicitly labeled as time constraint, location constraint, or attribute constraint. The constraint content is standardized constraint information (e.g., the time constraint "2023" is standardized to "2023-01-01 to 2023-12-31", and the attribute constraint "registered capital exceeding 10 million" is standardized to "registered capital > 10 million"). The third step involves constructing edge connections, first establishing the associated edges between entities: [The text abruptly ends here, likely due to an incomplete sentence or missing information.] After disambiguation, the relationships between entities are defined, with each relationship corresponding to an edge. The relationship type of the edge is the determined relation keyword (e.g., "cooperation," "belongs to," "research and development"). The direction of the edge strictly follows the logical flow of the relationship (e.g., the direction of the edge corresponding to "Zhejiang University cooperates with Huawei" is "Zhejiang University (entity node) → Huawei (entity node)", and the direction of the edge corresponding to "Huawei Mate60 belongs to Huawei" is "Huawei Mate60 (entity node) → Huawei (entity node)"). Then, the corresponding edges between entities and constraints are established: it is determined which entity belongs to each constraint (i.e., which entity needs to satisfy the constraint), with each constraint corresponding to an edge. The direction of the edges is fixed from the entity node to the constraint node (e.g., in "2023 Zhejiang University and Huawei Cooperation", the corresponding edges for the time constraint "2023" are "Zhejiang University (entity node) → 2023 (constraint node)" and "Huawei (entity node) → 2023 (constraint node)"); the fourth step is graph structure verification, which checks whether all core entities, relationships and constraints have been converted into nodes and edges, whether there are any isolated nodes (nodes that are not connected to any edges), whether the direction of the edges is consistent with the relationship logic, and whether the correspondence between entity nodes and constraint nodes is complete. After the verification is passed, a complete structured query graph is formed.

[0025] It should be noted that meaningless special characters mainly refer to characters that are not letters, numbers, Chinese characters, or Chinese punctuation marks, and whose frequency of occurrence in the domain text is ≥0.01%. The list of common meaningless characters can be adjusted through the configuration file, and characters in this list can be directly removed during preprocessing.

[0026] S3) Retrieve multi-hop reasoning candidate paths similar to structured query graph vectors from the neural symbol hybrid knowledge base, and filter the candidate paths through preset symbol rules to obtain effective reasoning paths; In practice, the retrieval process calls the index query interface of the hybrid knowledge base, employing a batch vector calculation method to process 100 path vectors at a time to improve efficiency. The vector mapping of the structured query graph is implemented through an embedding model, which weights and sums the node and edge vectors of the query graph (node ​​weight 0.6, edge weight 0.4) to obtain the overall vector. The number of candidate paths retrieved is set to the Top-10 to ensure sufficient coverage of potentially effective paths while controlling computational load. The screening process follows a rule-based filtering followed by weight sorting: invalid paths are first eliminated using symbolic rules, then the weights of the effective paths are calculated and sorted. The size of the optimal inference path set is fixed at the Top-3 to balance result coverage and computational efficiency.

[0027] S4) Extract entity relationship information and text corpus examples corresponding to effective reasoning paths, convert them into prompt texts in natural language description, combine the prompt texts with the query texts to form optimized inputs and feed them into the pre-trained language model to generate and output query results; In practice, the pre-trained language model can be an open-source model such as LLaMA-7B or ChatGLM-6B. The generation parameters are set as follows: maximum generation length of 512 characters, temperature coefficient of 0.7 (balancing randomness and accuracy), and Top-P value of 0.9 (controlling the diversity of generated vocabulary). Relevant knowledge extraction uses a depth-first search (DFS) approach to traverse each path in the optimal inference path set, extracting entity information, relation information, and associated text corpora one by one to ensure no key knowledge is missed. The prompt text uses a fixed structure of core knowledge plus supplementary explanation: the core knowledge part describes the association between entities and relations in short sentences, such as "Entity A is associated with entity B through relation R," and the supplementary explanation part selects text fragments most relevant to the query intent, with a length ≤100 characters. The total length of the prompt text should be controlled within 200 characters to avoid exceeding the input length limit of the pre-trained language model. The optimized input concatenation order is fixed as "query text + [SEP] prompt text" to ensure the model prioritizes capturing the core query intent.

[0028] It should be noted that [SEP] is the default delimiter for pre-trained models (such as BERT's [SEP] token, LLaMA's [SEP] token). <s> and< / s>(token), when adapting to different models, directly call the built-in separator of the corresponding API; the similarity calculation object of the text corpus examples is the semantic similarity between the core entity of the path and the core entity of the corpus, to ensure that the examples are directly related to the query intent. The entity relationship sentence template standard for prompt text conversion is: when multiple entities and multiple relations are combined, the chain expression of "entity A-relation R1-entity B-relation R2-entity C" is adopted (such as "Zhejiang University-cooperation-Huawei-R&D-new energy project"), and the constraint conditions are attached to the corresponding entity (such as "Zhejiang University (2023)-cooperation-Huawei (2023)"); the selection priority rules of text corpus examples are: the first priority is the corpus with a semantic similarity of ≥0.8 with the query intent, the second priority is the short text corpus with a length of ≤80 characters, and the third priority is the corpus with an association frequency of ≥100 times in the knowledge graph. The corpus is selected in order of priority, and backward compatibility is used when insufficient.

[0029] In some embodiments, after the query results are generated, a consistency check is performed on the query results. The results are output only after the check passes. The consistency check includes verifying that the entity types in the query results are consistent with the type constraints of the structured query graph, that the relationships between entities conform to the ontology logic of the knowledge graph, and that the results meet the constraints in the query text.

[0030] In practice, consistency verification employs a three-dimensional, rule-by-rule verification and total score determination mechanism: entity type consistency (1 point), relational logic validity (1 point), and constraint satisfaction (1 point). A total score of ≥2 points indicates successful verification. Entity type consistency verification checks whether the entity type in the query graph matches the constraint type in the query graph by querying the knowledge graph entity type library. Relational logic validity verification checks whether the relationships between entities conform to preset logic, such as transitive or mutually exclusive relationships, by querying the ontology constraint library. Constraint satisfaction verification uses corresponding methods for different constraint types: time constraints are parsed and compared using date formats, numerical attribute constraints are parsed and compared using numerical values, and location constraints are matched using geocoding. The final query result output format includes three core fields: result content (natural language description or structured list), verification score (0-3 points), and confidence level (calculated based on model output probability, ranging from [0,1]). The entity type consistency verification process is as follows: extract the type constraints of all entity nodes in the query graph, traverse each entity in the result, query the knowledge graph entity type library to obtain its entity type, and compare it with the constraint type. If all are consistent, 1 point is awarded; otherwise, 0 points are awarded. Relational Logic Validation Process: Extract all relationships between entities in the results, query the knowledge graph ontology constraint library, and verify whether the relationships conform to the preset logic, such as the transitive relationship "A belongs to B, B belongs to C, then A belongs to C" and the mutually exclusive relationship "A and B are mutually exclusive, then the results cannot contain the association of A and B simultaneously". 1 point is awarded if all relationships conform to the logic; otherwise, 0 points are awarded. Constraint Satisfaction Validation Process: Extract all constraints from the query text and verify them one by one by type (Time constraint: compare the time information in the parsed results with the query constraint time; if they match, it passes; Location constraint: match the location information in the parsed results with the query constraint location using geocoding; if a match is successful, it passes; Attribute constraint: compare the attribute information in the parsed results with the query constraint attributes; if they match, it passes). 1 point is awarded if all constraints are satisfied; otherwise, 0 points are awarded. The scores of the three validations are summed; a total score ≥ 2 points is considered passing; otherwise, it is considered failing.

[0031] In some embodiments, constructing the neural symbolic hybrid knowledge base in step S1 includes: S101) Obtain domain-related structured knowledge graphs and unstructured text corpora. The structured knowledge graphs include entities, relations, and ontology constraints. S102) Perform word segmentation, part-of-speech tagging, and semantic role tagging on each piece of text in the corpus, and select nouns and verbs as core vocabulary; S103) Obtain semantic alignment results by mapping core words to entities and relations in the knowledge graph through semantic graph mapping; S104) Based on the semantic alignment results, a mapping index between text corpus and knowledge graph entity relation pairs is established through weak supervision to form a hybrid knowledge base, in which the text corpus serves as the index key and the corresponding entity relation subgraph serves as the index value.

[0032] In specific implementation, the acquisition channels for structured knowledge graphs in step S101 include public knowledge bases, industry standard databases, and enterprise internal knowledge bases. Public knowledge bases include Freebase, DBpedia, and CN-DBpedia. Data in industry standard databases needs to be converted from CSV / JSON format to graph database import format. Enterprise internal knowledge bases need to undergo anonymization processing to remove sensitive information. The acquisition channels for unstructured text corpora include: public corpora (such as academic paper corpora and news corpora), web crawling (using the Scrapy framework, adhering to the robots.txt protocol, and crawling text relevant to the target domain), and user-uploaded corpora (which require legality verification). The acquired structured knowledge graphs need to undergo integrity verification; entity coverage ≥90% and relationship coverage ≥85% are required for use. The domain relevance of unstructured text corpora needs to be verified through keyword matching (the domain core keyword library contains ≥50 core terms), and corpora with a relevance ≥80% are retained.

[0033] Step S102 uses Stanford NLP version 4.5.0 or later for annotation. Word segmentation employs a statistical-based algorithm, optimized using jieba segmentation for Chinese scenarios. Part-of-speech tagging follows the PennTreebank standard, and semantic role annotation identifies core semantic roles such as agent, patient, and instrument. The core vocabulary selection rule is to directly retain words whose part-of-speech tagging results are nouns (NN, NNS, etc.) and verbs (VB, VBD, etc.), while removing non-core words such as prepositions (IN), pronouns (PRP), quantifiers (M), and auxiliary words (UD), ensuring that the semantic density of core words is ≥0.8 (the proportion of core words to the total vocabulary).

[0034] In step S103, the semantic graph uses WordNet version 3.0. For Chinese scenarios, it is combined with the ChineseWordNet extension. The semantic similarity calculation between core words and knowledge graph entities or relations uses the cosine similarity formula: in, For core vocabulary vectors, These are entity or relation vectors, all generated through a Word2Vec model (training corpus consists of domain text corpora with knowledge graph-tagged text). A similarity threshold of 0.8 is set. When the similarity is ≥0.8, the alignment is considered successful, and the entity or relation ID is recorded. When the similarity between the core term and multiple entities or relations is ≥0.8, the entity or relation with the highest similarity is selected as the alignment result. When the similarity is less than 0.8, the core word is discarded and no alignment relationship is established. The semantic alignment similarity threshold of 0.8 is set based on domain experimental data. Through testing three thresholds of 0.7, 0.8, and 0.9, 0.8 shows that semantic alignment has the highest recall and precision, balancing coverage and accuracy. If the domain data is sparse (corpus size < 100,000 entries), it can be lowered to 0.7; if the data is dense (corpus size > 1 million entries), it can be raised to 0.9. The ratio of domain text corpus to knowledge graph labeled text in the training corpus is 7:3. The knowledge graph labeled text includes entity names, short relation description sentences (such as "Enterprise A - Relation R - Entity B"), and natural language descriptions of ontology constraint triples (such as "University type entities can have cooperative relationships with enterprise type entities").

[0035] In step S104, the mapping index is preferably stored in Redis 7.0 or later. The index key is the SHA-256 hash value of the text corpus to ensure uniqueness, and the index value is the JSON serialized string of the entity relationship subgraph. The entity relationship subgraph must contain a complete knowledge chain: all aligned entities, associated relationships, and relevant ontology constraints. The number of entities in the subgraph should be ≤20, and the number of relationships should be ≤30 to ensure the compactness and completeness of the subgraph. After the index is established, sampling verification is required. 1000 index records are randomly selected to verify the accuracy of the correspondence between the index key and the index value. A hit rate of ≥95% is considered a valid index. The hybrid knowledge base adopts a hybrid storage architecture of graph database, cache database, and file storage: the structured knowledge graph is stored in the graph database, the mapping index is stored in the Redis cache database, and the unstructured text corpus is stored in a distributed file system (such as HDFS). The labels for weakly supervised mapping are automatically annotated based on knowledge graph ontology constraints (e.g., entities of type "university" are only associated with preset relationships such as "cooperation" and "belong to"), requiring no manual annotation. The association threshold of the mapping index can be dynamically adjusted, decreasing to 0.7 in sparse domain data scenarios and increasing to 0.9 in data-intensive scenarios. The threshold adjustment needs to be determined based on the domain data distribution characteristics. When the index is updated, only the mapping relationships of newly added text corpora are recalculated, without overwriting the original index. The calculation process for the mapping relationships of newly added text corpora is consistent with the initial construction. The confidence calculation logic for weakly supervised mapping relationships is as follows: confidence = semantic similarity between core words and entities / relationships × 0.8 + text pattern matching score × 0.2. The text pattern matching score is determined as complete match (1 point), partial match (0.5 points), and no match (0 points). Only mapping relationships with a confidence ≥ 0.7 will be stored in the index, and mapping relationships below this threshold will be filtered out.

[0036] It should be noted that the specific logic for converting ontology constraints into annotation rules is as follows: Text pattern matching rules are generated based on the ontology constraint <entity type A, relation R, entity type B>, such as "[entity A (type A)] + [relation keywords (synonyms of R)] + [entity B (type B)]". For example, the ontology constraint <university, cooperation, enterprise> corresponds to the sentence template "XX university cooperates with XX enterprise" or "XX enterprise cooperates with XX university". The relation keywords are taken from the WordNet thesaurus. The initial seed sample for weak supervision selects ≥500 manually annotated core scene corpora (covering major entity types and relation combinations). The number of iterations for training is 3-5 rounds, and the convergence condition is that the mapping index hit rate is ≥95% for two consecutive rounds.

[0037] It should be noted that the initial seed sample selection rules for weakly supervised mapping are as follows: samples are selected from the core scenario corpus of the domain, covering ≥8 core entity types (such as "university", "enterprise", "product", etc.) and ≥10 core relation types (such as "cooperation", "research and development", "belong to", etc.), with each entity-relation combination corresponding to ≥50 corpora to ensure a balanced sample distribution; the iterative training and update mechanism is as follows: after each round of training, mapping relations with a confidence score ≥0.9 are automatically selected as new seed samples, and the proportion of new samples in this round of training samples does not exceed 30%, and iteration stops when the mapping index hit rate is ≥95% for two consecutive rounds; the text pattern matching score refinement standard is as follows: complete match means that the core words and the text expression of the entity or relation are completely consistent (including synonym substitution, such as "collaboration" is equivalent to "cooperation"), which scores 1 point; partial match means that the core words contain the key features of the entity or relation (such as "joint research and development" contains the "research and development" relation), which scores 0.5 points; no match means that the core words and the entity or relation have no semantic relationship, which scores 0 points.

[0038] In some embodiments, the semantic parsing in step S2 includes: S201) Semantically encode the query text to identify the core entities, relational keywords and constraints in the query, including time constraints, location constraints and attribute constraints. S202) Based on ontology constraint rules of knowledge graph, disambiguation is performed on the identified ambiguous entities and polysemous relations, the unique identifier of the entity and the relation type are determined, and the disambiguated entities, relations and constraints are converted into a structured query graph with a directed graph structure. In specific implementation, named entity recognition (NER) technology is adopted for core entity recognition in step S201, which is implemented based on the fine-tuned BERT model and supports the recognition of common entity types in fields such as person names, place names, organization names, product names, etc. Relationship keyword recognition adopts a method combining keyword dictionary matching and semantic similarity verification: by constructing a domain relationship keyword dictionary, which needs to contain ≥100 core relationship keywords and synonyms, initially identify through dictionary matching, and then verify the effectiveness of the matching results through semantic similarity (threshold 0.7). Constraint condition recognition adopts corresponding methods for different types: time constraints are matched through regular expressions, supporting formats such as "YYYY-MM-DD", "YYYY年MM月DD日", "近X年 / 月 / 日", and the regular expression is "\d{4}[-年]\d{1,2}[-月]?\d{1,2}日?|近\d+[年日月]"; place constraints are matched through a geographical coding dictionary (including the names of provinces, cities, districts and main places in the country); attribute constraints are recognized through the pattern of attribute words plus numerical values or categories, such as "registered capital exceeding 10 million" and "industry is new energy", and the attribute word dictionary contains ≥80 common attribute terms. The parsing rules for different types of attributes are as follows: enumeration type attributes (such as "industry type", "product category") adopt "exact match + synonym equivalence" determination (such as "new energy" is equivalent to "new type of energy"), and the synonym library is shared with the domain relationship keyword dictionary; the comparison standard for numerical type attributes is: the boundary values include the critical values corresponding to "≥" and "≤" (such as "registered capital exceeding 10 million" includes 10 million yuan), and the unit conversion rule is: prioritize the unit in the query text, if the unit in the result is different, automatically convert it to a unified unit for comparison (such as "100 million yuan" is converted to "10000 million yuan"), and when there is no clear unit, it is processed according to the default unit in the domain (such as the default unit for amount is "10000 yuan").

[0039] Step S202, the disambiguation of ambiguous entities, employs a dual mechanism of ontology type matching and contextual semantic verification. First, candidate entities compatible with the entity types in the query context are selected based on ontology constraint rules. For example, if the query context includes "R&D," candidate entities corresponding to entity types related to R&D activities, such as "enterprise" and "university," are selected. Then, the semantic similarity between the candidate entities and the query context is calculated (threshold 0.75), and the entity with the highest similarity is selected as the final result, determining a unique entity identifier (UUID). Ambiguous relation disambiguation is achieved through "relationship-enterprise type compatibility verification": a pre-set relationship-enterprise type compatibility library is used, such as matching the "cooperation" relationship with entity type combinations like "enterprise-enterprise" and "university-enterprise." The compatibility between ambiguous relations and entity type combinations in the query is verified, and the relationship type with the highest compatibility (≥0.8) is selected as the final result. The context vector is constructed by weighted concatenation of the overall query text vector and the local vectors of the five words surrounding the core entity, with a weight ratio of 0.7 for the overall vector and 0.3 for the local vectors. Vector concatenation is performed element-wise. The overall query text vector is obtained by encoding the entire query text using a pre-trained language model, while the local vectors surrounding the core entity are obtained by encoding fragments of two words before and after the core entity. The preset fit score is based on domain statistics, specifically the actual frequency of entity type combinations and relationships in the knowledge graph. A frequency ≥80% earns 1 point, 50%-80% earns 0.6 points, 30%-50% earns 0.3 points, <30% earns 0.1 points, and no correlation earns 0 points. After the scores are set, they must be validated using ≥1000 domain-annotated corpora to ensure that the fit is ≥90% consistent with the human judgment results.

[0040] It should be noted that the context scope for disambiguation of ambiguous entities is defined as: the complete query clause containing the core entity (the entire query text if it is a single-sentence query, and the clause containing the core entity if it is a multi-sentence query). The maximum number of extended words before and after the core entity is 3 (to avoid contextual redundancy). The formula for calculating the fit of disambiguation of polysemous relations is "fit = Σ (preset fit score of entity type combination and relation) / total number of entity type combinations". The preset fit score is set based on the domain ontology rules (e.g., "enterprise-enterprise+cooperation" gets 1 point, "university-individual+cooperation" gets 0.2 points). A fit score ≥ 0.8 is considered a fit.

[0041] In some embodiments, step S3, retrieving and filtering valid inference paths, includes: S301) Employs an embedding model based on contrastive learning optimization to retrieve multi-hop paths from the knowledge graph that are similar to the vectors of the structured query graph as candidate paths; S302) Based on preset symbol rules, candidate paths are filtered and invalid paths are eliminated. The symbol rules include path length constraints, relation type consistency constraints, and ontology level legality constraints. S303) The selected effective paths are weighted and merged to form the optimal inference path set. The weight calculation is based on path matching degree and entity relevance.

[0042] In specific implementation, the TransE model is preferred as the base model for the embedding model in step S301. Contrastive learning is introduced for optimization, and the ratio of positive to negative samples is set to 1:3. Positive samples are multi-hop paths (2-5 hops in length) in the knowledge graph that conform to the ontology logic. Negative samples are generated in two ways (randomly shuffling the entity order of positive samples and replacing 1-2 relations in positive samples with irrelevant relations). The contrastive loss function adopts the InfoNCE loss function. The model training parameters are: batch size 32, learning rate 1e-4, 50 training rounds, and an early stopping mechanism is adopted. If the similarity calculation accuracy on the validation set does not improve for 3 consecutive rounds, training is stopped. The vector mapping process of the structured query graph is as follows: first, each node is mapped to a low-dimensional vector (dimension 256), and each edge is mapped to a low-dimensional vector (dimension 256). Then, the overall vector representation of the query graph is obtained by weighted summation (node ​​weight 0.6, edge weight 0.4). Candidate path retrieval uses an approximate nearest neighbor algorithm (such as FAISS) to retrieve the top-10 paths with the highest similarity to the query vector, and the similarity calculation uses cosine similarity.

[0043] It should be noted that irrelevant relations in contrastive learning are defined as relations with a semantic similarity of ≤0.3 to the original relation (based on WordNet semantic similarity calculation). The irrelevant relation library is constructed in two ways: one is through mutually exclusive relations in the knowledge graph ontology constraints, and the other is by randomly selecting relations from other domains that are not related to the original relation (the number of relations is twice that of the original relation library). The Word2Vec model training parameters are: minimum word frequency ≥5 (filtering low-frequency meaningless words), number of iterations = 10 rounds. For small corpora (≤50,000 entries), the minimum word frequency can be lowered to 3, and for large corpora (≥500,000 entries), it can be increased to 8. The selection criteria for negative irrelevant relations in contrastive learning are as follows: in addition to semantic similarity ≤ 0.3, they must also satisfy the constraint of mutual exclusion with the ontology to which the original relation belongs (e.g., if the original relation is "cooperation", the irrelevant relation can be "treatment", and the two ontology constraints have no intersection); the specific calculation method for the core indicator of model validation (accuracy of similarity calculation) is: accuracy = (number of effective paths retrieved / total number of retrieved paths) × 100%, and effective paths need to be initially screened through symbol rules; the relevant information of the validation set is as follows: the validation set size is ≥ 5000 paths, covering different lengths of 2-5 hops, of which positive samples account for 60% and negative samples account for 40%, and the sample source is domain data in the knowledge graph that did not participate in model training to ensure the independence of validation.

[0044] In step S302, the symbol rules are specifically defined as follows: mutually exclusive entity types are defined using a pre-defined list of mutually exclusive relationships in the knowledge graph ontology, such as <entity type = disease, mutually exclusive relationship = belong to, entity type = enterprise>. A path containing a combination of mutually exclusive types is considered invalid. The core relationship type selection criterion is a relationship with a degree ≥ 2 in the query graph (a relationship associated with 2 or more nodes), ensuring that the selected relationship represents the core intent of the query. The path length constraint is set to ≤ 5 hops (path length is defined as the number of relationships in the path). A path length ≤ 5 hops represents the experimental optimization result, determined by comparing the accuracy of paths with 1-10 hops. Paths exceeding 5 hops are directly eliminated due to overly complex reasoning logic and high computational cost. Relationship type consistency constraint: core relationship types are extracted from the query graph. A matching degree ≥ 70% for core relationship types in candidate paths is considered compliant with the constraint. The matching degree equals the percentage of the number of relationships in the candidate path that are consistent with the core relationships in the query graph out of the total number of core relationships in the query graph. Ontology hierarchy validity constraints verify whether the hierarchical relationships of all entities in the path conform to the ontology constraints of the knowledge graph. For example, a subclass entity cannot be the parent node of a parent entity, and mutually exclusive entity types cannot appear in the same path. Paths that violate ontology constraints are considered invalid paths. Candidate paths that satisfy all three rules are retained as valid paths, and paths that do not satisfy any one rule are eliminated.

[0045] It should be noted that the 70% relationship matching degree setting is based on experimental verification. Under this threshold, more than 90% of valid paths can be retained, while 85% of invalid paths are eliminated. The path length is ≤5 hops because when testing 1-10 hop paths, the inference accuracy of 5-hop paths is the highest. After 5 hops, the accuracy decreases and the computation time increases. For the medical and financial fields, the judgment standard is adjusted to ≤3 hops, which is based on the domain data density ≥1000 records / entity type and the high cost of incorrect inference results (such as medical diagnosis and financial risk control scenarios). The preset logic of the ontology mutually exclusive entity type combination is as follows: based on the classification system defined by the domain ontology, combined with the association frequency of entity types in the actual application scenario (association frequency <1% is considered mutually exclusive); the storage format adopts the triple <entity type A, mutually exclusive relationship, entity type B>, and the calling format is: when searching for candidate paths, all entity type combinations in the path are automatically extracted and matched with the preset mutually exclusive combination library. If a match is found, the path is directly determined to be invalid.

[0046] Path matching degree in step S303 ( The formula for calculating ) is: in, This represents the number of entities of the same type as the candidate path in the query graph. To query the total number of entities in the graph, This represents the number of candidate paths that match the type of relationships in the query graph. To query the total number of relations in the graph, the value range is [0,1]. Entity relevance ( The formula for calculating ) is: in, For each entity in the candidate path, To query the core entities of the graph, The cosine similarity is calculated for Word2Vec vectors, with values ​​ranging from [0,1].

[0047] Path weights ( The final calculation formula for ) is: in, The value range is [0,1]. Valid paths are sorted in descending order of weight, and the top-3 paths are selected to form the optimal inference path set. If there are fewer than 3 valid paths, all are retained. In the path weight calculation, the weight coefficients (0.6 and 0.4) were optimized through 5 sets of experiments (coefficient combinations 0.5-0.5, 0.6-0.4, 0.7-0.3, 0.8-0.2, 0.9-0.1), among which the 0.6-0.4 combination has a higher query accuracy. For domain adaptation, knowledge graph-intensive domains (such as academic queries) can be adjusted to a path matching degree of 0.7 and an entity relevance of 0.3, while text corpus-intensive domains (such as news and information queries) can be adjusted to a path matching degree of 0.5 and an entity relevance of 0.5. Adjustments need to be confirmed through domain validation set testing to achieve optimal accuracy.

[0048] Furthermore, the training process of the embedding model includes: We construct positive and negative sample pairs, where positive samples are multi-hop paths in the knowledge graph that conform to ontology logic, and negative samples are invalid paths. By comparing the loss function, we optimize the model parameters and improve the discriminative power of the path vector representation.

[0049] In practice, the selection rules for positive samples are as follows: Paths with a length of 2-5 hops are randomly selected from the knowledge graph. After passing ontology constraint verification (conforming to ontology hierarchical relationships and relational logic), they are used as positive samples, with a total number of positive samples ≥ 10,000. The selection rules for negative samples are as follows: Based on positive samples, each positive sample corresponds to 3 negative samples, generated through three methods: "randomly shuffling the entity order," "replacing one core relationship with an irrelevant relationship," and "replacing two core relationships with irrelevant relationships," ensuring that the difference between negative and positive samples is moderate (similarity ≤ 0.5). The comparison loss function (…) The InfoNCE loss function is used, and the formula is as follows: in, For query vector, For positive sample vectors, For all sample vectors, Temperature parameter (set to 0.07); During model training, the Adam optimizer was used with a batch size of 32, a learning rate of 1e-4, and 50 training epochs. The model was validated every 5 epochs, and the model parameters were saved when the accuracy on the validation set was ≥90%.

[0050] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the core ideas of this application. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.

Claims

1. A complex query method for knowledge bases based on neural symbolic augmentation, characterized in that, Includes the following steps: A neural symbolic hybrid knowledge base is constructed, which includes a structured knowledge graph, an unstructured text corpus, and a weakly supervised mapping relationship between the text corpus and entities and relations in the knowledge graph; The system receives query text and performs semantic parsing, converting it into a structured query graph with a directed graph structure. This includes: extracting core entities as entity nodes, each entity node containing a unique entity identifier, entity type, and entity content; extracting constraints as constraint nodes, each constraint node containing a unique constraint identifier, constraint type, and constraint content; and extracting the relationships between entities and the correspondence between entities and constraints as edges, with the direction of the edges conforming to the logical flow of the relationships. Retrieve multi-hop reasoning candidate paths similar to the structured query graph vector from the neural symbol hybrid knowledge base, and filter the candidate paths using preset symbol rules to obtain effective reasoning paths; Extract the entity relationship information and text corpus examples corresponding to the effective reasoning path, convert them into prompt text describing natural language, combine the prompt text with the query text to form an optimized input and feed it into a pre-trained language model to generate and output the query results.

2. The method for complex knowledge base query based on neural symbol enhancement according to claim 1, characterized in that, The construction of a neural symbolic hybrid knowledge base includes: Acquire a domain-related structured knowledge graph and an unstructured text corpus, wherein the structured knowledge graph includes entities, relations, and ontology constraints; Each piece of text in the corpus is segmented, part-of-speech tagging is performed, and semantic role tagging is performed to select nouns and verbs as core vocabulary. Semantic alignment results are obtained by mapping core words to entities and relationships in the knowledge graph through semantic graph mapping; Based on the semantic alignment results, a mapping index between text corpus and knowledge graph entity relation pairs is established through weak supervision to form a hybrid knowledge base, in which the text corpus serves as the index key and the corresponding entity relation subgraph serves as the index value.

3. The method for complex knowledge base query based on neural symbol enhancement according to claim 1, characterized in that, The semantic parsing includes: The query text is semantically encoded to identify the core entities, relational keywords, and constraints in the query, including time constraints, location constraints, and attribute constraints. Based on the ontology constraint rules of the knowledge graph, the identified ambiguous entities and polysemous relations are disambiguated to determine the unique identifier of the entity and the relation type. The disambiguated entities, relations, and constraints are then converted into a structured query graph with a directed graph structure.

4. The method for complex knowledge base query based on neural symbol enhancement according to claim 1, characterized in that, The steps for retrieving and filtering valid reasoning paths include: An embedding model based on contrastive learning optimization is used to retrieve multi-hop paths from the knowledge graph that are similar to the vectors of the structured query graph as candidate paths; Candidate paths are filtered based on preset symbol rules to eliminate invalid paths. The symbol rules include path length constraints, relation type consistency constraints, and ontology level legality constraints. The selected valid paths are weighted and merged to form an optimal inference path set. The weighting is based on path matching degree and entity relevance.

5. The method for complex knowledge base query based on neural symbol enhancement according to claim 4, characterized in that, The training process of the embedding model includes: We construct positive and negative sample pairs, where positive samples are multi-hop paths in the knowledge graph that conform to ontology logic, and negative samples are invalid paths. By comparing the loss function, we optimize the model parameters and improve the discriminative power of the path vector representation.

6. The method for complex knowledge base query based on neural symbol enhancement according to claim 4, characterized in that: In the symbol rules, the path length constraint is that the number of relations in the path does not exceed 5 hops, and the relation type consistency constraint is that the proportion of the number of relations in the candidate path that are consistent with the core relations of the query graph is not less than 70% of the total number of core relations of the query graph. The ontology hierarchy legality constraint is that the path must not contain a subclass entity as the parent entity's superior node, and it must not contain mutually exclusive entity type combinations preset by the knowledge graph ontology library.

7. The method for complex knowledge base query based on neural symbol enhancement according to claim 1, characterized in that: After the query results are generated, a consistency check is performed on the query results. The results are output only after the check passes. The consistency check includes verifying that the entity types in the query results are consistent with the type constraints of the structured query graph, that the relationships between entities conform to the ontology logic of the knowledge graph, and that the results meet the constraints in the query text.

8. The method for complex knowledge base query based on neural symbol enhancement according to claim 2, characterized in that, When mapping core words to entities and relations in a knowledge graph, the training parameters of the Word2Vec model used are: window size 5, vector dimension 300, minimum word frequency ≥ 5, and 10 iterations.

9. A complex query method for a knowledge base based on neural symbol enhancement according to claim 8, characterized in that: The training data for the Word2Vec model consists of a domain text corpus and knowledge graph labeled text, in a ratio of 7:

3.

10. A complex query method for a knowledge base based on neural symbol enhancement according to claim 3, characterized in that: The domain-specific keyword dictionary used for relation keyword identification contains no fewer than 100 core relation keywords and synonyms.