Multi-mode fusion product document and source code association retrieval method based on knowledge graph
By employing a multi-modal fusion approach, combining full-text search, vector search, and knowledge graphs, the problem of information fragmentation in product documentation and source code retrieval was solved, enabling efficient and accurate multi-dimensional information association and understanding, thereby improving R&D efficiency and user experience.
Patent Information
- Application Number
- CN202511340202.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-19
- Publication Date
- 2026-01-23
AI Technical Summary
Existing technologies lack semantic understanding in product document and source code retrieval, logical connections in vector retrieval, and natural language responses in knowledge graph retrieval, resulting in information fragmentation and impacting R&D efficiency and iteration speed.
We adopt a knowledge graph-based multi-modal fusion method, combining full-text retrieval, vector retrieval, and knowledge graph retrieval. Through preprocessing, semantic mapping, vector generation, and knowledge graph construction, we achieve multi-dimensional information fusion and association, supporting natural language query and code understanding.
It significantly improves retrieval accuracy and efficiency, reduces false positive and false negative rates, enhances system versatility and scalability, supports multi-source information retrieval across modules and projects, and reduces communication and information acquisition costs.
Smart Images

Figure CN121387967A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of software engineering and artificial intelligence, and particularly relates to a multi-mode fusion product document and source code association retrieval method based on a knowledge graph. BACKGROUND
[0002] With the continuous expansion of the scale of Internet products and the explosive growth of the associated large-scale code repository, enterprise developers and product managers often need to quickly locate the required information in the massive product documents and source codes during product development, maintenance and iteration. However, due to the differences in document and code recording methods, inconsistent naming conventions and historical burdens brought about by long-term evolution, the cost of information positioning and association understanding is rising, which seriously affects the development efficiency and product iteration speed.
[0003] The existing retrieval methods mainly include three types of full-text retrieval, vector retrieval and knowledge graph retrieval: full-text retrieval can quickly match product documents and code fragments based on keywords, but lacks understanding of the deep semantics and logical structure of the code; vector retrieval can capture semantic similarity, but has deficiencies in accurately matching code identifiers, identifying system / business module / method function calling relationships, and supporting multi-hop logical retrieval; knowledge graph retrieval can better exhibit the complex calling and dependency relationships between entities, but has limited intuitive response capability to natural language queries. In addition, there is a lack of effective association means between product documents and source codes, and the information is fragmented due to different expression methods and long-term iteration, making it difficult for developers to quickly understand the feature design or code implementation background of the historical version.
[0004] In view of the above problems, the present application provides a multi-mode fusion product document and source code association retrieval method based on a knowledge graph, which can generate a new retrieval enhancement method by combining the advantages of full-text retrieval, vector retrieval and knowledge graph retrieval, improve the semantic understanding and association reasoning capability while maintaining the retrieval efficiency, and effectively solve the deficiencies of the prior art. SUMMARY
[0005] The present application provides a multi-mode fusion product document and source code association retrieval method based on a knowledge graph to solve the problems of lack of semantic understanding in full-text retrieval, lack of logical association in vector retrieval, lack of natural language response in knowledge graph retrieval and difficulty in associating documents and codes in the prior art.
[0006] To solve the above technical problems, the present application provides the following technical scheme: a multi-mode fusion product document and source code association retrieval method based on a knowledge graph, comprising the following steps: Step S1: Full-text search index construction. The files in the source code library are preprocessed, and combined with a predefined business terminology dictionary, the code structure information is mapped with business semantics to form a standardized terminology dictionary and business semantic mapping. Step S1 also includes the following sub-steps: S1-1, Source Code Preprocessing and Index Building, preprocesses all code files in the source code repository, including removing comments, tokenizing, and building inverted and forward indexes; S1-2, Semantic Enhancement and Intelligent Mapping, based on standardized word segmentation and indexing, further integrates code structure information with predefined business terms to build a standardized business terminology dictionary and a deep business semantic mapping foundation.
[0007] Step S2: Constructing a vector retrieval index system. Based on business semantic mapping and a standardized terminology dictionary, a large model is used to perform controlled summarization of code files and product documents, extract business terms, logical intent and subject relationships, and merge them with the original code to generate embeddings, thus establishing a vector retrieval index system that supports semantic retrieval. S2-1: Utilize the large model to perform controlled induction on each code file and product document. Combined with the standardized terminology dictionary built in step S1, output structured business domain terms, code logic intent descriptions, and high-level relationships between subjects, i.e., structured induction results. S2-2, multi-path fusion vector generation, is based on the structured induction results of S2-1. It integrates multi-dimensional information into the vector generation module and uses a hierarchical granularity and multi-mode fusion strategy to generate high-dimensional embeddings. S2-3, Hierarchical Vector Index Construction: Based on the high-dimensional embedding vector generated in S2-2, an efficient vector retrieval index system is constructed, employing a hierarchical indexing strategy and a metadata separation architecture.
[0008] Step S3: Knowledge graph construction. Based on the semantics of steps S1 and S2, the code structure is parsed using an abstract syntax tree to extract entities and call relationships. Semantic enhancement and relationship normalization are performed in conjunction with a large model, and key logic is highlighted through a weighted mechanism. Finally, the entities and relationships are stored in a graph database to form a knowledge graph. Step S3 also includes the following sub-steps: S3-1, AST parsing and basic relation extraction: In the initial stage of knowledge graph construction, the source code is first parsed using AST technology to extract the structured basis of the knowledge graph and form the syntactic skeleton of the code structure. S3-2, based on the grammatical skeleton, introduces a large model combined with a standardized terminology dictionary to perform semantic enhancement and normalization on entities and relations, and expands the basic grammatical relations into business logic relations to obtain a semantic relation network; S3-3, Edge Weight Calculation and Global Differentiation: Based on the semantic relationship network, the relationship weight is calculated by comprehensively considering call frequency, co-occurrence, call chain depth, and business importance indicators, and then classified and differentiated to obtain a weighted semantic relationship network that highlights the core logic. S3-4, Graph Database Storage and Knowledge Graph Construction: Import a weighted semantic relation network into a graph database, store entities and relations in the form of nodes and edges, and form a knowledge graph.
[0009] Step S4 involves multi-mode fusion retrieval and result generation. Based on the full-text retrieval index from step S1, the vector retrieval index system from step S2, and the knowledge graph from step S3, the user query is standardized in terms of terminology. Full-text retrieval, semantic retrieval, and knowledge graph retrieval are performed in parallel. Candidate results are fused and reordered to finally generate a "product concept" that includes business entities and logical relationships.
[0010] Step S4 also includes the following sub-steps: S4-1, Query preprocessing and business terminology definition: Receive natural language queries input by users, perform word segmentation, semantic normalization and terminology unification based on the standardized terminology dictionary established in step S1, unify synonyms, abbreviations and variants into standard terms, output standardized query text, and establish mapping relationships between business entities and code snippets and document content. S4-2, Three-mode hierarchical retrieval, based on standardized query, triggers three retrieval modes in parallel: calling the full-text search index in step S1 to obtain exact matching results, calling the vector search index system in step S2 to obtain semantic similarity results, and calling the knowledge graph in step S3 to obtain subject relationship and call chain results, and finally outputting a set containing three types of candidate results; S4-3, Result Fusion and Reordering: Taking the output candidate result set as input, the system collects and removes duplicates, extracts features such as matching degree, semantic similarity, call depth, and business importance, and performs a comprehensive sorting of the results through an intelligent reordering algorithm, outputting the reordered result set. S4-4, Result Generation and Semantic Enhancement Presentation: Receive the output rearranged result set, combine it with the knowledge graph from step S3 to perform semantic completion and relationship restoration, expand the search results into "product concepts" that include business entities, logical relationships and contextual descriptions, and present them in the form of code snippets, documentation, or relationship graphs.
[0011] Compared with the prior art, the beneficial effects of the present invention are: This invention combines keyword matching, semantic similarity calculation, and entity relationship analysis to perform multi-dimensional relevance scoring on query results, improving overall relevance by approximately 25%, effectively reducing false positives and false negatives, and significantly improving retrieval accuracy.
[0012] This invention can handle complex queries that include natural language descriptions, code snippets, and call relationships. It is suitable for multi-source information retrieval across modules and projects, significantly enhancing the system's versatility and scalability.
[0013] This invention uses knowledge graphs to visualize call chains and relationship networks, helping developers and product managers to intuitively understand code structure, product documentation, and their dependencies, thereby reducing communication and information acquisition costs.
[0014] This invention combines large model generation capabilities to automatically complete tasks such as code snippet completion and documentation generation based on search results, further improving development efficiency and user experience.
[0015] This invention achieves high-quality multi-hop retrieval by leveraging the logical relationships between entities in a knowledge graph. It overcomes the limitations of traditional full-text retrieval and vector retrieval, which can only handle one hop or rely on cyclic keyword matching. It avoids problems such as insufficient logical relevance, quality degradation, and complex implementation, thereby significantly improving the accuracy and practicality of multi-hop retrieval. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. The following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained from these drawings without creative effort.
[0017] Figure 1 This is a flowchart of the method of the present invention; Figure 2 This is a schematic diagram of the overall process of the three-mode hybrid retrieval enhancement generation technology of the present invention; Figure 3 A schematic diagram of the module structure for building a full-text search index; Figure 4 Flowchart for vector retrieval index construction and embedding; Figure 5 A flowchart and example diagram for knowledge graph construction; Figure 6 This is a schematic diagram of the three-mode parallel retrieval and reordering generation module. Detailed Implementation
[0018] 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 a part of the embodiments of the present invention, not all of them. 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. Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but is merely a selection of embodiments of the present invention.
[0019] Please refer to Figures 1-6 , Figure 1 This is a flowchart of the method of the present invention. Figure 2 This is a schematic diagram of the overall process of the three-mode hybrid retrieval enhancement generation technology of the present invention. Figure 3 A schematic diagram of the module structure for building a full-text search index. Figure 4 Flowchart for vector retrieval index construction and embedding process. Figure 5 A flowchart and example diagram for building knowledge graphs. Figure 6 This is a schematic diagram of the three-mode parallel retrieval and reordering generation module, which includes the following steps: Step S1, full-text search index construction: through source code preprocessing and index construction, all code files in the source code repository are preprocessed; through semantic enhancement and intelligent mapping, the code structure information is further deeply integrated with predefined business terms.
[0020] S1-1, Source Code Preprocessing and Index Building: This involves preprocessing all code files in the source code repository, including removing comments, tokenizing, and building inverted and forward indexes. Remove comments: Remove meaningless single-line and multi-line comments, and retain tagged comments that are closely related to business logic (such as @param, @return, TODO) to ensure that key business information is not lost during retrieval.
[0021] Word segmentation rules: mainly targeting identifiers and comment content. For identifiers, camelCase and underscore splitting are used (e.g., getUserInfo → get, user, info); for comment text, natural language word segmentation algorithms are used to avoid incorrect segmentation of technical terms, while a stop word filtering mechanism (e.g., "the", "of") is combined to reduce invalid words.
[0022] Business terminology integration: A predefined business terminology dictionary is introduced during the word segmentation process to standardize the mapping of high-frequency words and specialized terms in vertical fields; for example, in the financial scenario, usrBal, account_balance, and bal are mapped to the unified term "account balance".
[0023] Index building and weighting mechanism: Inverted index and forward index are built. The inverted index uses keywords as index items and records their position, line number and context in the code file. The forward index saves source code documents and structured information to ensure that the search results can be quickly traced back. At the same time, higher weights are given to the entries mapped to the business term dictionary, so that the user query results are more in line with the business semantics.
[0024] Through the above process, the source code was cleaned and standardized, and a core index structure was built, establishing the foundation for standardized word segmentation and semantic indexing.
[0025] S1-2, Semantic Enhancement and Intelligent Mapping, based on standardized word segmentation and indexing, further integrates code structure information with predefined business terms to achieve a leap from basic vocabulary retrieval to semantic understanding retrieval, as detailed below: Function and class mapping: This feature maps function and class names in the code to a word segmentation dictionary, allowing users to search using either natural language descriptions or raw identifiers (such as function and class names) in the code. During the mapping process, a business terminology dictionary is used to unify synonyms or abbreviations, such as mapping calculateRiskScore() to business descriptions like "risk score calculation" and "credit assessment".
[0026] Annotation mapping: The natural language description in the annotation is associated with the word segmentation dictionary, so that when the user inputs "risk control logic", the function or class containing the semantics can be matched. For complex annotations, a large model is introduced to perform semantic induction, extract the core business concepts and add them to the dictionary to expand the semantic coverage of the retrieval.
[0027] Dynamic dictionary updates: By analyzing newly added code files, user query logs, and domain documents, emerging terms are identified and the dictionary is expanded based on TF-IDF. At the same time, expert manual annotation and semi-automated clustering methods are combined to ensure that the dictionary set is continuously updated as the business system evolves, maintaining the timeliness and accuracy of the retrieval system.
[0028] Through the above steps, the source code library is transformed into an intelligent retrieval system that supports business semantic understanding. An inverted index containing word position mapping and a forward index supporting fast backtracking are established, realizing unified term retrieval across languages and naming styles. At the same time, a standardized business term dictionary and a deep business semantic mapping foundation are constructed, forming a two-way mapping relationship between code symbols and business semantics, thereby realizing the intelligent retrieval capability of "user input natural language → accurate location of code implementation".
[0029] Step S2: Based on the business semantic mapping foundation and standardized terminology dictionary, the code files and product documents are summarized in a controlled manner using a large model. Limited and controllable nouns, verbs, domain terms, subject relationships and code logic intent are extracted. The summary results are then integrated with the source code text to generate embeddings and build an efficient vector retrieval index system.
[0030] S2-1, Controlled content summarization of the large model, as a prerequisite for vectorization, utilizes the large model to perform controlled summarization on each code file and product document. Combined with the standardized terminology dictionary built in step S1, it outputs structured business domain terminology, code logic intent descriptions, and high-level relationships between entities: Business domain terminology standardization: Identify and extract noun and verb terms, and combine them with the standardized terminology dictionary constructed in step S1 for standardization and synonym merging. For example, unify "payment" and "payment" to "payment". Normalize cross-language naming and abbreviation variants. Set the Top-K high-frequency terms (K≤20) for each file / function to ensure that the term summary is discriminative and sparsity, and provide a standardized semantic foundation for vector representation.
[0031] Code logic intent description generation: The core behavior and input / output constraints are summarized in concise short sentences or key points, such as "verify token → query user → write order → commit transaction → rollback strategy"; the length (≤100 characters) and the number of entries (≤10) are strictly limited, covering key control flow elements such as preconditions, postconditions and error branches, and supporting accurate semantic retrieval of code snippets with "similar intents but different implementations".
[0032] Subject Relationship Structured Extraction: High-level relationships between subjects (including business subjects, systems, classes, functions, etc.) are extracted and represented in the form of structured triples (subject-relation-object), such as "order service-call-inventory service"; relation predicates are limited to a preset set (call / dependency / write / read / validate / publish / subscribe, etc.), and each triple is accompanied by confidence and source location, which not only ensures that the relationship is searchable and comparable, but also reserves an interface for S3 knowledge graph integration.
[0033] Quality control and traceability mechanism: Sensitive information (API keys, passwords, tokens, etc.) is masked before summarization, and deduplication is performed based on Jaccard similarity after summarization; the model version, prompt word version, timestamp and code submission hash are recorded throughout the process to ensure that the summarization process is traceable and the results can be reconstructed, generating structured summarization results.
[0034] S2-2, multi-path fusion vector generation, based on the structured induction results of S2-1, fuses multi-dimensional information into the vector generation module, and uses a hierarchical granularity and multi-mode fusion strategy to generate high-dimensional embeddings: Multi-input fusion strategy: Simultaneously process source code fragments containing necessary comments and identifiers (such as function names and class names), controlled summaries of "domain terminology + logical intent + triple relations" generated by S2-1, and structural feature summaries such as function signatures and parameter / return types, to form a complete multi-dimensional semantic representation, ensuring that the vector contains both code implementation details and business semantic information.
[0035] Layered granular embedding generation: Generates file-level, class / module-level, function-level, and fragment-level vectors segmented by semantic boundaries. Each vector is bound to precise metadata (repo, branch, commit hash, path, start and end line numbers, language, timestamp, and model / dictionary version), supporting different granularity retrieval needs and precise result backtracking.
[0036] Vector fusion mode optimization: Two modes are adopted: early fusion and late fusion. Early fusion performs a weighted average of the source code vector and the semantic summary vector (e.g., using weight coefficients α and β); late fusion adopts a dual-tower recall plus fusion and rearrangement strategy; all vectors are processed by L2 normalization and cosine is used as a unified similarity measure to ensure the geometric consistency of the vector space.
[0037] Incremental updates and version management: Implement file / function-level local re-embedding for code changes, automatically downgrade or archive old vectors through hash drift detection, maintain version coupling with the S1 terminology dictionary, explicitly point to the dictionary version number in the embedding record, and ensure consistency and interpretability of cross-version retrieval.
[0038] S2-3, Hierarchical Vector Index Construction: Based on the high-dimensional embedding vectors generated in S2-2, an efficient vector retrieval index system is constructed, employing a hierarchical indexing strategy and a metadata separation architecture, as detailed below: Tiered indexing strategy: For small-scale data (≤100,000 vectors), HNSW indexes are used to achieve high recall and low latency; for medium-to-large-scale data, FaissIVF-PQ or IVF-HNSW-PQ schemes are adopted, which achieve the best balance between recall, memory usage and query latency through inverted file bucketing and product quantization techniques; key parameters are optimized through offline evaluation to achieve the target recall (Recall@10≥95%) and 99th percentile latency requirements (≤50ms).
[0039] Storage architecture and metadata management: The system adopts an architecture that separates the vector library and the metadata table. The vector library only stores the semantic representation of the embedding, while the metadata table records the precise location of the code and its mapping relationship with S1 terminology standard items and S3 relationship IDs. The system supports multi-replica deployment, multi-tenant sharding, and hot and cold data tiering to meet the requirements of high availability query, fast backtracking, and canary rollback.
[0040] Asynchronous Updates and Service Assurance: An asynchronous index building pipeline is established, triggered by code submissions, which sequentially executes content summarization → embedded calculation → index refresh. Index updates adopt an atomic switching mechanism (A / B dual index switching) to avoid online retrieval service jitter. Integrated monitoring metrics (recall rate, precision) are implemented, and index reconstruction is automatically triggered when performance metrics fall below the threshold or when there are significant changes to the business terminology dictionary.
[0041] Through the above processing, the business semantic mapping and term dictionary of S1 are transformed into high-dimensional vector embedding representations, and a vector retrieval index system supporting deep semantic understanding is constructed. This achieves a leap from "keyword matching" to "semantic similarity retrieval", supports the discovery of code snippets with "similar intent but different implementations", and the hierarchical index architecture supports sub-second retrieval of tens of millions of vectors.
[0042] Step S3 involves knowledge graph construction. Based on the business semantic mapping and standardized terminology dictionary established in Step S1, and the vector retrieval index system built in Step S2, the code structure is statically analyzed using Abstract Syntax Tree (AST) technology to extract basic entities and call relationships. Then, the entities and relationships are semantically enhanced using a large model to form descriptions that conform to the business context. Key logic is highlighted through weighted and differentiated processing of relation edges. Finally, the entities and relationships are uniformly stored in the graph database to form a queryable and reasonable knowledge graph.
[0043] S3-1, AST parsing and basic relation extraction: In the initial stage of knowledge graph construction, the source code is first parsed using AST technology to extract the structured foundation of the knowledge graph, as follows: Entity Node Identification: Based on the AST traversal mechanism, this system systematically identifies structured entity nodes in the code, such as projects, modules, files, classes, interfaces, methods / functions, variables, constants, and parameters. Each entity is assigned a unique identifier, and its precise location and contextual metadata in the code are recorded.
[0044] Basic Relationship Extraction: Extract the syntactic relationships between entities, including call relationships (function calls, method calls), dependency relationships (class inheritance, interface implementation, module import), composition relationships (classes contain methods, methods contain variables), and reference relationships (variable references, type references), forming the syntactic skeleton of the code structure.
[0045] S3-2, Large Model-Assisted Semantic Annotation: After obtaining the grammatical skeleton, a large model is introduced for semantic expansion and business-specific annotation. Entity semantic enhancement: Combining the business semantic mapping and standardized terminology dictionary in step S1, technical entities are transformed into business semantics. For example, "UserService.validateAccount()" is labeled as "User Service - Account Verification Function". Attributes such as business domain, function description, and complexity assessment are added to the entity, transforming the entity from a purely technical identifier into a semantic node that can be understood by the business.
[0046] Relational semantic upgrade: With the support of the logical intent description in step S2, the syntactic relationship is expanded into a business logic relationship. For example, "function A calls function B" is further interpreted as "order service calls payment service". Semantic attributes such as business meaning, calling purpose, and data flow are added to the relationship edge, realizing the leap from "syntactic structure" to "business semantics".
[0047] Relation type normalization: Based on the standardization of S1 terminology, relation types are uniformly classified, and relations with similar semantics are merged into standard types (such as call / dependency / composition / inheritance, etc.), avoiding semantic dispersion and ensuring the consistency and queryability of the graph.
[0048] S3-3, Edge Weight Calculation and Global Differentiation: After constructing a semantic relation network, a multi-dimensional weighting mechanism is used to differentiate the relations, highlighting the core logic. Multidimensional weight calculation: The comprehensive weight value is calculated for each relation edge by combining dimensions such as call frequency (static analysis results), PMI point mutual information (entity co-occurrence density), call chain depth (dependency complexity), and business importance (based on the term weight of step S1).
[0049] Global Differentiation Processing: A weighted hierarchical mechanism is established, with high-weight relationships marked as core business logic, medium-weight relationships used as important references, and low-weight relationships retained but with reduced display priority. This highlights the critical path during queries, reduces noise, and improves retrieval efficiency and user experience.
[0050] S3-4, Graph Database Storage and Knowledge Graph Construction: After completing relation extraction, semantic annotation, and weight calculation, the results are imported into a graph database to form a complete, queryable, and reasonable knowledge graph. Graph database storage architecture: It adopts graph databases such as Neo4j to persistently store entities and relationships in the form of nodes and edges. Nodes store the semantic attributes and metadata of entities (code location, business domain, complexity, etc.), and edges store relationship types, weight values and source information, thus building an efficient storage and query infrastructure.
[0051] Multidimensional retrieval and reasoning capabilities: Supports multidimensional retrieval using graph query languages such as Cypher, including entity lookup, relation traversal, and pattern matching. It performs dependency analysis and impact assessment through path traversal algorithms. Pattern matching enables architectural pattern recognition and code smell detection, enhancing code knowledge discovery capabilities.
[0052] Integration with the preceding system: Establish a linkage mechanism with the full-text search index in step S1 and the vector search index system in step S2. User queries can be progressively explored from keyword search → semantic search → relational reasoning, realizing code understanding from "point" to "surface" to "network".
[0053] Through the above operations, the static structure of the code is transformed into a business semantic-driven knowledge graph, realizing a leap from "code syntax analysis" to "business logic reasoning". The constructed knowledge graph covers multiple levels of entity nodes, including project level, file level, and function level, and covers multiple types of semantic relationships such as calls, dependencies, and compositions. It supports weight-based critical path identification and semantic pattern matching, and is deeply integrated with steps S1 and S2, ultimately forming a three-dimensional retrieval system of "keywords → semantics → relationships", supporting advanced code understanding functions such as dependency analysis, impact assessment, and architecture insight.
[0054] Step S4: Based on the full-text search index built in Step S1, the vector search index system built in Step S2, and the knowledge graph built in Step S3, the user input is standardized and preprocessed and mapped through a business terminology framing mechanism. Then, the query text is split into three parts: semantics, code fragments, and main body, and three search modes are called in parallel. Next, the candidate results in different modes are fused and reordered to highlight the most relevant and critical results. Finally, the knowledge graph is combined to generate a "product concept" containing business subjects and logical relationships, realizing a semantic and structured search experience.
[0055] S4-1, Query preprocessing and business terminology definition: As a unified retrieval entry point, the standardized terminology dictionary established in step S1 is first used to preprocess and semantically unify the user input. Semantic normalization: The query text is segmented, lemmatized and stopped word filtered to identify business terms, code symbols and business entities. Based on the segmentation rules and term recognition mechanism in step S1, the natural language query is transformed into standardized search terms.
[0056] Terminology unification mapping: Through a predefined business terminology dictionary, synonyms, abbreviations and variants are unified into standard terms. For example, "payment", "payment", and "payTransaction" are unified into "payment operation", avoiding retrieval omissions caused by naming differences.
[0057] Multidimensional mapping relationship establishment: Establish an abstract mapping relationship between business entity and document content and business entity and code fragment, and combine the semantic understanding of step S2 with the relationship network of step S3.
[0058] S4-2, a three-mode hierarchical retrieval system, after completing terminology standardization, divides user queries into subqueries of different dimensions and triggers three retrieval modes in parallel: Full-text search mode: For code snippets and exact matching requirements, the full-text search index in step S1 is invoked. Based on the inverted index and the forward index, relevant files, functions and line numbers are quickly located. The ranking of domain-related results is improved by combining the business term weighting mechanism to achieve efficient and accurate matching.
[0059] Vector retrieval mode: For semantic description and intent matching needs, the vector retrieval index system in step S2 is invoked. The code segment or document fragment that is semantically closest to the user is returned through embedding similarity calculation. Multi-path fusion vector representation is used to achieve code discovery that is "similar in intent but different in implementation".
[0060] Knowledge graph retrieval mode: For the needs of subject relationship and dependency analysis, the knowledge graph in step S3 is called, and the relevant entity nodes, their call chains, dependency paths and upstream and downstream relationships are returned through the graph traversal algorithm. The complete set of code and documents related to the business subject is obtained, realizing structured logical reasoning retrieval.
[0061] The three modes operate in parallel, leveraging the precise matching of full-text retrieval, the semantic expansion of vector retrieval, and the logical reasoning advantages of knowledge graph retrieval, respectively, to achieve complementary retrieval capabilities and maximize coverage.
[0062] S4-3, Result Fusion and Re-ranking: After obtaining three types of candidate results, it is necessary to uniformly collect, extract features, and intelligently rank the results. Unified collection of candidate results: The candidate results returned by the three search modes are merged, deduplicated, and a unified result pool is established. Each candidate result is accompanied by source information and an initial score.
[0063] Multidimensional feature extraction: Calculate multidimensional features for candidate results, including matching degree (BM25 / TF-IDF score), semantic similarity (embedding similarity), call depth (relationship chain level), and business importance (based on the term weight in step S1 and the relationship weight in step S3).
[0064] Intelligent reordering algorithm: It integrates feature values and uses a rule engine and a learning model to reorder the results, ensuring that the business-critical path and the most relevant results are displayed first, achieving a balance between accuracy, semantics and structure.
[0065] S4-4, Result Generation and Semantic Enhancement Presentation: Building upon ranking optimization, this section combines the knowledge graph from step S3 to generate business-friendly search results. Semantic Enhancement Display: By using knowledge graphs to complete the context, isolated code snippets are expanded into complete "product concepts" that include business entities, logical relationships, and contextual descriptions. Combined with the terminology mapping in step S1 and the semantic understanding in step S2, technical symbols are translated into business-understandable descriptions.
[0066] Diverse presentation methods: Based on user needs, multiple output formats are supported, including: a sorted list of code snippets with business semantic comments and contextual explanations; an automatically generated business logic specification showing relevant modules, call relationships and implementation logic; and a visualized relationship graph showing the entity network and dependency paths related to the query.
[0067] Interactive exploration support: Supports further exploration based on results. Users can expand relationships through knowledge graphs, discover similar codes through vector retrieval indexing systems, and accurately locate codes through full-text search indexes, achieving a progressive code understanding from "points" to "surfaces" to "networks".
[0068] Through the above steps, the full-text search index of S1, the vector search index system of S2, and the knowledge graph of S3 are integrated into an intelligent query and retrieval system, realizing a leap from "keyword search" to "semantic understanding" and then to "logical reasoning". It not only supports semantic parsing and multi-dimensional parallel retrieval of natural language queries, but also ensures semantic consistency through terminology standardization, achieves complementary retrieval capabilities through multi-mode fusion, improves result relevance through intelligent reordering, and provides a business-friendly presentation through semantic enhancement, thereby significantly improving the retrieval efficiency and usability of product documents and source code.
[0069] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations will be apparent to those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A multi-modal fusion product document and source code association retrieval method based on knowledge graph, characterized in that, Includes the following steps: Step S1: Full-text search index construction. The files in the source code library are preprocessed, and combined with a predefined business terminology dictionary, the code structure information is mapped with business semantics to form a standardized terminology dictionary and business semantic mapping. Step S2: Constructing a vector retrieval index system. Based on business semantic mapping and a standardized terminology dictionary, a large model is used to perform controlled summarization of code files and product documents, extract business terms, logical intent and subject relationships, and merge them with the original code to generate embeddings, thus establishing a vector retrieval index system that supports semantic retrieval. Step S3: Knowledge graph construction. Based on the semantics of steps S1 and S2, the code structure is parsed using an abstract syntax tree to extract entities and call relationships. Semantic enhancement and relationship normalization are performed in conjunction with a large model, and key logic is highlighted through a weighted mechanism. Finally, the entities and relationships are stored in a graph database to form a knowledge graph. Step S4 involves multi-mode fusion retrieval and result generation. Based on the full-text retrieval index of step S1, the vector retrieval index system of step S2, and the knowledge graph of step S3, the user query is standardized in terms of terminology. Full-text retrieval, semantic retrieval, and knowledge graph retrieval are performed in parallel. Candidate results are fused and reordered to finally generate product concepts that include business entities and logical relationships.
2. The multi-modal fusion product document and source code association retrieval method based on knowledge graph according to claim 1, characterized in that: Step S1 also includes the following sub-steps: S1-1, Source Code Preprocessing and Index Building: Preprocesses all code files in the source code repository, including removing comments, tokenizing, and building inverted and forward indexes; S1-2, Semantic Enhancement and Intelligent Mapping, based on standardized word segmentation and indexing, further integrates code structure information with predefined business terms to build a standardized business terminology dictionary and a deep business semantic mapping foundation.
3. The multi-modal fusion product document and source code association retrieval method based on knowledge graph according to claim 1, characterized in that: Step S2 also includes the following sub-steps: S2-1: Utilize the large model to perform controlled induction on each code file and product document. Combined with the standardized terminology dictionary built in step S1, output structured business domain terms, code logic intent descriptions, and high-level relationships between subjects, i.e., structured induction results. S2-2, multi-path fusion vector generation, is based on the structured induction results of S2-1. It integrates multi-dimensional information into the vector generation module and uses a hierarchical granularity and multi-mode fusion strategy to generate high-dimensional embeddings. S2-3, Hierarchical Vector Index Construction: Based on the high-dimensional embedding vector generated in S2-2, an efficient vector retrieval index system is constructed, employing a hierarchical indexing strategy and a metadata separation architecture.
4. The multi-modal fusion product document and source code association retrieval method based on knowledge graph according to claim 1, characterized in that: Step S3 also includes the following sub-steps: S3-1, AST parsing and basic relation extraction: In the initial stage of knowledge graph construction, the source code is first parsed using AST technology to extract the structured basis of the knowledge graph and form the syntactic skeleton of the code structure. S3-2, based on the grammatical skeleton, introduces a large model combined with a standardized terminology dictionary to perform semantic enhancement and normalization on entities and relations, and expands the basic grammatical relations into business logic relations to obtain a semantic relation network; S3-3, Edge Weight Calculation and Global Differentiation: Based on the semantic relationship network, the relationship weight is calculated by comprehensively considering call frequency, co-occurrence, call chain depth, and business importance indicators, and then classified and differentiated to obtain a weighted semantic relationship network that highlights the core logic. S3-4, Graph Database Storage and Knowledge Graph Construction: Import a weighted semantic relation network into a graph database, store entities and relations in the form of nodes and edges, and form a knowledge graph.
5. The multi-modal fusion product document and source code association retrieval method based on knowledge graph according to claim 1, characterized in that: Step S4 also includes the following sub-steps: S4-1, Query preprocessing and business terminology definition: Receive natural language query input from user, perform word segmentation, semantic normalization and terminology unification based on the standardized terminology dictionary established in step S1, unify synonyms, abbreviations and variants into standard terms, output standardized query text, and establish mapping relationship between business entities and code snippets and document content. S4-2, Three-mode hierarchical retrieval, based on standardized query, triggers three retrieval modes in parallel: calling the full-text search index in step S1 to obtain exact matching results, calling the vector search index system in step S2 to obtain semantic similarity results, and calling the knowledge graph in step S3 to obtain subject relationship and call chain results, and finally outputting a set containing three types of candidate results; S4-3, Result Fusion and Reordering: Taking the output candidate result set as input, the system collects and removes duplicates, extracts features such as matching degree, semantic similarity, call depth, and business importance, and performs a comprehensive sorting of the results through an intelligent reordering algorithm, outputting the reordered result set. S4-4, Result Generation and Semantic Enhancement Presentation: Receive the output rearranged result set, combine it with the knowledge graph from step S3 to perform semantic completion and relationship restoration, expand the search results into "product concepts" that include business entities, logical relationships and contextual descriptions, and present them in the form of code snippets, documentation, or relationship graphs.
Citation Information
Cited By
Intelligent business object searching system based on meta-metadata
CN121681576A
Intelligent Search System for Business Objects Based on Metadata
CN121681576B
Intelligent question answering method based on structured semantic index and double-layer memory enhancement
CN122019738A
An intelligent question-answering method based on structured semantic index and double-layer memory enhancement
CN122019738B
Coding structure and data coding method and system
CN122088444A