An intelligent question-answering method based on structured semantic index and double-layer memory enhancement

By employing a structured semantic indexing and dual-layer memory-enhanced intelligent question-answering method, the problems of code semantic fragmentation, insufficient multimodal processing, and lack of long-term memory in existing systems for unstructured data processing are solved. This enables efficient and personalized code retrieval and interaction, and reduces the difficulty of system maintenance.

CN122019738BActive Publication Date: 2026-07-07TURING AI INST NANJING CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
TURING AI INST NANJING CO LTD
Filing Date
2026-04-16
Publication Date
2026-07-07

AI Technical Summary

Technical Problem

Existing intelligent question-answering systems suffer from semantic breaks in code, insufficient multimodal processing capabilities, limited retrieval accuracy, and lack of long-term memory mechanisms when processing unstructured data, resulting in low interaction efficiency and difficulty in self-optimization.

Method used

By employing structured semantic indexing and dual-layer memory enhancement, and through query preprocessing, multi-tool dynamic routing, structured and semantically enhanced index construction, adaptive context assembly, and dual-layer memory management, combined with a large language model for code retrieval and long text processing, personalized interaction and self-evolution are achieved.

Benefits of technology

It improves the accuracy of code retrieval, enhances context utilization, possesses personalized learning capabilities, reduces system maintenance costs, and achieves self-iterative optimization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122019738B_ABST
    Figure CN122019738B_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of natural language processing and information retrieval, and relates to an intelligent question and answer method based on structured semantic index and double-layer memory enhancement, which comprises six steps of query preprocessing, Agent-based multi-tool dynamic routing, structured and semantic enhanced index construction, adaptive context assembly, double-layer memory management, data closed loop and self evolution. By adopting a differentiated segmentation strategy for text, code and multi-modal data, combining query optimization, intelligent tool routing and hybrid retrieval algorithm, the technical defects of existing RAG systems, such as semantic breakage, low retrieval accuracy, lack of long-term memory and self-optimization, are solved. The application improves the code retrieval accuracy and context utilization rate, realizes personalized long-term service and automatic operation and maintenance, and is suitable for technical research and development, code library maintenance and intelligent question and answer scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of natural language processing and information retrieval technology, and relates to an intelligent question answering method based on structured semantic indexing and two-layer memory enhancement. Background Technology

[0002] With the development of Large Language Models (LLMs), Retrieval Augmentation (RAG) has become the mainstream paradigm for intelligent question answering systems. However, existing RAG systems suffer from the following technical shortcomings:

[0003] Unstructured data segmentation is unreasonable: Traditional fixed character / token segmentation leads to semantic breaks in code and logical fragmentation in long texts, and cannot adapt to the semantic features of different types of data;

[0004] Insufficient multimodal processing capabilities: low conversion efficiency for non-text files such as PDF and PPT, and difficulty in effectively extracting semantic information from non-text elements such as tables and charts;

[0005] Limited search accuracy: The modal gap between user queries and code / professional documents leads to low relevant information recall, and a single search algorithm cannot take into account both semantic matching and keyword matching.

[0006] No long-term memory mechanism: Context is lost after the session ends, and users need to repeatedly provide background information, resulting in low interaction efficiency;

[0007] Lack of self-optimization loop: Relying on manual parameter adjustment, user feedback is not effectively utilized for system iteration.

[0008] Comparative document 1 (CN120337898B) focuses on the scenario of tender document plagiarism detection. Although it involves multimodal information processing and semantic segmentation, it does not solve problems such as code retrieval, long-term memory, and system self-evolution, and cannot meet the needs of scenarios such as technology research and development and code maintenance. Therefore, there is an urgent need for an unstructured document processing solution that takes into account differentiated segmentation, accurate retrieval, personalized interaction, and self-evolution. Summary of the Invention

[0009] The purpose of this invention is to overcome the shortcomings of the prior art and provide an intelligent question answering method based on structured semantic indexing and dual-layer memory enhancement.

[0010] To achieve the objectives of this invention, the following technical solutions are adopted.

[0011] An intelligent question answering method based on structured semantic indexing and two-layer memory enhancement includes:

[0012] (1) Query preprocessing: rewrite the user query, extract key entities and set search filtering conditions; if the query is found to involve code retrieval, generate hypothetical pseudocode for code retrieval;

[0013] (2) Agent-based multi-tool dynamic routing: Deploy a central routing Agent to analyze the user's query intent and select a retrieval tool from a preset retrieval tool set based on the semantic matching degree; where: the retrieval tool set includes a document retrieval tool, a code library retrieval tool, a FAQ retrieval tool, and an online retrieval tool;

[0014] (3) Structured and semantic-enhanced index construction:

[0015] Text data processing: First, perform segmentation according to the document title hierarchy. When there is no clear title or the text length exceeds the preset threshold, perform segmentation according to the maximum character length; non-text format files are converted to text format through a multi-modal parsing tool and then segmented;

[0016] Code data processing: Use the Tree-sitter parser to convert the code file into an Abstract Syntax Tree (AST), use the identified high-level semantic nodes as segmentation units, extract code meta-information at the same time, and call a large language model to generate a functional description summary for each code segmentation block;

[0017] Hybrid index construction: Adopt a hybrid retrieval mechanism that combines vector cosine similarity and the BM25 algorithm to calculate the retrieval score;

[0018] (4) Adaptive context assembly: Set a length threshold Tmax. When the length of the retrieval result L < Tmax, return the full text; when L ≥ Tmax, use a large language model to extract the core information from the long text and extract the skeleton from the long code, retaining the key logical structure;

[0019] (5) Double-layer memory management: Build a short-term scenario buffer for storing structured interaction logs, an asynchronous memory solidification module for periodically extracting long-term information, and a long-term semantic knowledge base for realizing persistent knowledge storage and retrieval;

[0020] (6) Data closed-loop and self-evolution: Record the complete link of each interaction and the user feedback, generate positive and negative sample test data sets, and verify the answer consistency through regression testing when the system is updated to achieve data-driven self-optimization.

[0021] Further, the key entities include programming languages, device models, date ranges, and technical terms; the retrieval filtering condition is a metadata filtering condition, which is implemented through the metadata filtering expression of the vector library.

[0022] Further, the multi-modal parsing tools include mineru and paddleocr-vl; the non-text format files include PDF and PPT, and after conversion, a docx format file is generated for title parsing.

[0023] Furthermore, the high-level semantic nodes include function definitions and class definitions; the code metadata includes file path, file type, module name, method name, start line number, end line number, and keywords; the code segmentation uses regular expressions to capture function comments and syntax structure.

[0024] Furthermore, the preset threshold is obtained by dynamically adjusting the capacity of the large model context window; the maximum text length is 5000 characters and can be adjusted according to the actual scenario.

[0025] Furthermore, the structured interaction log includes the fields session_id, turn_index, timestamp, and interaction_data; wherein: the interaction_data field contains the user's original query, the rewritten query, the agent's thought process, the tool name, the tool output summary, and the final response.

[0026] Furthermore, the triggering conditions for the asynchronous memory solidification are the end of the session, the system idle time exceeding a preset threshold, or archiving across days; the long-term information includes user technology stack preferences, core requirement characteristics, and key facts of historical interactions.

[0027] Furthermore, the positive samples are user likes and interaction records, from which the query and retrieval content and final answers are extracted and rewritten to construct the dataset; the negative samples are user dislikes and interaction records, which are supplemented into the dataset after being manually labeled with error types.

[0028] Furthermore, the retrieval toolset is extended through a tool registry, which contains tool names, function descriptions, and parameter lists, and supports custom configurations according to business scenarios.

[0029] Furthermore, the code skeleton extraction retains the function signatures, parameter lists, and main control flow structures, while the specific implementation details are replaced with comment placeholders.

[0030] Compared with the prior art, the present invention has the following beneficial effects:

[0031] 1. Code retrieval accuracy is significantly improved. By introducing AST parsing and LLM-generated semantic summaries, the problem of traditional RAGs being unable to understand the functional semantics of code is solved. Even if the user's question does not match the variable names in the code, accurate matching can be achieved through the generated Chinese summary and pseudocode.

[0032] 2. High context utilization and more accurate answers: Through an adaptive strategy of segmenting / summarizing long content and returning the full text of short content, context window overflow is avoided, while irrelevant information is reduced to prevent interference with LLM inference and the signal-to-noise ratio of the answer is improved.

[0033] 3. Possesses personalization and continuous learning capabilities. The dual-layer memory architecture enables the system to remember the user's technology stack and preferences. As usage time increases, the system becomes more and more familiar with the user, providing more customized assistance.

[0034] 4. Automated operation and maintenance and evaluation: The integrated log and test data generation loop transforms users' daily usage into system test assets, greatly reducing the maintenance cost and optimization difficulty of the RAG system and enabling the system to self-iterate. Attached Figure Description

[0035] Figure 1 Here is a framework diagram of the method;

[0036] Figure 2 This is a schematic diagram of the structured and semantically enhanced index;

[0037] Figure 3 This is an architecture diagram of the dual-layer memory management. Detailed Implementation

[0038] The present invention will be further described in conjunction with the accompanying drawings and embodiments.

[0039] As an embodiment 1 of the present invention, such as Figures 1 to 3 As shown, an intelligent question-answering method based on structured semantic indexing and dual-layer memory enhancement includes the following process:

[0040] (1) Query preprocessing:

[0041] In the RAG system, the quality of question processing directly determines the upper limit of search results. Simple question rewriting typically only involves resolving semantic references and removing meaningless words. In this method, the question rewriting part also allows the large model to extract key entities E = {e1, e2,...} (such as programming language, device model, date range, etc.). The entities extracted will vary depending on the business scenario. These extracted entities will serve as metadata filtering conditions for subsequent vector retrieval. If a user asks "pointers in C language", the system will automatically generate the filtering condition language: 'c'. Later, during vector library retrieval, the filtering expression metadata['language'] == 'c' will be used, thus excluding all Java or Python code snippets from the search scope. This significantly reduces the vector search space and improves recall accuracy.

[0042] Secondly, in highly specialized tasks such as code retrieval, a modal gap exists between natural language and programming languages. The similarity between a user's natural language question and specific code is low, making accurate retrieval difficult. When a user's question is identified as relevant to the retrieved code, in addition to rewriting the question, the system generates hypothetical pseudocode, which is then used for the retrieval. This "code-to-code" retrieval method has a higher recall rate than "text-to-code" methods.

[0043] (2) Agent-based multi-tool dynamic routing

[0044] This invention deploys a central routing agent to analyze user intent and determine whether and which tools to invoke. If the user's question is casual or a common knowledge-based question, an answer can be generated directly without invoking any tools. If the question involves specific knowledge, the appropriate tool is invoked, the results are compiled, and an answer is provided. The system pre-configures various retrieval tools, such as document retrieval for unstructured documents; code repository retrieval for project code repositories; FAQ retrieval for high-frequency question-and-answer pairs; and network retrieval for real-time information. The agent selects the most suitable tool based on semantic matching.

[0045] / / Tool registry definition (taking IC field as an example)

[0046] {

[0047] "tools": [

[0048] {

[0049] "name": "code_search",

[0050] "description": "Search for the software development kit (SDK) or hardware code library that comes with the chip. Used to find API functions, driver implementations, sample code, macro definitions, etc."

[0051] "parameters": {"query": "string", "language": "string", "part_number": "string"}

[0052] },

[0053] {

[0054] "name": "document_search",

[0055] "description": "Search chip-related technical documents (datasheets, manuals, specifications). Used to find information such as hardware parameters, electrical characteristics, register mappings, and physical dimensions."

[0056] "parameters": {"keywords": "string", "part_number": "string"}

[0057] }, ...... ]

[0060] }

[0061] (3) Structured and semantically enhanced indexes:

[0062] In the knowledge base construction section, general RAG systems often use the same standard to segment all data. This method, however, employs differentiated processing strategies for different data types, such as... Figure 2 As shown.

[0063] For text data, the principle of minimizing segmentation is adopted. Currently, large models support long contexts, and technical documents have strong internal connections. Segmentation is only permissible when there are explicit chapter titles. For non-text files such as PDFs and PPTs, they can be converted into text documents (e.g., docx) first using multimodal document parsing tools (e.g., Mineru, Paddleocr-VL), and then segmented by parsing the titles in the Word document using the `document.paragraphs` method. When there are no specific titles or the text content under the same title is too long, a maximum length is limited (e.g., 5000 characters, which can be adjusted according to the actual scenario) to prevent multiple search results from being merged and exceeding the model context limit.

[0064] For code data, a Tree-sitter parser is used to transform the code file into an Abstract Syntax Tree (AST). The system traverses the AST, identifying high-level semantic nodes such as function definitions and class definitions, treating them as independent chunks to avoid truncating a function and ensuring the integrity of the code syntax. Besides the code content, the data also includes elements such as file path, file type, module, number of methods, method name, start line, end line, and keywords. The following example uses the IC domain, primarily C language code. First, the regular expression `r'( / \*\*[\s\S]*?\* / \s*)?^(?!static\s+inline)([\w\s\*]+?)\s+(\w+)\s*\(([^)]*)\)\s*\{'` is used to identify the function's return type, function name, parameter list, and can capture Doxygen-style comments above the function. Then, the end of the function is located by counting brackets.

[0065] def _find_function_end(self, content: str, start_pos: int) -> int:

[0066] brace_count = 0

[0067] in_function = False

[0068] # ... Traverse characters...

[0069] if char == '{':

[0070] brace_count += 1

[0071] elif char == '}':

[0072] brace_count -= 1

[0073] # When the count reaches zero, it means the function has ended.

[0074] if in_function and brace_count == 0:

[0075] return i + 1

[0076] The complete logical flow is as follows:

[0077] graph TD

[0078] A[Start: main()] --> B{Check input path};

[0079] B -- Invalid --> Z [Exit];

[0080] B -- Valid --> C [Initialize CCodeParser];

[0081] C --> D[process_directory: Traverse SDK directories];

[0082] D --> E{file type?};

[0083] %% C Source File Processing

[0084] E -- .c source file --> F[parse_c_file];

[0085] F --> F1 [Read content & Calculate line count];

[0086] F1 --> F2 [Extract all function information (regular expression + bracket matching)];

[0087] F2 --> F3 {Number of lines <= 500?};

[0088] F3 -- Yes (small file) --> F4 [Generate a single FileChunk];

[0089] F3 -- No (Large Files) --> F5 [Aggregate by Function Boundaries];

[0090] F5 --> F6 {current block + new function > line 500?};

[0091] F6 -- Yes --> F7 [Pack the current code chunk -> Reset the count];

[0092] F6 -- No --> F8 [Add to current block];

[0093] F7 --> F5;

[0094] F8 --> F5;

[0095] %% Header File Processing

[0096] E -- .h header file --> G[parse_header_file];

[0097] G --> G1 [Regular expression matching Struct / Enum / Macro];

[0098] G --> G2[Generate HeaderDefinition Chunks];

[0099] %% Documentation Processing

[0100] E -- .md document --> H[parse_markdown_file];

[0101] H --> H1 [Separate chapters by Markdown headings];

[0102] H --> H2 [Generate DocumentChunk];

[0103] %% Aggregation

[0104] F4 & F7 & G2 & H2 --> I [Collect all Chunks];

[0105] I --> J{output format?};

[0106] J -- JSONL --> K [Write .jsonl line by line];

[0107] J -- JSON --> L [Write the entire file to .json];

[0108] K & L --> M [Print statistical summary];

[0109]

[0110] In addition, to address the mismatch between code and natural language queries, the system calls the larger model again for each segmented code block to generate a functional description summary in natural language.

[0111] During retrieval, the accuracy is improved through "code-code" and "text-text" methods. This involves matching user questions with code keywords and code summaries, and matching pseudocode from question rewrites with actual code. Users can accurately retrieve relevant code information regardless of how they ask the question. A hybrid retrieval method is also used, as detailed below:

[0112] ,

[0113] in: For vector cosine similarity, Score for BM25 These are dynamic weighting coefficients.

[0114] (4) Adaptive Context Assembly:

[0115] To solve the window overflow problem of long contexts, the system implements a dynamic processing strategy during the retrieval and return phase. First, set a length threshold Tmax. When the length L of the retrieved content is L < Tmax, return the full text directly to ensure that the large model knows all the details. When the length L of the retrieved content is L >= Tmax, trigger real-time summarization. Summarize and refine the long text through the large model to extract the core content and retain the logic related to the user's question. Extract the skeleton of the long code through the large model, retain the function signatures and main control flow structures, and replace the specific implementation details with comment placeholders.

[0116] The retrieved results should also include the exact content sources, such as the sections of the document, the files and lines of the code, etc. These information have been processed accordingly during segmentation to ensure that accurate reference sources are included in the final answer.

[0117] (5) Dual-layer Memory Management:

[0118] This invention designs a dual-layer memory architecture that simulates human cognition to solve the forgetting problem in long-term interactions. This architecture consists of three parts: a short-term scenario buffer, an asynchronous memory consolidation module, and a long-term semantic knowledge base, as Figure 3 shown.

[0119] The structured metadata log of short-term scenario memory is different from the pure text history that only stores the user's questions and the system's answers in traditional dialogue systems. The short-term memory of this system is a high-dimensional structured metadata log. The system maintains a structured object for each session that can trace the reasoning process. Each round of interaction contains the following fields:

[0120] {

[0121] "session_id": "sess_20260211_001",

[0122] "turn_index": 5,

[0123] "timestamp": 1707645600,

[0124] "interaction_data": {

[0125] "user_query_raw": "...",

[0126] "user_query_rewritten": "...",

[0127] "agent_thought_trace": "..."

[0128] "tool_name": "code_search",

[0129] "tool_output_summary": "...",

[0130] "final_response": "..."

[0131] }

[0132] }

[0133] The system sets a maximum token threshold. When the log length exceeds the threshold, the earliest round is no longer simply discarded. Instead, the earliest k rounds of dialogue are compressed into a natural language summary, retaining key states while releasing context space.

[0134] The formation of asynchronous memory solidification is a process of extracting static knowledge from streaming logs. This system periodically scans short-term logs through a background asynchronous process. Memory retrieval is triggered in three situations: session end; idle time exceeds a set threshold; and archiving spans multiple days. During retrieval, a large model is used to analyze the short-term logs, distinguishing between facts, preferences, and noise. Facts or preferences with long-term value are extracted, while trivial chatter or temporary debugging instructions are discarded, thus forming a user profile (e.g., this user is a student who frequently uses Python programming).

[0135] Long-term memory is stored in a vector database, achieving knowledge persistence decoupled from specific time points. The extracted long-term memory is transformed into vector storage. At the start of each new future session, the user's memory partition is locked based on their user ID. The top-k relevant facts are retrieved from the long-term memory database based on the current user's question and used as part of the system prompt, thus achieving a personalized and consistent long-term service experience.

[0136] (6) Data closed loop and self-evolution

[0137] To address the challenges of evaluating and optimizing RAG systems, this invention constructs an automated data pipeline. The system meticulously records the entire chain of each interaction and captures user feedback (likes / dislikes), transforming this feedback into a test dataset through a large model. Positive samples are user like interactions, from which Qrewrite, Cretrieved, and Answer are extracted to construct the dataset. Negative samples are user dislike interactions, which are subsequently manually labeled to form the dataset.

[0138] Whenever the system code is updated, a regression test library is run. The system compares the newly generated answers with those in the historical records, using a large model to determine whether the new answers maintain key consistency with the original answers. This mechanism effectively ensures that the RAG system can automatically accumulate knowledge and continuously improve its stability as usage increases, forming a data flywheel.

[0139] As an embodiment 2 of the present invention, such as Figures 1 to 3 As shown, a specific application example of an intelligent question answering method based on structured semantic indexing and two-layer memory enhancement is presented:

[0140] The entire process of a certain device model N****5 (the data has been desensitized here) is demonstrated.

[0141] Data processing section:

[0142] This model has a datasheet, a 209-page PDF file. First, Mineru was used to parse it into a docx document, containing text, images, and headings. Then, the `document.paragraphs` method was used to parse and segment the headings in the docx file, resulting in 50 chunks. This model also has a codebase with 421 code files. Using the same code parsing method, these were segmented into 515 chunks. Finally, a large model was used to generate a functional summary of these chunks.

[0143] Q&A section:

[0144] Question: The N****5 supports a maximum operating frequency of 200MHz. After performing DMA data transfer on the SRAM, why does the CPU sometimes fail to read the latest data? How can this be resolved?

[0145] Step (1)

[0146] The problem has been rewritten and expanded to: Analysis of why the CPU cannot read the latest data after DMA transfer of SRAM data in N****5 and solutions, including cache consistency, L1-Cache refresh strategy, memory barrier usage and DMA cache synchronization mechanism.

[0147] Step (2)

[0148] A memory retrieval was performed, but since this is the user's first time asking a question, the memory retrieval result is empty.

[0149] Step (3)

[0150] The agent module automatically identifies and calls the tool.

[0151] Agent R1: Code retrieval revealed the main.c file under the DMA module. This file contains three complete functions: main, DMA_sramtosram, and DMA1_INT_0_handler. The model-generated functional description is as follows: Configure the DMA1 channel to implement block data transfer between SRAM and SRAM; bind a fixed source signal via DMAMUX; enable a transfer completion interrupt; in the main loop, LEDs flash to indicate the running status; the interrupt service routine verifies the integrity of the transferred data; upon success, outputs a verification pass message; otherwise, it indicates a data error, achieving efficient memory copying and automatic verification without CPU intervention.

[0152] agent r2: Document retrieval retrieved the device's architecture features from the datasheet: 32KB L1-Cache (16KB data cache + 16KB instruction cache), 128KB SRAM2 (with ECC check) + 64KB ITCM + 64KB DTCM.

[0153] agent r3: Summary of answer: The CPU's L1 data cache (16KB) caches data in SRAM. When DMA modifies the SRAM, if the CPU reads the same address again, it will directly read the old data from the cache instead of reading the latest data from SRAM. A solution is provided: use the `SCB_InvalidateDCache_by_Addr` method in `DMA1_INT_0_handler` to invalidate the data cache, forcing a reread from SRAM and ensuring the CPU reads the latest data.

[0154] Step (4)

[0155] The model extracts user memories to generate a user profile: User is an Embedded Systems Engineer, which is then stored in a vector library.

[0156] As a verification example 3 of the present invention, the recall rate, accuracy, context utilization, interaction efficiency, and operation and maintenance cost are verified.

[0157] (1) Code retrieval accuracy and overall question answering performance have been greatly improved.

[0158] In retrieval tests targeting SDK source code, underlying driver implementations, and complex system code, traditional RAG systems based on fixed token segmentation typically achieve a Top-5 recall rate of only around 65% for complex code. However, after adopting the structured and semantically enhanced indexing of this invention, the Top-5 retrieval recall rate for complex code fragments increases to 88%. In a closed test set containing 176 complex business questions, the overall accuracy of the system's generated answers reached 91%.

[0159] (2) Context utilization polarization and token consumption optimization

[0160] For lengthy technical documents and source files with thousands of lines, the adaptive context assembly strategy employed in this invention significantly improves the signal-to-noise ratio of the context window. While maintaining the accuracy of responses, the average token consumption per interaction is reduced by approximately 35%, greatly alleviating the computational pressure on model inference and avoiding logic truncation issues caused by long context overflows.

[0161] (3) The leap in interaction efficiency and long-term memory coherence

[0162] In testing, when troubleshooting complex hardware and software integration issues, the average number of interaction rounds decreased from the traditional 4.8 rounds to 2.2 rounds. Because the system can automatically complete the problem background using long-term memory, the frequency of users repeatedly inputting background information also decreased, resulting in significant improvements in interaction efficiency and immersive experience.

[0163] (4) Reduced operation and maintenance costs and self-evolution of system data

[0164] This invention constructs a data closed-loop and self-evaluation mechanism, transforming manual-driven processes into data-driven ones. By capturing structured metadata and like / dislike feedback during user interactions, the system can automatically generate the dataset required for regression testing. This approach replaces most of the manual data annotation workload (over 70%), significantly shortening the knowledge base maintenance cycle and substantially reducing overall operation and maintenance time costs.

[0165] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.

Claims

1. An intelligent question-answering method based on structured semantic indexing and dual-layer memory enhancement, characterized in that: It includes: (1) Query preprocessing: Rewrite the user's original query, and extract key entities to form metadata filtering conditions; If it is recognized that the query involves code retrieval, generate hypothetical pseudocode for code-code pattern retrieval; (2) Agent-based multi-tool dynamic routing: Deploy a central routing Agent, analyze the user's query intention, and select a retrieval tool from a preset retrieval tool set according to the semantic matching degree; among them: the retrieval tool set includes a document retrieval tool, a code library retrieval tool, an FAQ retrieval tool, and an online retrieval tool; (3) Structured and semantic-enhanced index construction: Text data processing: First, perform segmentation according to the document title level. When there is no clear title or the text length exceeds the preset threshold, perform segmentation according to the maximum character length; non-text format files are converted into text format through a multi-modal parsing tool and then segmented; Code data processing: Use the Tree-sitter parser to convert the code file into an abstract syntax tree (AST), use the identified high-level semantic nodes as segmentation units, and extract code meta-information at the same time. Call a large language model to generate a functional description summary for each code segmentation block; Hybrid index construction: Adopt a hybrid retrieval mechanism that combines vector cosine similarity and the BM25 algorithm to calculate the retrieval score; (4) Adaptive context assembly: Set a length threshold Tmax. When the length L of the retrieval result is L < Tmax, return the full text; when L ≥ Tmax, use a large language model to refine the core information of the long text and extract the skeleton of the long code, retaining the key logical structure; (5) Double-layer memory management: Build a short-term scenario buffer for storing structured interaction logs, an asynchronous memory solidification module for regularly extracting long-term information, and a long-term semantic knowledge base for realizing persistent storage and retrieval of knowledge; (6) Data closed-loop and self-evolution: Record the complete link of each interaction and user feedback, generate positive and negative sample test data sets, and verify the answer consistency through regression testing during system update to achieve data-driven self-optimization.

2. The intelligent question-answering method based on structured semantic indexing and dual-layer memory enhancement according to claim 1, characterized in that: The key entities include programming languages, device models, date ranges, and technical terms; the metadata filtering conditions are implemented through the metadata filtering expressions of the vector library.

3. The intelligent question-answering method based on structured semantic indexing and dual-layer memory enhancement according to claim 1, characterized in that: The multi-modal parsing tools include mineru and paddleocr-vl; the non-text format files include PDF and PPT, and after conversion, a docx format file is generated for title parsing.

4. The intelligent question-answering method based on structured semantic indexing and dual-layer memory enhancement according to claim 1, characterized in that: The code meta-information includes file path, file type, module name, method name, start line number, end line number, and keywords; the code segmentation uses a regular expression capture function comment and syntax structure.

5. The intelligent question-answering method based on structured semantic indexing and dual-layer memory enhancement according to claim 1, characterized in that: The preset threshold can be dynamically adjusted according to the context window capacity of the large model; the maximum text length is 5000 characters and can be adjusted according to the actual scenario.

6. The intelligent question answering method based on structured semantic indexing and dual-layer memory enhancement according to claim 1, characterized in that: The structured interaction log includes the fields session_id, turn_index, timestamp, and interaction_data; wherein, the interaction_data field contains the user's original query, the rewritten query, the agent's thought process, the tool name, the tool output summary, and the final response.

7. The intelligent question answering method based on structured semantic indexing and dual-layer memory enhancement according to claim 1, characterized in that: The triggering conditions for asynchronous memory solidification are the end of the session, the system idle time exceeding a preset threshold, or archiving across days; the long-term information includes user technology stack preferences, core requirement characteristics, and key facts of historical interactions.

8. The intelligent question answering method based on structured semantic indexing and dual-layer memory enhancement according to claim 1, characterized in that: The positive samples are user likes and dislikes interaction records, which are extracted, rewritten, queried, retrieved, and finally answered to construct the dataset; the negative samples are user dislikes and dislikes interaction records, which are manually labeled with error types and then added to the dataset.

9. The intelligent question-answering method based on structured semantic indexing and dual-layer memory enhancement according to claim 1, characterized in that: The retrieval toolset is extended through a tool registry, which contains tool names, function descriptions, and parameter lists, and supports custom configurations according to business scenarios.

10. The intelligent question-answering method based on structured semantic indexing and dual-layer memory enhancement according to claim 1, characterized in that: The code skeleton extract retains the function signatures, parameter lists, and main control flow structures, while the specific implementation details are replaced with comment placeholders.