Retrieval question-answering system and method based on multi-source hierarchical context
By employing a multi-source hierarchical context design and modular architecture, the problems of fragmented conversational context, difficulty in multi-source content collaboration, and poor system scalability in online reading systems have been solved. This has enabled refined question answering and efficient resource management, thereby improving user experience and system scalability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHANGHAI XIHAN ARTIFICIAL INTELLIGENCE TECHNOLOGY CO LTD
- Filing Date
- 2025-12-24
- Publication Date
- 2026-04-21
AI Technical Summary
Existing online reading systems suffer from several problems, including a disconnect between conversational context and reading content, a lack of collaborative understanding across multiple books, limited retrieval and recommendation capabilities, poor performance due to reliance on external services for AI capabilities, and poor maintainability and scalability due to monolithic system architecture.
It adopts a multi-source layered context design, including a backend service module, a book tag management module, a conversation reading management module, a RAG question and answer processing module, and a member and token fine-grained control module. Through modular architecture and unified tag management, it achieves decoupling of data storage and business logic, and supports multi-tag filtering, multi-book mode question and answer, fine-grained token control, and streaming interaction.
It improves the accuracy and scenario adaptability of question and answer, enables fine-grained management of resources and permissions, and provides an efficient, scalable and consistent knowledge service solution.
Smart Images

Figure CN121901366A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of digital reading platform technology, and in particular to a retrieval question-answering system and method based on multi-source hierarchical context. Background Technology
[0002] With the development of digital reading platforms, managing multiple books on the same platform, synchronizing reading progress across devices, and using intelligent question-and-answer tools to aid content comprehension have become essential needs for users. Existing online reading systems generally include user management, book content storage, and basic search and tagging functions. However, when faced with the increasingly intelligent and in-depth needs of users, they reveal significant technical limitations and architectural flaws, mainly reflected in the following:
[0003] First, there is a severe disconnect between the conversational context and the reading content. While traditional platforms may integrate "Q&A" or "discussion forum" functions, these functions are often independent of the user's reading flow. The system cannot automatically perceive the specific book, chapter, or even paragraph that the user is currently reading. As a result, Q&A bots or community discussions cannot generate targeted answers based on the most relevant textual context. The user experience presents a disconnect between "reading" and "asking," significantly reducing the effectiveness of aiding comprehension.
[0004] Second, there is a lack of collaborative understanding and question-and-answer capabilities across multiple books. When users delve into a particular topic, they often need to consult multiple related works. Existing systems, when performing content retrieval or answering questions, can typically only operate based on a single book's database. They cannot dynamically identify user intent within a continuous dialogue session and extract and integrate information from multiple specified or related books in parallel. Consequently, they cannot provide comprehensive and integrated answers, limiting the breadth and depth of knowledge exploration.
[0005] Third, retrieval and recommendation capabilities are rudimentary and limited. Many systems rely on simple fuzzy matching (LIKE) in relational databases for their search functions, or only create full-text indexes for a few fields. Meanwhile, data such as book tags, user interest profiles, and library classification systems, which should enhance retrieval and recommendation effectiveness, are often scattered across different database tables or configuration files, lacking a unified and flexibly configurable management mechanism. This results in an inability to support accurate searches and personalized recommendations based on full-text content, multi-tag combinations, user behavior, and other dimensions, leading to high operation and maintenance costs and slow response times.
[0006] Fourth, AI capabilities rely excessively on external "black box" services, resulting in poor controllability and performance. To quickly achieve intelligent question answering, many platforms choose to completely outsource their core RAG (Retrieval Augmentation) or LLM (Large Language Model) workflows to external third-party platforms. This approach leads to long call chains, high latency, and reliance on external systems for concurrency, making internal debugging extremely difficult. More importantly, platforms struggle to precisely track token consumption for each interaction within their own systems, hindering deep integration and precise control with membership levels, points systems, or payment strategies, thus limiting business model design.
[0007] Fifth, the system architecture tends to be monolithic, resulting in poor maintainability and scalability. Traditional backend designs often employ a single-layer architecture with a "fat controller" directly connected to the database, where all business logic (users, books, search, question answering) is highly coupled. With the continuous addition of new demands such as AI, complex statistics, and real-time recommendations, the codebase becomes bloated and complex. Any modification or upgrade to a local function may trigger unforeseen side effects, resulting in heavy technical debt and making agile iteration and modular evolution difficult.
[0008] In summary, existing methods have significant shortcomings in areas such as context-aware, fine-grained question answering, multi-source content collaboration, unified tag management, and agile, scalable system architecture. Summary of the Invention
[0009] The purpose of this invention is to provide a retrieval question-answering system and method based on multi-source hierarchical context, which solves the technical problems of existing technologies that have obvious shortcomings in context-aware fine-grained question answering, multi-source content collaboration, unified tag management, and agile and scalable system architecture.
[0010] To achieve the above objectives, the present invention provides a retrieval question-answering system based on multi-source hierarchical context, including a backend service module, a book tag management module, a conversation reading management module, a RAG question-answering processing module, and a member and token fine-grained control module;
[0011] The book tag management module, the conversation reading management module, the RAG question and answer processing module, and the member and token fine control module are all connected to the backend service module.
[0012] The backend service module includes an API layer, a service layer, and a repository layer.
[0013] The API layer uses FastAPI to provide a JSON REST interface, routes are divided by functional domain, and encapsulation and error interception are performed through a unified response structure and a global exception handler.
[0014] The service layer is divided into independent services according to core functional domains, including membership service, book service, session service, token service and RAG orchestration service. The service layer decouples business logic from data storage by calling the repository layer interface.
[0015] The repository layer implements separate repository classes for user, book, session, tag, member, and token statistics. Data operations are performed based on SQLAlchemy ORM and PostgreSQL, and TSVECTOR, JSONB, and GIN / Trigram indexes are used to improve performance in complex retrieval scenarios.
[0016] The book tag management module includes a unified configuration unit, a data import and verification unit, and an advanced search unit.
[0017] The unified configuration unit defines the association between tag categories, user profile tags, and book metadata through YAML files.
[0018] The data import and verification unit supports automatically importing book and tag data from CSV and JSON, and performing consistency checks;
[0019] The data import and verification unit supports automatically importing book and tag data from CSV and JSON, and performing consistency checks;
[0020] The advanced search unit is based on full-text indexing to achieve multi-tag filtering, author fuzzy matching, year range query and library classification filtering, and records user search behavior for optimization.
[0021] The conversation reading management module includes a conversation and message storage unit, a multi-book mode management unit, and an active book and reading progress unit.
[0022] The session and message storage unit is used to manage user session history and message records;
[0023] The multi-book mode management unit supports switching between single-book mode and multi-book mode, and calls the corresponding RAG processing path based on the mode.
[0024] The active books and reading progress unit is used to maintain the list of active books selected by the user in the session and the reading position, and to dynamically determine the search scope in the RAG process.
[0025] The RAG question-answering processing module includes a question classification and chapter extraction unit, a context construction and length control unit, a multi-book parallel processing unit, an LLM call and streaming output unit, and an error unified processing unit.
[0026] The problem classification and chapter extraction unit uses LLM to classify user problems and extract related chapters;
[0027] The context building and length control unit combines book summaries, chapter lists, full text of chapters, and conversation history according to the question type, and automatically truncates them when the length threshold is exceeded.
[0028] The multi-book parallel processing unit processes the context of each active book in parallel in multi-book mode and supports a graceful degradation mechanism.
[0029] The LLM call and streaming output unit converts the LLM generation process into a standardized event stream through SSE and returns the status and response content in real time;
[0030] The unified error processing unit maps various types of errors into structured error events and outputs them through an event stream.
[0031] The member and token fine-grained control module includes a member plan management unit, a quota verification unit, a token statistics unit, and a management interface unit.
[0032] The membership program management unit defines the quotas and functional permissions for different membership levels and records membership change history;
[0033] The quota verification unit performs permission and quota checks before operations such as session creation and active book settings.
[0034] The Token statistics unit records the Token usage for each RAG call and supports summarizing and displaying usage by user and time. It also supports administrators in setting custom Token limits or unlimited limits for specific users and recording operation logs.
[0035] The management interface unit provides a query interface for user-side token usage.
[0036] This invention also provides a retrieval question-answering method based on multi-source hierarchical context, applicable to the retrieval question-answering system based on multi-source hierarchical context as described above.
[0037] Including the following:
[0038] Receive user query requests and route them to the appropriate service through the API layer;
[0039] The conversation reading management module determines the user's currently active books and reading mode.
[0040] User questions are categorized using the RAG orchestrator, and hierarchical contexts are built based on question type and the active book list.
[0041] The quota is verified based on the member and the Token control module. If it passes, the LLM is called to generate the answer; otherwise, a permission error is returned.
[0042] Returns the status events during the answer generation process and the final answer content in a streaming manner;
[0043] Record the token usage for this Q&A session and update user statistics.
[0044] This invention discloses a retrieval question-answering system and method based on multi-source hierarchical context. Through multi-source hierarchical context design, modular architecture, and unified tag management, this invention effectively solves the problems of insufficient context awareness, difficulty in multi-source content collaboration, scattered tag system, and weak system scalability in existing technologies. It significantly improves the accuracy and scenario adaptability of question answering, while realizing fine-grained control of resources and permissions, providing an efficient, scalable, and seamless integrated solution for knowledge services. Attached Figure Description
[0045] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below.
[0046] Figure 1 This is a flowchart of the retrieval and question answering method based on multi-source hierarchical context of the present invention. Detailed Implementation
[0047] The embodiments of the present invention are described in detail below. Examples of the embodiments are shown in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain the present invention, but should not be construed as limiting the present invention.
[0048] This invention provides a retrieval question-answering system based on multi-source hierarchical context, including a backend service module, a book tag management module, a conversation reading management module, a RAG question-answering processing module, and a member and token fine-grained control module;
[0049] The book tag management module, the conversation reading management module, the RAG question and answer processing module, and the member and token fine control module are all connected to the backend service module.
[0050] In this specific implementation, the present invention effectively solves the problems of insufficient context awareness, difficulty in multi-source content collaboration, fragmented tag system, and weak system scalability in the prior art through multi-source hierarchical context design, modular architecture, and unified tag management. It significantly improves the accuracy and scenario adaptability of question answering, while realizing fine-grained control of resources and permissions, providing an efficient, scalable, and consistent integrated solution for knowledge services.
[0051] Furthermore, the backend service module includes an API layer, a service layer, and a repository layer.
[0052] The API layer uses FastAPI to provide a JSON REST interface, routes are divided by functional domain, and encapsulation and error interception are performed through a unified response structure and a global exception handler.
[0053] The service layer is divided into independent services according to core functional domains, including membership service, book service, session service, token service and RAG orchestration service. The service layer decouples business logic from data storage by calling the repository layer interface.
[0054] The repository layer implements separate repository classes for user, book, session, tag, member, and token statistics. Data operations are performed based on SQLAlchemy ORM and PostgreSQL, and TSVECTOR, JSONB, and GIN / Trigram indexes are used to improve performance in complex retrieval scenarios.
[0055] Furthermore, the book tag management module includes a unified configuration unit, a data import and verification unit, and an advanced search unit:
[0056] The unified configuration unit defines the association between tag categories, user profile tags, and book metadata through YAML files.
[0057] The data import and verification unit supports automatically importing book and tag data from CSV and JSON, and performing consistency checks;
[0058] The advanced search unit is based on full-text indexing to achieve multi-tag filtering, author fuzzy matching, year range query and library classification filtering, and records user search behavior for optimization.
[0059] The conversation reading management module includes a conversation and message storage unit, a multi-book mode management unit, and an active book and reading progress unit.
[0060] The session and message storage unit is used to manage user session history and message records;
[0061] The multi-book mode management unit supports switching between single-book mode and multi-book mode, and calls the corresponding RAG processing path based on the mode.
[0062] The active books and reading progress unit is used to maintain the list of active books selected by the user in the session and the reading position, and to dynamically determine the search scope in the RAG process.
[0063] Specifically, by managing books and tags through unified configuration and import scripts, the consistency of online data and the ability to maintain it in batches are ensured.
[0064] 1. Content operations staff maintain CSV files in the `reference` directory, adding information such as the title, author, year, brief description, corresponding Chinese tag name, and library classification for new books.
[0065] 2. Run the `data.create_books_manifest` script to generate or update `config / books_manifest.yaml` based on the correspondence between the CSV and the JSON of the book content in `data / json`.
[0066] 3. When updating or adding tags, edit `config / tags.yaml` and then execute `utils.seed_tags` to synchronize the tag definitions to the database and update the mapping between tags and library categories.
[0067] 4. Run `utils.json_importer_optimized` or the parallel import script to import all book content and metadata into the database, automatically establishing the association between books and tags and categories.
[0068] 5. Through the tag interface and book interface of the API layer, the front end can obtain all tags, category trees, and tag details of a specific book.
[0069] Enhanced full-text search, tag filtering, author fuzzy matching, and year filtering enable advanced book search for administrators and end users.
[0070] 1. Users can enter search keywords on the front end and select filtering conditions such as tags, multi-tag matching mode (any / all), author, year range and library category.
[0071] 2. The front-end calls the `POST / books / search` interface, carrying the above parameters.
[0072] 3. After validating the parameters, the API layer calls `book_service.search_books`, which combines full-text search, tag filtering, author fuzzy matching, and year filtering based on `BookRepository` to perform paginated queries and sort the results.
[0073] 4. The query results are returned to the front end, including the book list, pagination information, and the filtering conditions used in this practical application.
[0074] 5. At the same time, the system writes the search request and its filtering conditions into the `search_queries` table for subsequent analysis and algorithm optimization.
[0075] By using a conversation model and an active book model, we can manage the reading context of a user within the same conversation and the combination of multiple books.
[0076] 1. After a user logs in, a new session is created. The system creates a new record in the `sessions` table and initializes `active_book_mode` (default single book).
[0077] 2. When a user selects one or more books as the active books for the current session on the front end, the front end calls the relevant API to update the `user_active_book` or `user_active_books` table.
[0078] 3. When a user initiates a RAG Q&A request, the RAG orchestrator first calls the backend session API to obtain the current session details and its `active_book_mode`, and then retrieves the list of active books.
[0079] 4. For the multi-book mode, the system pulls the structural information of multiple books in parallel and integrates the content of these books in the subsequent context construction.
[0080] 5. Reading progress (current chapter and section) is saved in the active book record so that you can continue reading and ask questions across devices and sessions.
[0081] Furthermore, the RAG question-answering processing module includes a question classification and chapter extraction unit, a context construction and length control unit, a multi-book parallel processing unit, an LLM call and streaming output unit, and an error unified processing unit;
[0082] The problem classification and chapter extraction unit uses LLM to classify user problems and extract related chapters;
[0083] The context building and length control unit combines book summaries, chapter lists, full text of chapters, and conversation history according to the question type, and automatically truncates them when the length threshold is exceeded.
[0084] The multi-book parallel processing unit processes the context of each active book in parallel in multi-book mode and supports a graceful degradation mechanism.
[0085] The LLM call and streaming output unit converts the LLM generation process into a standardized event stream through SSE and returns the status and response content in real time;
[0086] The unified error processing unit maps various types of errors into structured error events and outputs them through an event stream.
[0087] Furthermore, the entire RAG process is implemented on the backend, rather than relying on external platforms, combining conversation history and active book information to provide users with streaming multi-turn Q&A.
[0088] 1. A user opens a session on the front end and enters a question. The front end then calls `POST / api / v1 / rag / v2 / chat / stream`, along with the `session_id` and the authentication token.
[0089] 2. The RAG orchestrator first calls the session message interface to retrieve the most recent session history and format it as dialogue text.
[0090] 3. The RAG orchestrator calls the session details and active book interfaces to determine whether the current mode is single-book or multi-book and obtains a list of active book IDs.
[0091] 4. In single-book mode, the RAG editor pulls the book's metadata, chapter list, and chapter number; in multi-book mode, the above operations are performed in parallel for each book.
[0092] 5. Use LLM to perform problem classification. If it is a content-related problem, then further call LLM to extract the most relevant chapter number.
[0093] 6. In the content class path, the system reads the content of the specified chapter from the backend and constructs a context including a book summary, chapter list, chapter content, session history, and current question using `ContextBuilder`; the overview class path constructs a lightweight context that does not contain the full text of the chapter.
[0094] 7. The RAG orchestrator calls the LLM streaming function to generate answers, and uses statistics to package intermediate states (such as "extracting chapters" and "generating answers") with tokens into a unified structure, and sends it to the front end via SSE stream.
[0095] 8. At the end, the RAG orchestrator returns the book ID used, path (overview / content), chapter number (if any), and token statistics in the `done` event for front-end display and back-end token subsystem recording.
[0096] Furthermore, the membership and token fine-grained control module includes a membership plan management unit, a quota verification unit, a token statistics unit, and a management interface unit:
[0097] The membership program management unit defines the quotas and functional permissions for different membership levels and records membership change history;
[0098] The quota verification unit performs permission and quota checks before operations such as session creation and active book settings.
[0099] The Token statistics unit records the Token usage for each RAG call and supports summarizing and displaying usage by user and time. It also supports administrators in setting custom Token limits or unlimited limits for specific users and recording operation logs.
[0100] The management interface unit provides a query interface for user-side token usage.
[0101] Specifically, it implements granular token statistics and quota control for RAG calls locally, providing differentiated experiences for different membership levels and VIP users, while providing administrators with visual monitoring and on / off functionality.
[0102] 1. After a user logs into the system, the service layer retrieves the user's current membership plan through `membership_service.get_effective_user_membership` (if there is no explicit record, the implicit basic plan will be used automatically).
[0103] 2. Before creating a session or setting multiple active books, the business logic calls `validate_session_limit`, `validate_multiple_books_feature`, and `validate_active_books_limit`. If the user's current membership plan does not allow certain operations, an error message is returned directly.
[0104] 3. After each RAG call is completed, the RAG orchestrator passes the returned Token usage data to the `token_service`. This service records the details of each call in `TokenUsageLog` and updates the daily and cumulative statistics fields of the corresponding user in `UserTokenStatistics`.
[0105] 4. Before updating statistics, `token_service` determines whether a limit or exemption is needed based on the master switch in `SystemSettings` and the user override settings in `UserTokenOverride`.
[0106] 5. Users can obtain current usage status, remaining daily quota, and historical data through a dedicated Token query interface; administrators can call the management interface to enable / disable Token restrictions, view global statistics, and set or modify the coverage policy for a specific user.
[0107] The beneficial effects of this invention are as follows:
[0108] 1. RAG context construction that is more closely integrated with the reading scenario;
[0109] By explicitly modeling a hierarchical structure of "book → chapter → section → paragraph" in the backend and using this structure to classify questions and locate chapters in the RAG process, this invention significantly improves the relevance of answers to the user's current reading position.
[0110] 2. Supports high-concurrency native RAG services in both single-book and multi-book modes;
[0111] By asynchronously and in parallel fetching information and chapter content from multiple books and orchestrating LLM calls locally, this invention can support hundreds of concurrent users without the need for an external RAG platform, and maintain a response time close to that of the single-book mode in multi-book mode.
[0112] 3. Unified configuration and automatic import of tag and book management;
[0113] By using `tags.yaml` and `books_manifest.yaml` as the single source of truth, along with import and verification scripts, we have achieved automated maintenance of tag definitions and book-tag mappings, reducing the risk of manual configuration errors and facilitating large-scale content operations.
[0114] 4. Detailed token statistics and membership control capabilities;
[0115] This invention establishes detailed logs and aggregated statistical models for token usage in the database, and combines them with membership programs, system master switches, and per-user coverage strategies, enabling the platform to visualize and controllably manage AI call costs while ensuring user experience.
[0116] 5. A clearly layered and easily evolving backend architecture;
[0117] By decoupling the API layer, service layer, and repository layer, and maintaining compatibility with the interface return format and history, this invention successfully introduces native RAG, multidimensional search, and Token system without disrupting the existing front-end and test cases, providing a solid foundation for subsequent new features and performance optimizations.
[0118] 6. Unified error handling and a fluid interactive experience;
[0119] This invention simplifies the front-end's processing logic for multi-stage AI processes by unifying error formats and SSE event stream output. It also provides clear recoverability prompts in cases of network anomalies, back-end errors, and LLM timeouts, thereby improving the overall user experience and system observability.
[0120] Using a multi-source hierarchical context-based retrieval question-answering system as described in this embodiment, the present invention effectively solves the problems of insufficient context awareness, difficulty in multi-source content collaboration, scattered tag system, and weak system scalability in existing technologies through multi-source hierarchical context design, modular architecture, and unified tag management. It significantly improves the accuracy and scenario adaptability of question answering, while realizing refined management of resources and permissions, providing an efficient, scalable, and seamless integrated solution for knowledge services.
[0121] Please see Figure 1 , Figure 1 This is a flowchart of the retrieval and question answering method based on multi-source hierarchical context of the present invention.
[0122] This invention also provides a retrieval question-answering method based on multi-source hierarchical context, applicable to the retrieval question-answering system based on multi-source hierarchical context as described above.
[0123] Including the following:
[0124] Receive user query requests and route them to the appropriate service through the API layer;
[0125] The conversation reading management module determines the user's currently active books and reading mode.
[0126] User questions are categorized using the RAG orchestrator, and hierarchical contexts are built based on question type and the active book list.
[0127] The quota is verified based on the member and the Token control module. If it passes, the LLM is called to generate the answer; otherwise, a permission error is returned.
[0128] Returns the status events during the answer generation process and the final answer content in a streaming manner;
[0129] Record the token usage for this Q&A session and update user statistics.
[0130] The above-disclosed embodiments are merely one or more preferred embodiments of this application and should not be construed as limiting the scope of this application. Those skilled in the art can understand that implementing all or part of the above embodiments and making equivalent changes in accordance with the claims of this application still fall within the scope of this application.
Claims
1. A retrieval and question-answering system based on multi-source hierarchical context, characterized in that, It includes a backend service module, a book tag management module, a conversation reading management module, a RAG question and answer processing module, and a membership and token fine-grained control module; The book tag management module, the conversation reading management module, the RAG question and answer processing module, and the member and token fine control module are all connected to the backend service module.
2. The retrieval and question-answering system based on multi-source hierarchical context as described in claim 1, characterized in that, The backend service module includes an API layer, a service layer, and a repository layer; The API layer uses FastAPI to provide a JSON REST interface, routes are divided by functional domain, and encapsulation and error interception are performed through a unified response structure and a global exception handler. The service layer is divided into independent services according to core functional domains, including membership service, book service, session service, token service and RAG orchestration service. The service layer decouples business logic from data storage by calling the repository layer interface. The repository layer implements separate repository classes for user, book, session, tag, member, and token statistics. Data operations are performed based on SQLAlchemy ORM and PostgreSQL, and TSVECTOR, JSONB, and GIN / Trigram indexes are used to improve performance in complex retrieval scenarios.
3. The retrieval and question-answering system based on multi-source hierarchical context as described in claim 2, characterized in that, The book tag management module includes a unified configuration unit, a data import and verification unit, and an advanced search unit: The unified configuration unit defines the association between tag categories, user profile tags, and book metadata through YAML files. The data import and verification unit supports automatically importing book and tag data from CSV and JSON, and performing consistency checks; The advanced search unit is based on full-text indexing to achieve multi-tag filtering, author fuzzy matching, year range query and library classification filtering, and records user search behavior for optimization.
4. The retrieval and question-answering system based on multi-source hierarchical context as described in claim 3, characterized in that, The conversation reading management module includes a conversation and message storage unit, a multi-book mode management unit, and an active book and reading progress unit. The session and message storage unit is used to manage user session history and message records; The multi-book mode management unit supports switching between single-book mode and multi-book mode, and calls the corresponding RAG processing path based on the mode. The active books and reading progress unit is used to maintain the list of active books selected by the user in the session and the reading position, and to dynamically determine the search scope in the RAG process.
5. The retrieval and question-answering system based on multi-source hierarchical context as described in claim 4, characterized in that, The RAG question-and-answer processing module includes a question classification and chapter extraction unit, a context construction and length control unit, a multi-book parallel processing unit, an LLM call and streaming output unit, and an error unified processing unit. The problem classification and chapter extraction unit uses LLM to classify user problems and extract related chapters; The context building and length control unit combines book summaries, chapter lists, full text of chapters, and conversation history according to the question type, and automatically truncates them when the length threshold is exceeded. The multi-book parallel processing unit processes the context of each active book in parallel in multi-book mode and supports a graceful degradation mechanism. The LLM call and streaming output unit converts the LLM generation process into a standardized event stream through SSE and returns the status and response content in real time; The unified error processing unit maps various types of errors into structured error events and outputs them through an event stream.
6. The retrieval and question-answering system based on multi-source hierarchical context as described in claim 5, characterized in that, The member and token fine-grained control module includes a member plan management unit, a quota verification unit, a token statistics unit, and a management interface unit: The membership program management unit defines the quotas and functional permissions for different membership levels and records membership change history; The quota verification unit performs permission and quota checks before operations such as session creation and active book settings. The Token statistics unit records the Token usage for each RAG call and supports summarizing and displaying usage by user and time. It also supports administrators in setting custom Token limits or unlimited limits for specific users and recording operation logs. The management interface unit provides a query interface for user-side token usage.
7. A retrieval and question answering method based on multi-source hierarchical context, applied to the retrieval and question answering system based on multi-source hierarchical context as described in claim 6, characterized in that, Including the following: Receive user query requests and route them to the appropriate service through the API layer; The conversation reading management module determines the user's currently active books and reading mode. User questions are categorized using the RAG orchestrator, and hierarchical contexts are built based on question type and the active book list. The quota is verified based on the member and the Token control module. If it passes, the LLM is called to generate the answer; otherwise, a permission error is returned. Returns the status events during the answer generation process and the final answer content in a streaming manner; Record the token usage for this Q&A session and update user statistics.