Entity disambiguation and multi-path recall-based code retrieval method and system

By employing entity disambiguation and multi-path recall methods, combined with caching and a large language model, the problems of entity ambiguity and high concurrency in existing code retrieval systems are solved, enabling efficient and accurate retrieval in programming education scenarios and improving user experience.

CN122045262APending Publication Date: 2026-05-15SHIJIAZHUANG VOCATIONAL & TECH COLLEGE OF POSTS & TELECOMM
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610159653.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-02-04
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

Existing code retrieval systems in programming education suffer from entity ambiguity and multi-source heterogeneous data, making it difficult to accurately identify user intent. This results in retrieval results that deviate from actual needs. Furthermore, traditional caching mechanisms cannot efficiently handle high-concurrency queries, affecting the system's real-time performance and scalability.

Method used

By employing entity disambiguation and multi-path recall methods, and combining query identifier caching, pre-trained language models, knowledge graphs, and vector databases, we achieve efficient concurrent retrieval, generate enhanced contextual data, and optimize response latency through intelligent caching.

Benefits of technology

It improves the accuracy and efficiency of code retrieval, resolves the problem of synonym ambiguity, takes into account both structured and unstructured information, reduces response latency in high-concurrency scenarios, and provides efficient and reliable intelligent code Q&A and knowledge retrieval services.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122045262A_ABST
    Figure CN122045262A_ABST
Patent Text Reader

Abstract

The invention relates to a code retrieval method and system based on entity disambiguation and multi-path recall. The method comprises the steps that a user query request is received, query text content is extracted, and a query identifier is generated; and searching the cache database, and directly outputting a cache response result if an effective cache exists. And when the valid cache does not exist, outputting an initial keyword set based on the query text content. And performing entity disambiguation operation on the initial keyword set to generate a disambiguation entity set. And executing multi-path concurrent retrieval based on the disambiguation entity set to obtain three paths of retrieval results, and combining the three paths of retrieval results to generate enhanced context data. And combining the enhanced context data and the query text content into a cue word, and calling a language model to generate a response text. And storing the response text associated query identifier into a cache database, and outputting a response result to the user. According to the intelligent tutoring system suitable for the programming education platform, the accuracy and response efficiency of code retrieval are improved through entity disambiguation and multi-channel concurrent retrieval technologies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of computer science and artificial intelligence, and in particular to a code retrieval method and system based on entity disambiguation and multi-path recall. Background Technology

[0002] With the deep integration of artificial intelligence technology, especially large language models, into the education field, intelligent code analysis and retrieval systems are gradually becoming core components of programming learning platforms. These systems automatically analyze student-submitted code to provide real-time error diagnosis, personalized learning suggestions, and accurate knowledge recommendations, thereby reducing teachers' tutoring burden and improving students' learning efficiency. Currently, code assistants based on large models can already understand natural language queries and generate code snippets or explanations, promoting the widespread adoption of programming education.

[0003] However, in practical deployments, existing code retrieval systems suffer from significant entity ambiguity due to the proliferation of synonyms and abbreviations in programming languages. This leads to the system's inability to accurately identify user query intent, resulting in search results that often deviate from actual needs. Furthermore, the multi-source, heterogeneous nature of code data makes it difficult for the retrieval process to simultaneously consider both structured and unstructured information, resulting in incomplete context coverage and impacting response quality. Moreover, traditional caching mechanisms lack intelligent timeliness management and cannot efficiently handle high-concurrency queries, further restricting the system's real-time performance and scalability. These limitations degrade the user experience and hinder the widespread application of code retrieval technology in educational settings. Summary of the Invention

[0004] To address the aforementioned technical issues, this application provides a code retrieval method and system based on entity disambiguation and multi-path recall.

[0005] Firstly, this application provides a code retrieval method based on entity disambiguation and multi-path recall, employing the following technical solution: A code retrieval method based on entity disambiguation and multi-path recall, the method comprising: Receive user query requests, extract query text content, and generate query identifiers; The cache database is retrieved based on the query identifier, and if a valid cache exists, the cache response result is output. If no valid cache exists, the pre-configured language model is invoked to process the query text content and output the initial keyword set; Perform entity disambiguation on the initial keyword set to generate a disambiguated entity set; Multi-path concurrent retrieval is performed based on the disambiguation entity set, including retrieving entity nodes, retrieving relation edges, and performing direct vector retrieval. The three retrieval results are obtained and merged to generate enhanced context data. The enhanced contextual data is combined with the query text content to form prompt words, and the language model is invoked to generate response text. The response text is associated with the query identifier and stored in the cache database, and the response result is output to the user.

[0006] By adopting the above technical solutions, the accuracy and efficiency of code retrieval have been improved. Entity disambiguation solves the semantic ambiguity caused by synonyms and abbreviations in the code, making the identification of query intent more accurate. A multi-path concurrent retrieval mechanism using knowledge graphs, vector databases, and code block databases takes into account both structured and unstructured information, generating comprehensive enhanced contextual data. Combined with intelligent caching and language model optimization, response latency in high-concurrency scenarios is reduced.

[0007] Secondly, this application provides a code retrieval system based on entity disambiguation and multi-path recall, employing the following technical solution: A code retrieval system based on entity disambiguation and multi-path recall, the system comprising: The query request receiving module is used to receive user query requests, extract query text content, and generate query identifiers. The cache retrieval module is used to retrieve the cache database according to the query identifier. If a valid cache exists, a first judgment result is output; if no valid cache exists, a second judgment result is output. The cache response module is used to respond to the first judgment result and output the cache response result; The keyword extraction module is used to respond to the second judgment result, call the pre-configured language model to process the query text content, and output an initial keyword set; The entity disambiguation module is used to perform entity disambiguation on the initial keyword set to generate a disambiguated entity set. The multi-path recall module is used to perform multi-path concurrent retrieval based on the disambiguation entity set, including retrieving entity nodes, retrieving relation edges, and performing direct vector retrieval, obtaining three-path retrieval results and merging them to generate enhanced context data; The response generation module is used to combine the enhanced context data with the query text content to form prompt words, and call the language model to generate response text. The response result return module is used to associate the response text with the query identifier, store it in the cache database, and output the response result to the user.

[0008] Thirdly, this application provides a computer device, which adopts the following technical solution: A computer device includes a memory, a processor, and a computer program stored in the memory, the processor executing the computer program to perform the steps of the method as described in the first aspect.

[0009] Fourthly, this application provides a computer-readable storage medium, which adopts the following technical solution: A computer-readable storage medium storing a computer program that can be loaded by a processor and executed as in any of the methods in the first aspect.

[0010] In summary, this application includes at least one of the following beneficial technical effects: By integrating a query caching mechanism, entity disambiguation technology, and a multi-path concurrent retrieval strategy, this application significantly improves the response speed and answer quality of the code retrieval system: the caching mechanism avoids redundant calculations and reduces response latency; entity disambiguation effectively solves the semantic ambiguity caused by synonyms and abbreviations in the code, improving the accuracy of query intent recognition; and multi-path concurrent retrieval based on knowledge graphs, vector databases, and code block databases combines the advantages of structured association, semantic matching, and precise code matching, generating contextual data with broader coverage and stronger relevance. Finally, the response generated by the large language model is more accurate and comprehensive, thus providing users with efficient and reliable intelligent code Q&A and knowledge retrieval services in scenarios such as programming education. Attached Figure Description

[0011] Figure 1 This is a first flowchart illustrating a code retrieval method based on entity disambiguation and multiple-path recall, according to one embodiment of this application.

[0012] Figure 2 This is a schematic diagram of the second process of a code retrieval method based on entity disambiguation and multiple-path recall, which is one embodiment of this application.

[0013] Figure 3 This is a schematic diagram of the third process of a code retrieval method based on entity disambiguation and multi-path recall, which is one embodiment of this application.

[0014] Figure 4 This is a schematic diagram of the fourth process of a code retrieval method based on entity disambiguation and multi-path recall, according to one embodiment of this application.

[0015] Figure 5 This is a schematic diagram of the fifth process of a code retrieval method based on entity disambiguation and multi-path recall, according to one embodiment of this application.

[0016] Figure 6 This is a schematic diagram of the sixth process of a code retrieval method based on entity disambiguation and multi-path recall, which is one embodiment of this application.

[0017] Figure 7This is a schematic diagram of the seventh process of a code retrieval method based on entity disambiguation and multiple-path recall, according to one embodiment of this application. Detailed Implementation

[0018] To make the purpose, technical solution, and advantages of this application clearer, the following description is provided in conjunction with the appendix. Figures 1-7 The present application will be further described in detail below with reference to embodiments. It should be understood that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the scope of the application.

[0019] Currently, in programming education practice, students often face difficulties such as low error debugging efficiency and lack of timely professional guidance when practicing code using interactive development environments like Jupyter. Existing large-scale model-assisted learning platforms typically directly apply retrieval enhancement and generation techniques like LightRAG to process code data, facing multiple challenges such as entity vector ambiguity, redundant synonymous entities, and semantic inconsistencies across text blocks. This results in low retrieval accuracy and significant resource waste, severely restricting the practical application of intelligent systems in programming education.

[0020] Based on this, this application discloses a code retrieval method based on entity disambiguation and multi-path recall, which is mainly applied to programming education platforms and aims to solve the technical problem of insufficient LightRAG retrieval optimization in existing code learning platforms.

[0021] Reference Figure 1 A code retrieval method based on entity disambiguation and multi-path recall, the specific method includes: Step S101: Receive user query request, extract query text content and generate query identifier; The core logic of this step lies in transforming the unstructured query request input by the user into a traceable, standardized data stream. When a user submits a query, the system first receives the original request through an API interface (such as a RESTful endpoint) and parses the text content. During text extraction, irrelevant characters (such as special symbols or redundant spaces) are filtered out, while core semantic information is preserved to ensure the accuracy of subsequent processing. The operation of generating query identifiers is implemented based on cryptographic hash functions (such as MD5), which works by mapping the query text content to a fixed-length unique string, thereby creating an irreversible digital fingerprint for each query. This design not only avoids redundant processing of repeated queries but also provides a key-value index foundation for cached retrieval.

[0022] For example, if a user queries "Solutions to SyntaxError in Python", the system will calculate its MD5 hash value (such as "a1b2c3d4...") as a unique identifier for the query throughout its lifecycle. The core logic of this step is to establish a one-to-one mapping between requests and identifiers, ensuring that subsequent modules can accurately trace the query context and providing efficient retrieval basis for the caching layer.

[0023] Step S102: Retrieve the cache database according to the query identifier and determine whether there is a valid cache; if yes, proceed to step S103; if no, proceed to step S104. Step S103: Output the cached response result; The system uses the query identifier as the key to perform an efficient lookup in a distributed cache database (such as Redis). If a cached response that has not expired exists, it indicates that the query has already been processed, and the system directly returns the historical result, avoiding duplicate calculations. The validity of the cache is maintained through timestamps and business rules, such as setting TTL (Time To Live) to ensure data timeliness. The professionalism of this design is reflected in two aspects: first, reducing dependence on downstream computing resources (such as LLM calls) and lowering latency; second, through hash lookups... (1) Time complexity, achieving second-level response.

[0024] For example, when the same student queries similar errors multiple times, the system can directly return the generated parsing report. If the cache is not hit, the process switches to the semantic parsing stage, forming a seamless branching logic. This entire process demonstrates the system's optimization for high-concurrency scenarios, ensuring stability through peak-shaving and valley-filling of the caching layer.

[0025] Step S104: Call the pre-configured language model to process the query text content and output the initial keyword set; The logic behind this step relies on keyword extraction techniques in Natural Language Processing (NLP). When a cache miss occurs, the system invokes a pre-trained language model (such as Claude-4) to perform deep semantic analysis on the query text. The language model uses an attention mechanism to identify entities, actions, and contextual relationships in the text, generating an initial set of keywords. For example, for the query "how to handle Java's NullPointerException", the model might extract the keywords ["Java", "NullPointerException", "handle"].

[0026] It should be noted that this process is not a simple word segmentation, but rather an enhancement by combining knowledge graphs from the code domain, such as distinguishing between the ambiguity of "Java" (programming language) and "java" (coffee brand).

[0027] Specifically, the system constructs a prompt word input sequence based on the user's query text content, calls a pre-trained language model for processing, parses the text response data generated by the language model, separates keyword entities and relation descriptors from the text response data (for example, extracting noun phrases between marker symbols as keyword entities and extracting verb phrases as relation descriptors), and finally outputs an initial keyword set. By mapping the query to a high-level semantic representation, it provides structured input for subsequent entity disambiguation and also acts as a bridge between natural language and machine-processable data, ensuring that user intent is accurately captured.

[0028] In some embodiments, this step may employ a Transformer generative model, which processes the input cue word sequence through the following process: performing word embedding layer vectorization; calculating contextual features through a 12-layer self-attention mechanism; and generating a probability distribution output text sequence through a fully connected layer.

[0029] Step S105: Perform entity disambiguation on the initial keyword set to generate a disambiguated entity set; Entity disambiguation is crucial for resolving semantic ambiguity. Its logic is based on a vector space model and clustering algorithms. The system first generates a high-dimensional semantic vector for each keyword (e.g., using an embedding model), converting textual symbols into mathematical representations. Then, hierarchical clustering algorithms (e.g., Agglomerative Clustering) group the vectors, calculating cosine similarity to group semantically similar entities into the same cluster (e.g., "SyntaxError" and "syntax error" are identified as the same). A clustering threshold (e.g., 0.9) controls the granularity of the clusters, ensuring a balance between recall and precision. Finally, a language model is invoked for deep validation. For example, a prompting process allows the LLM to determine whether "Python" and "Py" refer to the same entity, outputting a normalized set of disambiguated entities.

[0030] Step S106: Perform multi-way concurrent retrieval based on the disambiguation entity set, including retrieving entity nodes, retrieving relation edges, and performing direct vector retrieval, obtain the three-way retrieval results, merge them, and generate enhanced context data; Specifically, the purpose of this step is to build a collaborative and complementary heterogeneous information retrieval pipeline. Its core is to deconstruct and satisfy the user's query intent from the three dimensions of knowledge structure, association and semantics through parallel and different retrieval paradigms, and finally generate the optimal enhanced context through intelligent fusion strategy.

[0031] Step S107: Combine the enhanced contextual data with the query text content to form prompt words, and call the language model to generate response text; Specifically, the system combines enhanced contextual data (such as retrieved code snippets and error descriptions) with the original query to form structured prompts, for example, using the template: "Based on the following knowledge: {context}, answer the query: {query}". This design guides the language model to generate accurate and professional responses by providing external knowledge, avoiding the illusion problem.

[0032] When invoking the language model, the randomness of the output is controlled by adjusting the temperature parameter to ensure the stability of the generated response. For example, for error correction queries, the model combines similar cases in the context to generate a step-by-step solution. This step leverages the few-shot learning capability of LLM to transform the retrieval results into a natural language response, achieving a mapping from knowledge to answer.

[0033] Step S108: Store the response text associated with the query identifier in the cache database and output the response result to the user.

[0034] In this embodiment, the system binds the response text with the query identifier and stores it in a cache database, setting an expiration policy (such as dynamically adjusting the TTL based on access frequency). Serialization (such as JSON) is used during storage to ensure fast retrieval. When outputting to the user, streaming or non-streaming responses are supported, for example, real-time display via HTTP chunked transmission. This step ensures cache consistency through atomic operations and utilizes a message queue for asynchronous write processing, avoiding blocking the main thread. This not only improves subsequent query efficiency but also builds a learning feedback loop, providing data accumulation for system optimization.

[0035] In the above implementation, entity disambiguation solves the semantic ambiguity caused by synonyms and abbreviations in the code, making the identification of query intent more accurate; a multi-path concurrent retrieval mechanism using knowledge graphs, vector databases, and code block databases is adopted to take into account both structured and unstructured information and generate comprehensive enhanced contextual data; combined with intelligent caching and language model optimization, the response latency in high-concurrency scenarios is reduced, achieving more accurate and efficient code retrieval.

[0036] In practical applications, this application is applicable to intelligent tutoring systems within programming education platforms. For example, when a student encounters a code error in a Jupyter environment, the system can analyze their query (such as "how to handle SyntaxError") in real time, and generate personalized solutions by retrieving related historical error cases, similar code patterns, and concept nodes in the knowledge graph through multi-path recall. Furthermore, teachers can leverage the system's aggregated class error distribution data to provide precise teaching interventions for common problems. The practical significance of this technical solution lies in overcoming the bottlenecks of traditional code retrieval systems in terms of entity ambiguity, context coverage, and real-time performance. Through a scalable distributed architecture, it provides an automated tool for educational scenarios that supports personalized learning analysis and precise teaching guidance.

[0037] Reference Figure 2 As one implementation of step S102, the step of retrieving the cache database based on the query identifier includes: Step S201: Query the cache database using the query identifier as the retrieval key; The system uses the query identifier as the retrieval key to perform key-value matching operations in a distributed cache database (such as Redis).

[0038] In this embodiment, the cache database typically uses a hash table or B-tree index structure, making the time complexity of the query operation O(n log n). (1) Achieving millisecond-level response. During the retrieval process, the system performs an exact match between the identifier and the key in the database. If a matching key exists, subsequent validity verification is triggered; otherwise, a miss is returned directly. This step utilizes the high throughput of the cache database, avoiding the I / O latency caused by directly querying persistent storage (such as a disk database). For example, when the identifier "a1b2c3" is used as a key, the database engine will traverse the index to locate the corresponding cached record (such as serialized response data and its metadata).

[0039] Step S202: Determine whether there is a valid cache record associated with the retrieval key in the cache database; if not, proceed to step S203; if yes, proceed to step S204. Step S203: Output the result indicating that no valid cache exists; When a search operation fails to find a matching cached record, the system generates a miss status flag (such as a boolean value of false or a specific error code) and outputs the determination result. That is, when the cache is unavailable, the current process is immediately terminated, triggering the complete query processing chain. The output of the miss determination not only includes simple status signals but may also include contextual information (such as query identifiers and timestamps) for subsequent monitoring and optimization. For example, the system can record miss rate metrics and dynamically adjust the caching strategy. This step ensures the system's fault tolerance, avoids process blocking due to cache misses, and provides a basis for resource scheduling decisions.

[0040] Step S204: Calculate the difference between the expiration mark of the valid cached record and the current system timestamp, and compare it with the preset expiration threshold; When a cached record exists, the system first extracts the time stamp (such as creation time or last access timestamp) from its metadata. This stamp is usually stored in ISO 8601 format or Unix timestamp.

[0041] The system then obtains the current system timestamp and calculates the absolute difference between the two. This timestamp difference reflects the lifecycle of the cached record, and its calculation must consider time zone synchronization and clock drift correction to ensure accuracy. After calculating the difference, the system compares it with a preset time limit (e.g., 30 minutes). This preset time limit is typically dynamically configured based on business needs (e.g., a shorter threshold for code error queries and a longer threshold for syntax consultation queries).

[0042] Step S205: Determine whether the difference is greater than the preset time limit threshold; if not, proceed to step S206; if yes, proceed to step S203. Step S206: Output the result of the valid cache determination.

[0043] When the difference is less than or equal to the threshold, the system determines that the cache is valid and outputs a positive status (such as true), while triggering the cache response data reading process. This determination means that the cached record is still within its freshness period and its content is trustworthy. Conversely, if the difference exceeds the threshold, the cache is determined to be invalid, the system outputs a negative status (such as false), and may trigger cache cleanup or update operations (such as asynchronous recalculation).

[0044] Furthermore, invalidation determination not only changes the status flag but may also involve resource reclamation (such as deleting expired records) to prevent cache bloat. For example, for a query with a 30-minute threshold, if a record has been stored for 35 minutes, the system marks it as invalid and returns a miss result. This step, through a dual guarantee mechanism (existence check + timeliness verification), ensures that the cached response is both existent and valid, improving the system's reliability and consistency.

[0045] In the above embodiments, an efficient and reliable cache retrieval layer is constructed. Through the aging threshold mechanism, the timeliness and accuracy of the cached data are ensured, avoiding misresponses caused by expired information; based on the state determination logic, seamless connection between the cache layer and the processing layer is achieved, optimizing resource utilization. This method improves the cache hit rate, reduces the average response latency, provides high-performance support for the code retrieval system, and adapts to multi-scenario requirements through dynamic aging management.

[0046] Referring to Figure 3 , as an implementation of step S105, the steps of performing entity disambiguation on the initial keyword set to generate a disambiguated entity set include: Step S301, generating a semantic vector representation for each initial keyword according to the initial keyword set; Among them, the initial keyword set contains the core terms parsed from the user query, such as code error types (e.g., "SyntaxError"), programming languages (e.g., "Python"), or operation actions (e.g., "repair"). The system reads this set through a memory or cache interface to ensure the standardization of the data format (such as JSON list structure). Each keyword represents a potential semantic entity, but may be ambiguous due to differences in expression (e.g., "NullPointerException" and "null pointer exception" refer to the same concept).

[0047] Next, the system calls a pre-trained word vector model (such as Word2Vec, BERT, or a dedicated code domain model) to perform embedding calculations on each keyword. The model first performs word segmentation and sub-word processing on the input text (such as the BPE algorithm), and then generates a high-dimensional floating-point vector (commonly with a dimension of 768) through a neural network layer (such as a Transformer encoder). Each dimension of the vector represents a specific attribute of the vocabulary in the semantic space (such as syntactic role or context association). For example, the keyword "exception" may be mapped to a vector close to "error", while "Python" is far from "Java".

[0048] Step S302, clustering and grouping the semantic vector representations through a cosine similarity threshold; Among them, the system first calculates the similarity values between vectors. For example, the cosine similarity algorithm is used to evaluate the direction consistency by calculating the cosine value of the vector angle. The result range is [-1, 1], and the value closer to 1 indicates more similar semantics. For example, the cosine value of the vectors of "Exception" and "异常" may reach 0.9, while the value of "Python" and "Java" may be only 0.6.

[0049] Subsequently, the system performs clustering based on the similarity matrix, typically employing hierarchical clustering algorithms (such as Agglomerative Clustering). The logic is to merge similar vectors from the bottom up, forming a clustered structure. A clustering threshold (e.g., 0.85) dynamically controls the granularity of the clusters, ensuring that synonymous entities are grouped together (e.g., "SyntaxError", "syntax error", and "syntactic error" are clustered into one category). Clustering initially organizes scattered entities into semantically related groups, reducing the complexity of subsequent verification.

[0050] In some embodiments, when the similarity value is greater than a preset cosine similarity threshold, they are grouped into the same cluster, and this threshold can be dynamically configured according to the domain type: for example, it is set to 0.85 for the general programming domain and 0.92 for the professional framework domain.

[0051] Step S303: Perform synonym verification on the initial keywords within the cluster group and output a set of disambiguated entities containing standard entity names.

[0052] The system constructs natural language description text (such as "Please verify whether the following terms are synonyms: SyntaxError, syntax error") for keywords within each cluster group, and calls a pre-trained language model (such as Claude-4) for deep judgment.

[0053] Specifically, the model uses context-aware technology to analyze the domain usage of terms (such as specificity in programming contexts) and outputs a synonym confidence score (e.g., a range of 0-1). If the confidence score exceeds a set threshold (e.g., 0.8), entities within the cluster are considered synonymous, and a standard name is generated (e.g., unifying "SyntaxError" and "syntax error" into "SyntaxError"). This process uses cue engineering to guide the model to focus on synonym judgment, avoiding general semantic bias. Simultaneously, validation processing addresses potential misjudgments that may arise from simple clustering (e.g., the ambiguity between "Java" as a language and a coffee brand), and semantic consistency checks improve disambiguation accuracy.

[0054] Finally, the system merges the verified entity clusters into a structured collection, where each cluster corresponds to a standard entity name (e.g., represented by the most frequent or most canonical term). The collection format is typically key-value pairs (e.g., {"standard entity": ["synonym 1", "synonym 2"]}), ensuring machine readability (e.g., JSON or Protocol Buffers).

[0055] In the above embodiments, the multi-level disambiguation mechanism improves the accuracy and consistency of entity recognition in the code retrieval system, semantic vectorization maps text to a continuous space, making similarity measurement more robust, clustering grouping initially narrows the scope of ambiguity and reduces computational overhead, and language model verification introduces semantic reasoning to solve complex ambiguity scenarios, providing a reliable foundation for the personalized programming tutoring of this application.

[0056] Reference Figure 4 As one implementation of step S106, the step of performing multi-way concurrent retrieval based on the disambiguation entity set, including retrieving entity nodes, retrieving relation edges, and performing direct vector retrieval, obtaining the three-way retrieval results and merging them to generate enhanced context data, includes: Step S401: Establish an entity node recall path. Based on the disambiguation entity set, encode the query text content into a vector, perform vector retrieval and keyword matching in the preset entity index, and generate an entity node retrieval result set containing entity name, attributes and similarity score. The essence of the entity node recall path is a hybrid retrieval based on semantic vector and symbol matching. Its core principle is to align the semantic information queried by the user with the entity nodes in the knowledge graph in multiple dimensions.

[0057] In this embodiment, the query text is first transformed into a high-dimensional vector representation using an encoding model (such as BERT or Sentence-BP), capturing the deep semantic features of the query. Then, two retrieval operations are performed in parallel within the entity index: first, vector similarity calculation, which uses cosine distance or inner product to calculate the matching degree between the query vector and the entity node vector; second, keyword exact matching, which directly compares keywords in the query text with entity names, aliases, or attribute fields. For example, for the query "solutions to SyntaxError in Python", the system calculates the similarity between "SyntaxError" and the error type entity vector in the knowledge graph, and also directly matches the programming language entity associated with the keyword "Python". The final generated entity node retrieval result set includes the entity name, attribute description, and similarity score. This step balances semantic flexibility and symbolic precision, solving the semantic drift problem that may exist in pure vector retrieval.

[0058] Step S402: Establish a relation edge recall path. Based on the disambiguation entity set, extract topic words and relation words from the query text content. Perform vector retrieval and match topic tags in the preset relation edge index to generate a relation edge retrieval result set containing relation type, topic tags and path score. The core of the relation edge recall pathway is relation path discovery based on graph structure. This pathway is no longer limited to a single entity, but constructs a semantic network by analyzing the relationships between entities.

[0059] Specifically, first, topic terms (such as "inheritance" and "call") and relational terms (such as "cause" and "belong to") are extracted from the query text. These terms reflect the semantic relationship tendency of the query. Second, vector retrieval is performed in the relational edge index to match topic tags in the relation description. For example, for the query "how to handle NullPointerException", the system extracts "handle" as a relational term and searches for relational paths with semantic similarity to "handle" in the relational edge index (such as "solution method → ​​exception type"). The relational edge retrieval result set contains relation type, topic tags, and path scores. This step, by capturing complex logical relationships between entities, is particularly suitable for complex query scenarios that require the support of reasoning chains.

[0060] Step S403: Establish a vector recall path, perform vector similarity matching on the query text content based on the disambiguation entity set, retrieve the original text fragments in the vector database, and generate a set of text fragment retrieval results containing vector similarity scores and original text citations. The vector recall pathway employs an end-to-end semantic similarity matching strategy, based on the distributed hypothesis (similar contexts have similar vector representations). This pathway directly vectorizes the query text and retrieves semantically similar original text fragments from vector databases (such as FAISS or ChromaDB).

[0061] It's important to note that, unlike entity node retrieval, this method does not rely on a predefined knowledge graph structure. Instead, it discovers semantic relevance between texts in an unsupervised manner. For example, even if a user query uses non-canonical expressions (such as "what to do if the code reports a null pointer exception"), vector retrieval can still recall solution text containing "NullPointerException". The text fragment retrieval result set includes vector similarity scores and original text citations. Its technical advantage lies in its strong generalization ability, effectively handling the diversity of query expressions.

[0062] Step S404: Perform structured integration processing on the entity node retrieval result set, relation edge retrieval result set, and text fragment retrieval result set to obtain three-way retrieval results; Specifically, the structured integration stage converts heterogeneous search results into a unified intermediate representation, such as mapping entity nodes to "entity-attribute" triples and converting relation edges into "subject-relation-object" predicate logic forms.

[0063] Step S404: Establish an entity name hash set and a text content hash set as deduplication benchmarks. Based on a preset polling order, extract content that does not appear in the hash set from the three search results and add it to the enhanced context data list, and update the corresponding hash set. The preset polling order is entity node recall path → relationship edge recall path → vector recall path. Specifically, the system establishes a hash set of entity names (using MD5 or SHA-1 algorithm) and a hash set of text content as the basis for deduplication. The round-robin scheduling selects content in the order of priority: "entity node → relation edge → vector retrieval". The design of this order is based on the fact that entity nodes provide accurate structured knowledge, relation edges supplement logical paths, and vector retrieval ensures semantic coverage.

[0064] For example, when all three results contain information related to "SyntaxError", the system prioritizes the structured definition of the entity node path, then supplements the causal relationship chain in the relation path, and finally includes the instance code snippet of the vector path. This mechanism ensures the non-redundancy and diversity of the result set, avoiding a single path dominating the search results.

[0065] Step S405: Obtain the preset weight configuration coefficients, and calculate the weighted score for each item in the enhanced context data list based on the source path; The weighted merging stage employs a multi-factor weighted scoring model, mathematically based on linear weighted summation. The weighting coefficients (e.g., entity nodes 0.3, relation edges 0.4, vector retrieval 0.3) are set based on the confidence characteristics of each pathway: relation edges have the highest weight because they reflect the strength of semantic association between entities; entity nodes and vector retrieval have comparable weights, balancing structured accuracy and semantic generalization ability. The final score for each item is calculated as follows: Overall Score = Entity Node Score × +Relationship edge score× +Vector retrieval score× The scores are all normalized to the [0,1] interval.

[0066] Step S406: Sort by weighted score in descending order and select the top K items as the final enhanced context data, where k is a configurable positive integer.

[0067] Specifically, the mechanism of selecting the top K items after sorting by score in descending order implements dynamic threshold filtering. The parameter K can be adjusted according to business needs (e.g., K=10 in an educational scenario can balance information content and readability). This step, through a configurable weight system, enables the system to adapt to the precision / recall requirements of different scenarios. For example, in a teaching scenario, a smaller K value can generate concise answers, while a larger K value can provide more comprehensive learning references, thus achieving an optimal balance between precision, breadth, and practicality in the search results.

[0068] In the above implementation, at the semantic understanding level, a hybrid retrieval strategy addresses the issues of synonym ambiguity and structural diversity in the code domain; at the retrieval efficiency level, round-robin deduplication and weighted merging algorithms improve the efficiency of filtering redundant information; and at the application value level, a configurable K-value parameter allows the system to dynamically adjust information density according to the actual needs of educational scenarios (such as real-time classroom tutoring and after-school deep learning). Ultimately, this solution enables code retrieval results to possess both the accuracy of structured knowledge and the coverage of unstructured content, providing knowledge service support with both depth and breadth for programming education scenarios.

[0069] Reference Figure 5 As a further implementation of the code retrieval method, after the step of generating enhanced context data, it further includes: Step S501: Parse the code syntax structure in the enhanced context data and identify the abnormal syntax marker sequence within the code block data; The enhanced context data includes raw code block data merged from multi-way searches. This data may come directly from students' past assignments or open-source projects, and its syntactic correctness cannot be guaranteed.

[0070] In this embodiment, a lightweight parser (e.g., a parser generated based on the grammar of a specific programming language) is invoked to perform lexical and syntactic analysis on the code block data. Lexical analysis converts the code string into a series of lexical tags with categorical meaning; syntactic analysis checks whether the order of these tags conforms to the specification based on the context-free grammar of the programming language. When the parser cannot deduce the entire tag sequence according to the production rules, it interrupts and records the abnormal syntactic tag sequence that caused the parsing failure (i.e., tags that do not conform to the grammar rules and their context).

[0071] Understandably, this is equivalent to performing a quick compilation check on the retrieved "answer material," aiming to identify code snippets with obvious grammatical flaws, prevent incorrect code paradigms from being provided to users as part of the correct answer, and thus improve the input quality of subsequent repair and generation processes.

[0072] For example, if the system uses the Tree-sitter library and loads Python language grammar rules, when processing the code `if x > 5 print("Hello")`, the lexical analyzer generates the token sequence `[if, x, >, 5, print, (, "Hello",)]`. The parser expects to see a colon `:` after the conditional expression `x > 5` to begin a new block of statements, but instead encounters the identifier `print`, which violates the grammar rules of the `if` statement. Therefore, the parser throws a syntax error and records the exception token sequence as `[5,print]`, indicating that a necessary colon is missing.

[0073] Step S502: Detect the matching degree of the abnormal syntax marker sequence in the preset error classification model, and output the syntax error type code; The pre-defined error classification model encapsulates common syntax error patterns learned from a large amount of historical code error data, such as "missing colons," "mismatched parentheses," "incorrect indentation," and "incorrect keyword usage." This model extracts features and calculates matching degrees from the input anomaly marker sequence, mapping it to one or more of the closest predefined error categories. The final output syntax error type code is a standardized classification identifier. This step transforms fragmented, specific parsing errors into discrete error types that the system can process in a structured manner.

[0074] In some embodiments, the preset error classification model can be a machine learning-based classifier (such as SVM or a simple neural network). For the abnormal sequence [5, print] identified in the previous step, after extracting features, the model finds that the pattern highly matches the historical error pattern of "other statements following the conditional expression of control flow statements (such as if, for, while) directly". The error type encoding corresponding to this pattern is ERR_MISSING_COLON_AFTER_CONDITION. The model outputs this encoding, thereby converting the specific parsing error into a discrete type that the system can process in a structured way.

[0075] Step S503: Based on the pre-stored syntax repair template library, query the corresponding set of repair rules according to the syntax error type encoding; The syntax correction template library is a structured knowledge store where each record is associated with one or more syntax error type codes and stores typical correction strategies for that type of error. These sets of correction rules are not simply correct answers, but rather a series of correction templates containing constraints and operational instructions.

[0076] Specifically, for the "bracket mismatch" error type, the set of repair rules may include various strategies such as "checking the type of the nearest left bracket and completing the corresponding right bracket" and "deleting redundant right brackets," along with their prerequisites. By performing a quick query using error type coding, the system can accurately obtain the set of available repair solutions most relevant to the current diagnostic result.

[0077] In some embodiments, the syntax correction template library can be a JSON file or a database table. The system uses the error code ERR_MISSING_COLON_AFTER_CONDITION output from step two as the key for querying. The query result returns a correction rule object, which may contain: { "action": "insert", "position": "after_condition", "content": ":", "constraints": ["next_token_not_comment"]}. This set of rules provides clear operational guidelines and security boundaries for subsequent automated corrections.

[0078] Step S504: Split the code block data in the enhanced context data into independent code segment units by line, and generate an abstract syntax tree representation graph for each code segment unit; The core of this step is to generate an abstract syntax tree representation for each code segment unit. Splitting the code block data line by line is to isolate the context and separate out local areas that may contain errors, making it easier to perform detailed analysis.

[0079] Specifically, an Abstract Syntax Tree (AST) is a tree-like representation of the abstract syntactic structure of source code. Each node in the tree represents a syntactic structure in the source code (such as operators, function calls, control flow statements, etc.). Generating an AST is equivalent to converting linear, string-like code into a non-linear, structured object model rich in parent-child and sibling relationships. This AST representation accurately captures the syntactic hierarchy and logical structure of the code, while stripping away formatting information that does not affect syntactic semantics (such as spaces and line breaks). It provides a precise navigation map for locating errors at the syntactic structure level, rather than the text level.

[0080] In some embodiments, the system uses Python's built-in `ast` module. For the code snippet `x = 1 + 2`... 3, ast.parse This will generate an AST. Its root node is a Module node, containing a child node Assign (assignment statement). The Assign node contains targets (left-hand side x, a Name node) and value (right-hand side expression, a BinOp node). The left operand of this BinOp node is the number 1 (Constant node), the operator is Add, and the right operand is another BinOp node (2). 3). This AST diagram accurately describes the priority of operations and the code structure.

[0081] Step S505: Locate the abnormal node path corresponding to the abnormal syntax tag sequence in the abstract syntax tree representation graph; The system analyzes the correspondence between nodes and source text tags recorded by the parser during AST construction, tracing back through the AST to find the root node or its parent node that caused the parsing failure. The ultimately located error node path refers to the unique access path from the AST root node to the node containing the abnormal syntactic structure. For example, this path might indicate that the error occurred in a conditional expression child node of an if statement node.

[0082] Understandably, locating the abnormal node path allows subsequent repair operations to be performed directly on specific syntactic structure nodes and their context, avoiding potential side effects caused by string replacement at the text level.

[0083] In this embodiment, following the example of step one, the abnormal sequence [5, print] is located in row 1, column 9 to column 15. The system traverses the AST using ast.walk. The system then checked the `.lineno` and `.col_offset` attributes of each node and found that the `Compare` node corresponding to the `.test` (condition) attribute of the `If` node ended in column 8, while the next sibling node, `Expr` (expression statement, corresponding to the `print` call), started in column 10. The system thus determined that the problem was that the `If` node was missing its required statement body child node, and the abnormal node path was located to `Module -> If` itself, because its structure was incomplete.

[0084] Step S506: Input the set of repair rules and the abstract syntax tree representation of the labeled abnormal node paths into the language model; The structured set of repair rules defines the basic direction and constraints of the repair actions; the abstract syntax tree representation, with the problem locations marked, graphically and structurally describes the "anatomical diagram" of the current code. By inputting both of these into a pre-built language model, a constrained generation task is essentially set for the model: "modify a specified target structure within a given rule framework." This transforms the language model's role from an all-powerful code generator into an intelligent repair engine that reasones and executes within a controlled knowledge and structural framework, improving the reliability, security, and relevance of the generated results to the problem domain.

[0085] For example, the prompt word inputting a language model (such as Claude-3 or GPT-4) might be constructed as: "Given the AST structure of the following code (with the path to the problem node marked: Module -> If missing body) and the fix rule (insert a colon after the test clause of the If node and create a new body child node), generate the corrected AST fragment." The model receives both rule and structure information, allowing its reasoning to focus on how to apply the rule to fix the specific structure.

[0086] Step S507: The language model is used to parse the grammatical constraints in the repair rule set and verify the conflict points between the abnormal node path and the grammatical constraints, and generate the correction code segment to eliminate the conflict points. Specifically, the language model first deeply understands the syntactic constraints inherent in each rule in the set of repair rules (e.g., "a for loop statement must contain three parts: an initialization expression, a loop condition, and an iteration expression, separated by semicolons"). Then, the model compares and verifies these constraints against the subtree structure pointed to by the abnormal node paths marked in the AST. This process is not a simple string matching but rather logical reasoning at the syntactic and semantic level to identify which constraint(s) the current abnormal structure specifically violates and how it is violated (i.e., the conflict point). For example, the model might determine that an abnormal node is a while statement lacking a conditional expression, which conflicts with the constraint that "a while statement must have a conditional expression."

[0087] Next, after identifying the conflict point, the model's task becomes: to modify the abnormal node and its surrounding minimal scope while adhering to all relevant syntactic constraints, in order to eliminate the identified conflict. The final generated corrected code segment is a minimal and rationalized correction of the original erroneous fragment while satisfying all syntactic rules; it may be a complete statement, an expression, or a code block.

[0088] For example, model analysis confirms the conflict point is a missing body in the "If" node. According to the rule, it needs to insert a colon (:) after the test clause (i.e., between the exception sequence [5, print]) and wrap the subsequent print statement as the body of the If node. The model might output the corrected code text as: if x > 5: print("Hello"). This generation process is a structured output based on an understanding of the rules and the AST structure.

[0089] Step S508: Insert the corrected code segment into the header metadata area of ​​the enhanced context data to form the final enhanced context data packet.

[0090] The generated correction code snippet is appended as a correction suggestion to the header of the entire data packet in the form of metadata (e.g., adding a "suggested_correction" field to the JSON structure). The resulting enhanced context data packet retains the original, unaltered search and merge results in its main body, ensuring data traceability and diversity; while its header metadata section explicitly provides verified correction schemes for the identified grammatical issues.

[0091] Understandably, this design allows subsequent prompt word building modules or presentation layers to flexibly choose to display the original code, the revised code, or a comparison of the two, thereby providing users (students or teachers) with more comprehensive and inspiring learning materials. It achieves the principle of enhancing information without compromising the integrity of the original data ecosystem.

[0092] In the above implementation, the system not only locates relevant code examples for users but also proactively identifies and corrects syntax errors, providing correct code paradigms as learning references. This greatly enhances the educational reliability and practicality of the intelligent code tutoring system's output, upgrading search results from informational materials to verified teaching resources. It effectively assists students in understanding common syntax errors and their correction methods, thereby deepening the system's practical application value and influence in teaching scenarios.

[0093] Reference Figure 6 As one implementation of step S107, the step of combining enhanced contextual data with query text content into prompt words and calling a language model to generate response text includes: Step S601: Construct a prompt word template containing enhanced contextual data, and inject the query text content into the specified position of the prompt word template to obtain the combined prompt word sequence; The system predefines prompt templates, which typically include system role instructions (such as "You are a code assistant"), context data placeholders (such as "{context}"), and query injection anchors (such as "{query}"). Enhanced context data is inserted into the placeholder positions, forming a semi-structured prompt framework. In essence, this templated design transforms unstructured context into an input format understandable by the language model, while simultaneously constraining model behavior through instructions to guide the generation of professional responses.

[0094] Next, the system identifies query injection anchors (such as "{query}") in the template and seamlessly replaces the user's query text at those locations. The injection operation must maintain text coherence and grammatical correctness, for example, by adding natural language conjunctions before and after the query (such as "for the following query: {query}"). This can be precisely targeted using regular expressions or parse trees to avoid accidental replacements or formatting violations. This operation ensures deep integration of the query with its context, enabling the language model to generate responses based on complete semantics, rather than processing queries in isolation.

[0095] Step S602: Call the pre-trained language model to process the combined prompt word sequence and output text stream data; The system transmits combined prompts to a pre-trained language model (such as Claude-4) via an API interface (e.g., HTTP requests). The model first performs word embedding and encoding on the input to generate a high-dimensional vector representation. Subsequently, it calculates context weights through a self-attention mechanism and generates a text sequence based on a decoding strategy (e.g., beam search). The invocation process may adopt a streaming mode, sending prompts in chunks to optimize latency, with system instructions transmitted first to ensure the model quickly understands the task role.

[0096] Subsequently, the system receives the text stream generated by the model in real time via an asynchronous I / O interface. Data is transmitted in chunks (e.g., 512 bytes per chunk) to reduce memory usage and latency. The receiving process employs a double-buffer mechanism: one buffer stores the received data, while the other handles data parsing, ensuring continuity and real-time performance. This design utilizes an event loop (such as asyncio) to handle concurrent data streams, avoiding blocking the main thread. For example, for long responses, the system can display text incrementally, improving the user experience.

[0097] Step S603: Detect the termination identifier in the text stream data and extract the text content before the termination identifier as the response text.

[0098] The system monitors pre-defined termination identifiers (such as "]]>" or "<|endoftext|>") in the text stream. These identifiers are inserted by the language model to mark the end of the response. The detection algorithm, based on a sliding window and regular expressions, scans the incoming data in real time. When a termination sequence is matched, a stop receiving command is triggered. The system formats the text stream before the termination identifier, including code highlighting, indentation adjustment, and redundancy removal. Subsequently, the response text is serialized into the target format (such as JSON or HTML) and returned to the user via the API interface.

[0099] In the above embodiments, the response quality and real-time performance of the code retrieval system are improved through dynamic prompt word construction and streaming response generation. This technical solution enhances the automation of response generation, controls the average latency to the second level, and provides an efficient and reliable natural language interaction foundation for programming education platforms.

[0100] Reference Figure 7 As a further implementation of the code retrieval method, after the step of storing the response text associated with the query identifier in the cache database, the method further includes: Step S701: Periodically scan all cache entries in the cache database and output a cache activity dataset containing access frequency and the most recent access timestamp; Specifically, during system operation, the cache database, acting as a temporary storage area, continuously accumulates user queries and their responses. A simple time-to-live (TTL) based expiration mechanism cannot distinguish between high-frequency core knowledge and low-frequency, less popular content. Therefore, this step uses a separate background daemon or scheduled task to traverse all entries in the cache at fixed intervals (e.g., every minute or every five minutes). For each cached entry, it not only reads its stored response text but, more importantly, extracts and aggregates its associated metadata, namely the entry's historical access frequency and the timestamp of its most recent access. These two metrics together constitute the cache activity dataset; access frequency reflects the general demand for the entry, while the most recent access timestamp reflects its timeliness and popularity.

[0101] Step S702: Construct a min-heap data structure based on the cache activity dataset, mark cache entries whose access frequency is lower than the first frequency threshold and whose most recent access timestamp is earlier than the second time threshold as items to be reclaimed, and output a list of items to be reclaimed; The purpose of constructing a min-heap data structure is to optimize the filtering process. Specifically, the system can use access frequency or the most recent access timestamp as the heap key to quickly locate the entries with the smallest values ​​(i.e., the least active entries). Based on this, the system applies a two-condition judgment strategy: a first frequency threshold (e.g., fewer than 2 accesses per unit time) is used to filter entries with low general demand; a second time threshold (e.g., most recent access time more than 24 hours ago) is used to filter entries with low recent activity. Only "low-frequency cold data" that simultaneously meets both conditions are marked as items to be reclaimed. The final output list of items to be reclaimed is a precisely identified and prioritized target set for deletion operations, ensuring the accuracy and security of cache reclamation.

[0102] Step S703: When it is detected that the space occupied by the cache database exceeds the preset capacity threshold, the corresponding cache entries are deleted in batches according to the list of items to be reclaimed, and a space release signal is output. The system continuously monitors the disk or memory usage of the cache database, but does not trigger cleanup every time a new entry is inserted (as this would increase latency for a single request). Instead, it sets a preset capacity threshold (such as 80% or 90% of the total space). When the occupied space exceeds this threshold, it means that system resources are becoming strained and there is a risk of affecting overall performance, at which point cleanup is triggered.

[0103] Once the triggering conditions are met, the system no longer needs to perform time-consuming real-time filtering. Instead, it directly reads the list of items to be recycled and performs batch deletion. Compared to deleting items one by one, batch deletion significantly reduces the number of database I / O operations and improves recycling efficiency. The space release signal output after deletion serves as both confirmation of the operation's result and as an event notification to trigger other subsequent processes.

[0104] Step S704: In response to the space release signal, obtain the query identifier and response text content of the remaining cache entries; In response to the space release signal, the system retrieves the core data of all cached entries retained after this cleanup: the query identifier (as a unique key) and its corresponding response text content. Essentially, this operation takes a "snapshot" of the currently cached valid content. This snapshot data represents the set of core knowledge deemed most valuable after activity filtering, serving as the data foundation for subsequent hash calculations and version binding.

[0105] Step S705: Based on the query identifier and the response text content, a new set of hash keys is generated by calling a preset hash calculation function; Specifically, a cryptographic hash function (such as SHA-256) can be introduced to generate a unique and compact "digital fingerprint" for the cached content. The system concatenates the query identifier and response text content of each cached entry obtained in the previous step, inputs it into a preset hash function, and calculates a fixed-length, unique hash value. The characteristics of the hash function ensure that even the slightest difference in content will result in a significant change in the generated hash value. By aggregating the hash values ​​corresponding to all remaining cached entries, a "new hash key set" is generated. This hash value set mathematically uniquely represents the complete content state of the current cache repository. Any addition, deletion, or modification of content will cause a change in the entire hash key set, thus providing an accurate and reliable basis for detecting changes in the cache repository's state.

[0106] Step S706: Bind and store the new hash key set with the current version identifier of the preset knowledge graph; The knowledge graph is not static; it is updated via the LightRAG service as the system learns (e.g., by handling new student code errors), resulting in different versions (e.g., v1.0, v1.1). The cached response text is essentially a knowledge derivative generated from a specific version of the knowledge graph. This is achieved by binding the new set of hash keys obtained in the previous step (i.e., the digital fingerprint of the current cached content) to the current version identifier of the preset knowledge graph upon which this cached content was generated. This binding establishes a clear mapping: the cached content of this version is backed by that specific version of the knowledge graph.

[0107] Step S707: When the version identifier of the preset knowledge graph is updated, the cache entries bound to the old version are automatically discarded, and a cache optimization log is generated.

[0108] The cache optimization log records the number of deleted entries corresponding to the space release signal, the timestamp of the new hash key set generation, and is eventually written to the audit database.

[0109] Specifically, after the knowledge graph is upgraded, the system can quickly identify which cached content is generated based on the old graph and may be outdated. This allows for precise invalidation or cache preheating, ensuring users always receive accurate information consistent with the latest knowledge graph. This solves the challenges of data consistency and cache timeliness at the system architecture level, guaranteeing the accuracy and reliability of the entire intelligent system's response.

[0110] In the above implementation, the precise elimination of low-frequency cold data efficiently maintains the health of the cache space, ensuring the system's response speed and scalability in high-concurrency scenarios. At the same time, by establishing a strong correlation between cached content and knowledge graph versions, the accuracy and timeliness of the knowledge output by the retrieval system throughout its entire lifecycle are ensured. This fundamentally solves the technical problem of inconsistency between cached data and source data in a dynamic knowledge base environment, providing underlying support for the stable and reliable operation of the intelligent code tutoring system.

[0111] This application also discloses a code retrieval system based on entity disambiguation and multi-path recall.

[0112] A code retrieval system based on entity disambiguation and multi-path recall specifically includes: The query request receiving module is used to receive user query requests, extract query text content, and generate query identifiers. The cache retrieval module is used to retrieve the cache database based on the query identifier. If a valid cache exists, it outputs the first judgment result; if no valid cache exists, it outputs the second judgment result. The cache response module is used to respond to the first judgment result and output the cache response result; The keyword extraction module is used to respond to the second judgment result, call the pre-configured language model to process the query text content, and output the initial keyword set; The entity disambiguation module is used to perform entity disambiguation on the initial keyword set and generate a disambiguated entity set. The multi-path recall module is used to perform multi-path concurrent retrieval based on the disambiguation entity set, including retrieving entity nodes, retrieving relation edges, and performing direct vector retrieval. The three retrieval results are obtained and merged to generate enhanced context data. The response generation module is used to combine enhanced contextual data with query text content into prompt words and call the language model to generate response text; The response result return module is used to store the response text associated with the query identifier in the cache database and output the response result to the user.

[0113] The code retrieval system based on entity disambiguation and multi-path recall in this application embodiment can implement any of the above methods, and the specific working process of each module in the system can refer to the corresponding process in the above method embodiments.

[0114] In the several embodiments provided in this application, it should be understood that the provided methods and systems can be implemented in other ways. For example, the system embodiments described above are merely illustrative; for example, the division of a certain module is merely a logical functional division, and in actual implementation there may be other division methods, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed.

[0115] In practical applications, the implementation background of the code retrieval system based on entity disambiguation and multi-path recall in this application embodiment is a programming education platform, aiming to solve the technical problems of existing code learning platforms such as lack of real-time learning situation analysis, weak code data correlation, and insufficient LightRAG retrieval optimization. The system adopts a distributed microservice architecture, deployed in a server cluster environment, based on a full-process design of "data collection-correlation processing-optimized retrieval-visualization display". Each module communicates asynchronously through RESTful APIs and message queues. Hardware configuration includes multi-port network interface cards, Redis cluster, GPU servers, and heterogeneous computing platforms. The software environment requires pre-installed Jupyter kernel service, Claude-4 language models, and LightRAG optimization service. When the system starts, it first initializes each microservice component, establishes a Redis connection pool, loads initial knowledge graph data, and configures the WebSocket service endpoint. The complete implementation process includes the following core stages: Phase 1: Real-time monitoring and data collection in the Jupyter container. The system uses a port scanner to traverse the 30040-30050 port range, sending HTTP status requests to detect active Jupyter services. After token authentication of active services, a "port-kernel ID" mapping is established and stored in Redis. A long-lived connection is established with each active kernel based on the Jupyter native WebSocket API, with a heartbeat mechanism configured at 30-second intervals. During the data collection phase, four types of kernel messages are monitored and parsed: `execute_input` (code input), `execute_result` (execution result), `error` (error message), and `status` (kernel status). Collected data is written to a Redis list in real time and asynchronously pushed to the data processing layer. When a connection anomaly is detected, an exponential backoff reconnection mechanism is triggered based on the WebSocket close code type, with a maximum retry interval of 30 seconds. After a successful reconnection, offline message compensation is performed using the Sequence ID.

[0116] Phase Two: Data Processing and Structure Transformation. The data association module communicates with the user service, course service, and class service via the gRPC protocol to obtain container usage information and associated metadata such as course ID and student ID. The code preprocessing module analyzes and processes the code content: when a single code segment exceeds 2000 characters or contains multiple function / class definitions, it is divided into blocks based on function definitions and code block comments, controlling the number of characters in a single block to be within the range of 1000-2000. After block division, standardized JSON format data is generated, including required fields such as course ID, chapter ID, student ID, teacher ID, error identifier, error type, and code content, as well as optional block information fields.

[0117] Phase 3: LightRAG Optimization of Retrieval Processing. After receiving text data, the document processing module performs MD5 deduplication and initializes the document state. The document is processed in chunks using an asynchronous pipeline, with a default chunk size of 1200 tokens and 100 token overlap. The entity extraction module selects different processing strategies based on the mode: Mode 1 directly parses JSON fields to extract predefined entities; Mode 0 generates entities and relations using LLM. The entity disambiguation module uses a hierarchical clustering algorithm to group entity vectors, setting the clustering threshold to 0.9, and then uses LLM for deep semantic disambiguation to generate a canonical entity mapping table. The knowledge graph update module persists the disambiguated entities and relations to the vector database and graph database, completing the incremental update of the knowledge graph.

[0118] Phase Four: Intelligent Question Answering and Retrieval Applications. After receiving user query requests via the ` / query` API, the system first calculates the query hash and checks the cache. If the cache is not hit, it calls the LLM (Entity Module Management) to extract high-level and low-level keywords. Different retrieval contexts are constructed based on the query pattern: local mode performs structured queries based on entity relationship graphs; global mode performs unstructured queries based on vector similarity; hybrid mode combines the first two methods; and mix mode implements three-way retrieval using entity relationship graphs, relationship vectors, and text block vectors. Finally, the enhanced context data is combined with the user query to form prompts, the LLM is called to generate the response text, and the results are cached and returned to the user.

[0119] Through the above implementation process, the system achieves real-time collection, intelligent analysis, and accurate retrieval of code execution data, providing personalized teaching support capabilities for programming education scenarios. Students can quickly solve programming problems through the intelligent question-and-answer mechanism, significantly improving teaching efficiency and learning experience.

[0120] In summary, regarding core technological advantages, this application achieves efficient transmission with a code execution data collection delay of no more than 1 second by adopting WebSocket long connection combined with heartbeat detection and offline compensation mechanism. The automatic reconnection success rate after disconnection is as high as 99%, and the phenomenon of offline message loss is completely eliminated. This significantly reduces the system feedback delay from the 30-second level of the traditional polling mechanism to the second level, greatly improving the real-time performance and reliability of data collection.

[0121] In terms of information retrieval performance, this application effectively optimizes the retrieval accuracy of LightRAG through the synergistic application of entity disambiguation technology and multi-path recall strategies. Most importantly, by separating code content from knowledge graph information, the system successfully constructs a more precise knowledge graph, laying a solid foundation for high-quality retrieval services. Furthermore, the system automates error analysis, employing an error classification model based on a combination of regular expression matching and large-scale model semantic judgment. This model can accurately classify code errors, providing powerful index support for knowledge graph construction and further enriching the structure of the knowledge system.

[0122] In practical applications, the technical solution presented in this application provides strong support for personalized teaching. Students can leverage the integrated large-scale model capabilities and historical code records to quickly resolve practical problems encountered during programming through an intelligent question-and-answer mechanism, thereby significantly improving teaching efficiency and learning experience.

[0123] This application also discloses a computer device.

[0124] A computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement a code retrieval method based on entity disambiguation and multiplexed recall as described above.

[0125] This application also discloses a computer-readable storage medium.

[0126] A computer-readable storage medium storing a computer program that can be loaded by a processor and executed as described above in any of the code retrieval methods based on entity disambiguation and multiplexed recall.

[0127] The computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus, or device; the program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0128] The above are all preferred embodiments of this application and are not intended to limit the scope of protection of this application. Any feature disclosed in this specification (including the abstract and drawings) may be replaced by other equivalent or similar features unless specifically stated otherwise. That is, unless specifically stated otherwise, each feature is only one example of a series of equivalent or similar features.

Claims

1. A code retrieval method based on entity disambiguation and multi-path recall, characterized in that, The method includes: Receive user query requests, extract query text content, and generate query identifiers; The cache database is retrieved based on the query identifier, and if a valid cache exists, the cache response result is output. If no valid cache exists, the pre-configured language model is invoked to process the query text content and output the initial keyword set; Perform entity disambiguation on the initial keyword set to generate a disambiguated entity set; Multi-path concurrent retrieval is performed based on the disambiguation entity set, including retrieving entity nodes, retrieving relation edges, and performing direct vector retrieval. The three retrieval results are obtained and merged to generate enhanced context data. The enhanced contextual data is combined with the query text content to form prompt words, and the language model is invoked to generate response text. The response text is associated with the query identifier and stored in the cache database, and the response result is output to the user.

2. The code retrieval method based on entity disambiguation and multi-path recall according to claim 1, characterized in that, The steps for retrieving the cached database based on the query identifier include: Use the query identifier as the retrieval key to query the cache database; When there is no valid cache record associated with the retrieval key in the cache database, the result of determining that there is no valid cache is output. When a valid cache record associated with the retrieval key exists in the cache database, the difference between the expiration mark of the valid cache record and the current system timestamp is calculated and compared with a preset expiration threshold. If the difference is less than or equal to the preset time limit, the result of valid cache is output; if the difference is greater than the preset time limit, the cache is determined to be invalid and the result of valid cache is output.

3. The code retrieval method based on entity disambiguation and multi-path recall according to claim 1, characterized in that, The steps of performing entity disambiguation on the initial keyword set to generate a disambiguated entity set include: Based on the initial keyword set, generate a semantic vector representation for each initial keyword; The semantic vector representations are clustered and grouped using a cosine similarity threshold. Synonym validation is performed on the initial keywords within the cluster group, and a set of disambiguated entities containing standard entity names is output.

4. The code retrieval method based on entity disambiguation and multi-path recall according to claim 1, characterized in that, The steps of performing multi-way concurrent retrieval based on the disambiguation entity set, including retrieving entity nodes, retrieving relation edges, and performing direct vector retrieval, obtaining the three retrieval results and merging them to generate enhanced context data, include: Establish an entity node recall path, based on the disambiguation entity set, encode the query text content into a vector, perform vector retrieval and keyword matching in the preset entity index, and generate an entity node retrieval result set containing entity name, attributes and similarity score; Establish a relation edge recall path, extract topic words and relation words from the query text content based on the disambiguation entity set, perform vector retrieval and match topic tags in the preset relation edge index, and generate a relation edge retrieval result set containing relation type, topic tag and path score; A vector recall pathway is established. Based on the disambiguation entity set, vector similarity matching is performed on the query text content. The original text fragments are retrieved from the vector database to generate a set of text fragment retrieval results containing vector similarity scores and original text citations. The entity node retrieval result set, relation edge retrieval result set, and text fragment retrieval result set are structured and integrated to obtain three-way retrieval results; Establish an entity name hash set and a text content hash set as deduplication benchmarks. Based on a preset polling order, extract content that does not appear in the hash set from the three search results and add it to the enhanced context data list, and update the corresponding hash set. Obtain the preset weight configuration coefficients, and calculate a weighted score for each item in the enhanced context data list based on the source path; The top K items are selected as the final enhanced context data, arranged in descending order of the weighted scores, where k is a configurable positive integer.

5. The code retrieval method based on entity disambiguation and multi-path recall according to claim 4, characterized in that, Following the step of generating enhanced context data, the following is also included: Parse the code syntax structure in the enhanced context data and identify the abnormal syntax marker sequence within the code block data; Detect the matching degree of the abnormal syntax marker sequence in the preset error classification model, and output the syntax error type code; Based on the pre-stored syntax repair template library, the corresponding set of repair rules is queried according to the syntax error type encoding; The code block data in the enhanced context data is split into independent code segment units by line, and an abstract syntax tree representation graph is generated for each code segment unit; Locate the abnormal node path corresponding to the abnormal syntax tag sequence in the abstract syntax tree representation graph; Input the set of repair rules and the abstract syntax tree representation of the annotated abnormal node paths into the language model; The language model is used to parse the grammatical constraints in the set of repair rules and verify the conflict points between the abnormal node path and the grammatical constraints, and generate a correction code segment to eliminate the conflict points. The corrected code segment is inserted into the header metadata area of ​​the enhanced context data to form the final enhanced context data packet.

6. The code retrieval method based on entity disambiguation and multi-path recall according to claim 1, characterized in that, The steps of combining the enhanced context data with the query text content to form prompt words and then calling the language model to generate response text include: Construct a prompt word template containing the enhanced context data, and inject the query text content into a specified position of the prompt word template to obtain a combined prompt word sequence; The pre-trained language model is invoked to process the combined prompt word sequence and output text stream data. Detect the termination identifier in the text stream data, and extract the text content before the termination identifier as the response text.

7. A code retrieval method based on entity disambiguation and multi-path recall according to any one of claims 1 to 6, characterized in that, After the step of storing the response text associated with the query identifier in the cache database, the method further includes: Periodically scan all cache entries in the cache database and output a cache activity dataset containing access frequency and the most recent access timestamp; Based on the cache activity dataset, a min-heap data structure is constructed. Cache entries whose access frequency is lower than the first frequency threshold and whose most recent access timestamp is earlier than the second time threshold are marked as items to be reclaimed, and a list of items to be reclaimed is output. When the cache database is detected to have occupied space exceeding a preset capacity threshold, the corresponding cache entries are deleted in batches according to the list of items to be reclaimed, and a space release signal is output. In response to the space release signal, obtain the query identifier and response text content of the remaining cache entries; Based on the query identifier and the response text content, a new set of hash keys is generated by calling a preset hash calculation function; The new set of hash keys is bound and stored with the current version identifier of the preset knowledge graph; When the version identifier of the preset knowledge graph is updated, cache entries bound to the old version are automatically discarded, and a cache optimization log is generated.

8. A code retrieval system based on entity disambiguation and multi-path recall, characterized in that, The system includes: The query request receiving module is used to receive user query requests, extract query text content, and generate query identifiers. The cache retrieval module is used to retrieve the cache database according to the query identifier. If a valid cache exists, a first judgment result is output; if no valid cache exists, a second judgment result is output. The cache response module is used to respond to the first judgment result and output the cache response result; The keyword extraction module is used to respond to the second judgment result, call the pre-configured language model to process the query text content, and output an initial keyword set; The entity disambiguation module is used to perform entity disambiguation on the initial keyword set to generate a disambiguated entity set. The multi-path recall module is used to perform multi-path concurrent retrieval based on the disambiguation entity set, including retrieving entity nodes, retrieving relation edges, and performing direct vector retrieval, obtaining three-path retrieval results and merging them to generate enhanced context data; The response generation module is used to combine the enhanced context data with the query text content to form prompt words, and call the language model to generate response text. The response result return module is used to associate the response text with the query identifier, store it in the cache database, and output the response result to the user.

9. A computer device, characterized in that: The method includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer program is stored that can be loaded by a processor and executed as described in any one of claims 1 to 7.