Construction method, system and equipment of off-line pollution and carbon reduction criterion question and answer library based on large language model and medium
By preprocessing and vectorizing the policy texts on pollution reduction and carbon reduction, and combining them with a question-and-answer system deployed locally using a large language model, the problem of efficient and accurate policy text retrieval and question-and-answer in a local environment was solved, achieving efficient, secure, and reliable policy question-and-answer services.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING INST OF TECH
- Filing Date
- 2025-10-16
- Publication Date
- 2026-04-17
AI Technical Summary
Existing technologies struggle to efficiently and accurately process and retrieve unstructured policy text data in the field of pollution reduction and carbon reduction in a local environment, and lack question-and-answer systems that support FAISS vector indexing and WebSocket interaction.
By collecting and preprocessing textual data on pollution reduction and carbon reduction, standardized text blocks are generated. These blocks are then converted into vector representations using a semantic embedding model, and a vector index is constructed. Combined with a large language model, the system is deployed locally to achieve efficient semantic retrieval and question-answering generation, supporting incremental updates and data security.
It enables efficient, secure, and accurate policy Q&A services in a local environment, improving response speed and system stability, supporting dynamic updates and version management, and ensuring data security and smooth interaction.
Smart Images

Figure CN121880355A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence, environmental policy, and RAG knowledge base technology, specifically to a method, system, device, and medium for constructing an offline question-and-answer database of pollution reduction and carbon reduction guidelines based on a large language model. Background Technology
[0002] Against the backdrop of the ongoing implementation of policies aimed at synergistically enhancing pollution and carbon reduction, government departments, research institutions, and enterprises are placing higher demands on the real-time and professional aspects of obtaining and interpreting policy information. However, due to the complexity and dense terminology of such policy texts, traditional information retrieval methods are insufficient to meet the needs for efficient, accurate, and structured responses.
[0003] In recent years, the rapid development of Large Language Models (LLMs) has provided new insights into policy understanding and intelligent question answering. While mainstream cloud-based large models such as ChatGPT, DeepSeek, and Gemini excel in question-answer generation, their direct application in the policy domain faces limitations due to concerns about data security, response timeliness, and customization capabilities. On the one hand, government systems and commercial entities have a rigid demand for local data processing and data security; on the other hand, existing large model-based question answering systems largely rely on general corpora and lack targeted training and semantic indexing capabilities for specialized policy texts such as "pollution reduction and carbon reduction."
[0004] Meanwhile, although some open-source models support local deployment, they suffer from problems such as complex integration and high development threshold in the processes of embedding generation, semantic retrieval, and context response generation, making it difficult to form an integrated, interactive, and fast-response knowledge question-answering system.
[0005] Currently, there is a lack of a "pollution reduction and carbon reduction" policy question-and-answer library solution that can be deployed locally offline, supports the embedding of structured policy knowledge, and enables efficient semantic retrieval and streaming answer generation. In particular, there is a gap in the unified architecture that combines high-performance local models such as DeepSeek, supports the FAISS vector indexing mechanism, and has interactive WebSocket capabilities. Summary of the Invention
[0006] In view of the above-mentioned problems, the present invention is proposed.
[0007] Therefore, the technical problem solved by this invention is: how to structure and index large-scale unstructured policy text data in the field of pollution reduction and carbon reduction without relying on the cloud, through localized semantic embedding and vector retrieval technology, to achieve efficient local semantic retrieval, question and answer generation and dynamic updates, thereby constructing an offline question and answer library system that can accurately match user questions and generate answers.
[0008] To address the aforementioned technical problems, this invention provides the following technical solution: a method for constructing an offline question-and-answer database of pollution reduction and carbon reduction criteria based on a large language model, comprising, Collect text data related to pollution reduction and carbon reduction, and preprocess the text data to generate a standardized set of text blocks; convert each text block in the set into a vector representation using a semantic embedding model, and construct and store the corresponding vector index and text block set; retrieve vectors with high similarity and return their index, distance, and text block content to improve response speed and facilitate subsequent retrieval; receive user-input questions, convert the questions into query vectors, and retrieve the text blocks most similar to the query vectors from the vector indexes; perform semantic matching between the most similar text blocks and the questions using the large language model to generate an answer; users can choose whether to update the question-and-answer database based on dialogue information.
[0009] As a preferred embodiment of the method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model as described in this invention, the preprocessing includes: identifying non-text elements in the text data; deleting the identified non-text elements, dividing the remaining text into several text blocks with complete semantic units; uniformly encoding the text blocks and storing them to form a standardized set of text blocks.
[0010] As a preferred embodiment of the method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer library based on a large language model as described in this invention, the step of uniformly encoding and storing text blocks to form a standardized text block set includes: generating identification information for each text block that can identify its source and location; binding the identification information with the corresponding text block to form a structured data record; storing the structured data record in a local file to form a searchable text block set.
[0011] As a preferred embodiment of the method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer library based on a large language model as described in this invention, the following steps are taken: each text block in the processed text block set is converted into a vector representation through a semantic embedding model, and the corresponding vector index and text block set are constructed and stored, and the text blocks are converted into dense vectors; the dense vectors are subjected to dimensional consistency checks and numerical range validity checks; after passing the checks, the dense vectors are stored in the vector index.
[0012] As a preferred embodiment of the method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model as described in this invention, the following steps are taken: a similarity metric is pre-calculated on the dense vectors; a corresponding vector retrieval index structure is constructed based on the similarity metric pre-calculation results to improve response speed and facilitate subsequent retrieval.
[0013] As a preferred embodiment of the method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer library based on a large language model as described in this invention, the vector index and the text block set are stored locally in the form of independent binary files, and a memory mapping method is used during loading. After loading is completed, it is checked whether the number of entries in the text block set and the vector index are equal.
[0014] The beneficial effects of this preferred technical solution are as follows: by storing the vector index and the text block set locally as independent binary files and using memory mapping during loading, the efficiency of large-scale data loading can be improved, memory usage can be reduced, and repeated reading and decoding can be avoided; at the same time, checking whether the number of entries in the two is equal after loading can effectively avoid data inconsistency or loss, and improve the stability and reliability of the question-and-answer database system.
[0015] As a preferred embodiment of the method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model as described in this invention, when updating the question-and-answer database, the difference between the semantic vector of the newly added text block and the existing vector is calculated, and the difference is compared with the existing text block to determine whether it is a duplicate text block. If it is determined to be non-duplicate, the newly added text block and its vector are added to the question-and-answer database, and an incrementing version number is assigned to the updated question-and-answer database.
[0016] The beneficial effects of this preferred technical solution are as follows: During the question-and-answer database update process, by comparing the similarity between the semantic vector of the newly added text block and the existing vector, duplicate text blocks can be effectively identified and excluded, avoiding the accumulation of redundant data; at the same time, by assigning an incrementing version number to the updated question-and-answer database, version management is realized, which facilitates subsequent version tracking and rollback operations, and improves the maintainability of the system and the efficiency of data management.
[0017] This invention provides a system for constructing an offline question-and-answer database of pollution reduction and carbon reduction criteria based on a large language model.
[0018] To address the aforementioned technical problems, this invention provides the following technical solution: a system for constructing an offline question-and-answer database for pollution reduction and carbon reduction principles based on a large language model, comprising: a data collection and preprocessing module for collecting text data related to pollution reduction and carbon reduction, preprocessing the text data, and generating a standardized set of text blocks; a vector index construction module for converting each text block in the set of text blocks into a vector representation through a semantic embedding model, and constructing and storing the corresponding vector index and text block set; a question-and-answer generation module for performing semantic analysis on the set of text blocks using a locally deployed large language model, generating question-and-answer records corresponding to the text blocks, and storing them in a question-and-answer database; a question-and-answer matching module for receiving user-input questions, converting the questions into query vectors, retrieving the text block most similar to the query vector from the vector index, and performing semantic matching between the most similar text block and the question using the large language model to generate an answer; and a system feedback and update module for updating the question-and-answer database based on user feedback information.
[0019] The present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, characterized in that the processor executes the computer program to implement the steps of the method for constructing an offline pollution reduction and carbon reduction criterion question-and-answer database based on a large language model.
[0020] The present invention provides a computer-readable storage medium storing a computer program thereon, characterized in that, when the computer program is executed by a processor, it implements the steps of the method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer library based on a large language model.
[0021] The beneficial effects of this invention are as follows: By employing localized semantic embedding and vector retrieval mechanisms, unstructured policy texts in the field of pollution reduction and carbon reduction are transformed into standardized vector indexes, significantly improving retrieval accuracy and response speed; by combining a locally deployed large language model with question-and-answer record generation and semantic matching algorithms, high-quality question-and-answer for professional policy questions is achieved, avoiding cloud dependency and ensuring data security; the reliability and maintenance convenience of the question-and-answer database are improved by utilizing a standardized text block storage format and vector consistency verification mechanism; incremental update and deduplication mechanisms are introduced to support dynamic expansion and version management of the knowledge base, ensuring the timeliness and completeness of the question-and-answer database; and the combination of streaming generation and WebSocket interaction methods enables users to obtain answers in real time, improving the smoothness and experience of human-computer interaction. Attached Figure Description
[0022] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 The above is a flowchart illustrating the overall process of constructing an offline question-and-answer database of pollution reduction and carbon reduction criteria based on a large language model, as provided in one embodiment of the present invention.
[0024] Figure 2 This is a structural principle diagram of a method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model, provided as an embodiment of the present invention.
[0025] Figure 3 This is a web interface and answer login diagram of a method for constructing an offline pollution reduction and carbon reduction criteria question and answer database based on a large language model, as provided in one embodiment of the present invention.
[0026] Figure 4 The image shows a web interface and example answers for a method of constructing an offline pollution reduction and carbon reduction criteria question and answer database based on a large language model, as provided in one embodiment of the present invention. Figure 5 This is another example diagram of the web interface and answers for a method of constructing an offline pollution reduction and carbon reduction criteria question and answer library based on a large language model, provided as an embodiment of the present invention. Figure 6 This is a question-and-answer process diagram of a method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model, provided as an embodiment of the present invention. Detailed Implementation
[0027] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0028] Example 1, referring to Figure 1 This is one embodiment of the present invention, which provides a method for constructing an offline question-and-answer database of pollution reduction and carbon reduction criteria based on a large language model, including: S101: Data preparation and standardization: Collect text data related to pollution reduction and carbon reduction, and preprocess the text data to generate a standardized set of text blocks; S102: Vector index construction, converting each text block in the text block set into a vector representation through a semantic embedding model, and constructing and storing the corresponding vector index and text block set; S103: Semantic retrieval and question answering generation: Receive a question input by the user, convert the question into a query vector, and retrieve the text block most similar to the query vector from the vector index; perform semantic matching between the most similar text block and the question using the large language model to generate an answer; S104: System feedback and incremental update, used to update the question and answer database in a versioned manner based on user feedback or new data.
[0029] In practical applications, policy texts in the field of pollution reduction and carbon reduction often suffer from problems such as being voluminous, structurally irregular, using complex terminology, and being frequently updated, making it difficult for users to efficiently obtain content relevant to their needs. Existing keyword-based retrieval methods cannot accurately understand the semantics of user questions, resulting in insufficient relevance and professionalism in search results. Furthermore, reliance on cloud services poses risks such as data leakage and network latency. This embodiment addresses these issues by standardizing and preprocessing policy texts into structured blocks, transforming unstructured text data into a corpus that is easy to model. A local semantic embedding model is then used to represent text blocks as vectors, achieving efficient semantic indexing. Combined with a locally deployed large language model, human-computer dialogue is completed, supporting the provision of professional, fast, and leak-free intelligent question-and-answer services to users in an offline environment. This overcomes the problems of low retrieval accuracy, slow response, and poor data security in existing technologies.
[0030] This embodiment establishes a complete method for constructing an offline question-and-answer database for pollution reduction and carbon reduction guidelines through steps such as data collection, preprocessing, embedding and vectorization, retrieval and matching, question-and-answer generation, and update feedback. Its specific process covers the entire chain from data acquisition to knowledge base construction, user interaction, and iterative updates of the question-and-answer database. The logical connections between each step are clear: preprocessing improves text quality and consistency; vectorization and indexing enable efficient semantic retrieval; question-and-answer generation and semantic matching ensure the accuracy and professionalism of the answers; and the feedback update mechanism guarantees the system's timeliness and maintainability.
[0031] In this embodiment, the text preprocessing process may include removing non-text elements such as headers, footers, page numbers, and watermarks, and unifying the character encoding format to UTF-8. When segmenting text into blocks, semantically reasonable segmentation can be performed according to a preset character length range (e.g., 300-500 characters), and the source file name, page number, and block sequence number are recorded during storage to support traceability. The vectors generated by the semantic embedding model are fixed-length dense vectors, and a verification mechanism ensures dimensional consistency and numerical validity after generation. When the question-answering database is updated, the semantic similarity of newly added text blocks can be calculated to determine whether they are duplicates, and a new version number can be assigned to the updated database for management. The above parameters and mechanisms are only examples and can be adjusted and optimized according to actual needs.
[0032] Example 2, an embodiment of the present invention, provides a method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model, based on the previous embodiment, including: Step S101, data preparation and standardization, involves collecting text data related to pollution reduction and carbon reduction, and preprocessing the text data to generate a standardized set of text blocks, including the following steps A1-A3: A1: Identify non-text elements in text data; A2: After deleting the identified non-text elements, the remaining text is divided into several text blocks with complete semantic units; A3: After uniformly encoding the text blocks, store the text blocks to form a standardized set of text blocks.
[0033] It should be noted that, when storing the text blocks, corresponding identification information is established for each text block. The identification information includes generating identification information for each text block that can identify its source and location; binding the identification information with the corresponding text block to form a structured data record; storing the structured data record in a local file to form a searchable set of text blocks.
[0034] In this embodiment of the application, in step A3, the unified encoding can be stored using a unified UTF-8 encoding format. First, by uniformly converting all characters in the text data through UTF-8 encoding, it can be compatible with Chinese, English, and various special symbols, thereby ensuring the consistency of the encoding format of text data from different sources.
[0035] In an optional embodiment of the present invention, the unified encoding may also be selected to use the Unicode encoding format for storage. By using the Unicode encoding scheme, a globally unified character set identifier can be assigned to each text block, avoiding the conversion problem between different encodings and improving the speed of text retrieval and retrieval.
[0036] In another optional embodiment of the present invention, the unified encoding can also be stored using a Base64-based encoding format. Specifically, the text block content is first converted into a binary byte stream according to a preset character set, and then the byte stream is Base64 encoded before storage.
[0037] Further, step S102, vector index construction, involves converting each text block in the text block set into a vector representation using a semantic embedding model, and constructing and storing the corresponding vector index and text block set. The conversion of the semantic embedding model into a vector representation includes the following steps B1-B3: B1: Convert text blocks into fixed-length dense vectors using a semantic embedding model; B2: Perform dimension consistency checks and numerical range validity checks on dense vectors; B3: After the verification is passed, the dense vector is stored in the vector index.
[0038] In this embodiment, step B3 involves constructing the vector index using a vector retrieval framework based on FAISS (Facebook AI Similarity Search). Specifically, the preprocessed and embedded text block vectors are organized into a two-dimensional matrix, which is then loaded into the FAISS IndexFlatL2 index structure. The IndexFlatL2 index uses Euclidean distance as a metric to calculate the distance between vectors for similarity retrieval. After completion, the generated index data structure is saved as a local file, and the text block set is saved as a separate file. During the system loading phase, both the index file and the text block file are loaded simultaneously, and a consistency check for the number of entries is performed to ensure data correctness. During the query phase, the query vector generated by the user's question is input into the FAISS index. Nearest neighbor search returns the index numbers of one or more text blocks that are most similar to the query vector, and the corresponding text block content is then extracted from the text block set.
[0039] In an optional embodiment of the present invention, the vector index is constructed using a vector retrieval framework based on a multi-level graph structure. Specifically, the embedding vectors of text blocks are sequentially inserted into a hierarchical graph structure, with each node corresponding to a text block vector, and a multi-level graph is formed by dynamically maintaining the edge connections between nodes. The number of nodes in each layer decreases progressively, and the node degree and jump probability are controlled by predefined search parameters. During the query phase, starting from the highest level, the most similar node is selected as the starting point based on the distance between the query vector and each node, and the search proceeds downwards layer by layer, updating the candidate node set. Finally, the index numbers of one or more most similar text blocks are obtained at the bottom level.
[0040] In another optional embodiment of the present invention, the vector index is constructed using a vector retrieval framework based on a combination of cluster centers and inverted lists. Specifically, firstly, the embedding vectors of all text blocks are divided into several clusters, each represented by a cluster center; then, the text block vectors within each cluster are stored in their respective inverted lists. During the query phase, the distance between the query vector and each cluster center is first calculated, and several clusters with the smallest distance are selected as candidate clusters; subsequently, the similarity with the query vector is further calculated in the inverted lists within these candidate clusters, and the index numbers of one or more most similar text blocks are selected.
[0041] Furthermore, step B1, which transforms text blocks into fixed-length dense vectors using a semantic embedding model, includes the following steps B11-B13: B11: Performs uniform formatting on the text block content and inputs it into the locally deployed semantic embedding model interface; B12: Receives a fixed-length dense vector returned from the semantic embedding model interface, and records the state information during the transformation process; B13: Perform pre-calculation of similarity measurement on the generated dense vectors, including calculating the Euclidean distance between the dense vectors to assess the degree of similarity, constructing a corresponding vector retrieval index structure based on the calculation results, and establishing a unique identifier for each vector for subsequent retrieval.
[0042] Furthermore, step B2 performs a consistency check on the dense vectors, as well as a consistency check within the validity test of the numerical range. The validity test of the numerical range includes the following steps B21-B23: B21: Check whether the dimensions of the dense vectors meet the predetermined criteria; B22: Check if the values in a dense vector contain illegal values, such as NaN or Inf; B23: Check whether the numerical range of dense vectors is within the legal range, save the check results to the log file, and mark or remove vectors that do not meet the specifications.
[0043] In this embodiment, step B2 involves pre-calculating the similarity metric of dense vectors using Euclidean distance to check dimensional consistency. Specifically, the geometric distance between two vectors is obtained by calculating the square root of the sum of squares of the differences between corresponding elements of the vector dimensions.
[0044] In an optional embodiment of the present invention, the dimensional consistency check of dense vectors can also be performed by pre-compiling a similarity metric using cosine similarity. Specifically, the similarity between two dense vectors is measured by calculating the cosine of the angle between them.
[0045] In another optional embodiment of the present invention, the dimensional consistency check of dense vectors is performed based on pre-computed similarity metrics, and a tree-like index structure (such as a KD-tree) is constructed to efficiently organize and store dense vectors. Specifically, the vector space is partitioned layer by layer to construct a tree-like index, and similar vectors are quickly located along the tree structure during queries.
[0046] In another optional embodiment of the present invention, performing dimensional consistency checks on dense vectors can also involve storing the pre-computed similarity measurement results as a graph structure (such as a proximity graph or HNSW graph). Specifically, by recording the relationship between each vector and several of its nearest neighbors, a dense graph structure is formed, enabling the query process to quickly locate similar vectors through the nodes on the graph.
[0047] Furthermore, after step B3 passes the verification, storing the dense vector in the vector index includes the following steps B31-B33: B31: Bind dense vectors to corresponding text block identifiers to form structured storage units; B32: Store the bound dense vectors and text block sets locally as separate binary files; B33: During loading, memory mapping is used to improve reading efficiency, and after loading is completed, the number of text block sets and vector index entries are checked to ensure data consistency.
[0048] In this embodiment of the application, in B32, the text block set is stored using the PKL file format, and the index information is stored using the index file format. Storing the text block set and the index information separately improves loading speed and facilitates information updates and maintenance.
[0049] In an optional embodiment of the present invention, the text block set can be stored using a binary serialization method, such as standardized storage using the Pickle (PKL) format. The text blocks and their corresponding identification information are serialized as a whole into a binary file and stored locally. During loading, they are directly deserialized and loaded into memory, which can effectively improve the reading efficiency during system startup and runtime, while also facilitating data migration and backup operations.
[0050] In another optional embodiment of the present invention, the text block set is stored in a standardized JSONL (JSONLines) format. The specific steps are as follows: The system sequentially traverses the preprocessed text block set and extracts the main text content, source file name, page number, and sequence number in the original text for each text block; the extracted information is encapsulated into a standardized JSON object, ensuring that field names and data types conform to a unified standard; each text block's JSON object is appended to the target file as text, one line at a time, generating a JSONL format file; after writing is complete, the generated JSONL file is checked for integrity to verify that the total number of lines matches the total number of text blocks, confirming that file storage is complete.
[0051] Further, in step S103, semantic retrieval and question-answering generation, a question input by the user is received, the question is converted into a query vector, and the text block most similar to the query vector is retrieved from the vector index; the most similar text block and the question are semantically matched using the large language model to generate an answer.
[0052] In this embodiment, in step S103, the locally deployed large language model adopts the deepseek-R1 large language model. This model serves as the language understanding and generation engine for Chinese policy question-and-answer scenarios, deployed on a local server and providing services through a dedicated inference interface. Specifically, during the user query phase, the system merges the most similar text blocks retrieved with the user's question to construct prompt words, and calls the local deepseek-R1 model interface to generate a natural language answer that conforms to semantic logic. The deepseek-R1 model runs in an offline environment, supports batch calls, streaming returns, and detection mechanisms, and its weight file and inference logic are all stored locally, ensuring data security and efficient response capabilities.
[0053] In an optional embodiment of the present invention, the locally deployed large language model employs a question-answering model based on BERT and its extended architecture. After local fine-tuning, this model possesses the ability to understand and answer questions related to pollution reduction and carbon reduction policy texts. Specifically, during the knowledge base construction phase, the local BERT model performs sentence-level understanding and feature extraction on each text block, automatically generating question-answer pairs and writing them into the question-answering database. During the user query phase, the most similar text block is combined with the user's question and input into the local BERT question-answering model to generate a targeted answer. This model is deployed on a local inference engine using the ONNX format and provides an inference interface in the application to support question-answering services.
[0054] In another optional embodiment of the present invention, the locally deployed large language model adopts a local inference version based on the GPT architecture. This version is fine-tuned based on a large-scale publicly available Chinese corpus and incrementally trained on a corpus of pollution reduction and carbon reduction policies. Specifically, in the knowledge base construction phase, the local GPT model is invoked to perform semantic extraction and rewriting for each text block, forming structured questions and answers, which are then stored in a question-and-answer database. In the user query phase, the retrieved text blocks and the user's question are concatenated into contextual prompts, which are then fed into the local GPT model for language generation to obtain the final answer. The GPT model is encapsulated and runs on a local server using containerization technology, supporting concurrent calls, version rollback, and dynamic resource allocation, and is equipped with a local caching mechanism to accelerate response speed.
[0055] Furthermore, the S104 system feedback and incremental update is used to version update the question and answer database based on user feedback or new data, including the following steps, C1-C3; C1: When updating the question-and-answer database, the difference between the semantic vector of the newly added text block and the existing vector is calculated; C2: Compare with existing text blocks to determine if it is a duplicate text block; C3: After determining that the text block is not a duplicate, add the new text block and its vector to the question and answer database, and assign an incrementing version number to the updated question and answer database.
[0056] Example 3, referring to Figures 2-4 As an embodiment of the present invention, based on the previous embodiment, a method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model is provided, including: Specifically, in step S101, this application first downloads various policies published on the official websites of governments at all levels from 1999 to 2023, and then uses the policy text processing module to extract text and optimize the structure of the original policy documents. The specific policy text processing steps include D1-D4: D1: Use an integrated PDF parsing tool (such as PyPDF2) to parse the policy document page by page and extract the original text content; D2: Perform preprocessing operations such as blank line cleaning, garbled character removal, and title recognition on the extracted text to improve the semantic coherence of the text; D3: Uses regular expressions to segment the original text into sentences based on sentence-ending punctuation (such as ".", "!", "?") or other rules; It should be noted that enhanced segmentation rules are applied to the text processed in step D2. On one hand, considering the characteristics of long sentences and nested paragraphs in Chinese policy texts, the system employs a hybrid segmentation method based on regular expressions: first, sentences are initially segmented using semantic terminators such as ".", "!", "?", and ";". Then, paragraphs exceeding a preset threshold (e.g., 500 characters) but lacking terminators are segmented a second time using stop word positions or commas and semicolons. On the other hand, if a sentence is less than 50 characters long and logically coherent with the preceding and following sentences, it is merged into a single text block to avoid semantic sparsity due to excessively short sentences. Secondly, a language noise removal mechanism is applied to the text processed in step D2. For common non-text elements in PDFs such as line breaks, page numbers, watermarks, headers, and footers, the system automatically removes them using exclusion rules based on keywords and layout features, such as matching terms like "page d+". Finally, blank pages and formatting anomalies are detected in the text processed in step D2. After extracting the text, the system judges the length of each page's content. If it is less than a set threshold (such as 30 characters), it is automatically marked as a "blank page" and skipped.
[0057] D4: Divide the text further into several semantically independent text blocks according to a preset block length (e.g., 300-500 characters) to avoid semantic truncation and improve the subsequent vector expression effect. This includes the following steps D41-D45: D41: Each text block is saved in UTF-8 encoding format to ensure character compatibility; D42: Replace or remove any abnormal characters (such as full-width characters, Unicode control characters, form feed characters, etc.) that may exist in the text block to ensure that the corpus format is consistent; D43: Each block includes the original document source identifier, page number, and block sequence number, forming the following structure: {"source":"filename","page":page number,"block_id":serial number,"text":block content}; D44: All text block sets are uniformly cached in memory as a list or dictionary, or persistently stored in a standard format (such as JSONL or PKL files) as input for subsequent embedding and generation modules; D45: This standardized corpus ensures the traceability, reconfigurability, and semantic consistency of the context in subsequent semantic modeling tasks, and provides a stable data foundation for the system to build a high-quality knowledge vector library.
[0058] The above processing method effectively solves the problem that traditional policy texts have a chaotic structure and are difficult to use directly for semantic modeling, and significantly improves the understanding ability of subsequent models.
[0059] In step S102, the unstructured policy text is transformed into a high-dimensional semantic index structure that can be called by a large language model, supporting efficient and interpretable question-answering services. The key lies in the integrated implementation architecture of embedding generation, vector indexing, and semantic search. The specific implementation includes the following steps E1-E5: E1: Generate text embeddings, transforming preprocessed policy text blocks into high-dimensional vector representations with computable semantics for subsequent semantic retrieval and large language models. Through the embedding generation module, the original natural language is mapped to a vector space, thereby enabling the numerical calculation of semantic similarity and laying the foundation for building a question-answering knowledge base. The specific implementation includes the following steps E11-E15.
[0060] E11: Locally Deployed Semantic Embedding Model. The system uses a locally deployed DeepSeek-R1 model to obtain semantic representations of text blocks through its embedding interface / api / embeddings. This model is a Chinese language model trained based on the Transformer architecture, possessing strong context modeling capabilities and effectively encoding policy texts with complex syntactic structures and multiple logical nestings.
[0061] E12: Text input format standardization. Each text block is used as a prompt parameter to construct a standard JSON request body, which is then sent to the local model API. The system uniformly uses UTF-8 encoding to ensure consistency in Chinese text transmission and processing.
[0062] E13: Embedded vector output standardization. The model returns a fixed-length dense vector (e.g., a float32 array with dimension 768). The system uses the NumPy framework for array formatting to ensure compatibility with the data structure of the FAISS retrieval library.
[0063] E14: Exception Handling and Embedding Validation Mechanism. For events such as timeouts, response errors, or empty return vectors during the embedding process, the system automatically logs them to the log file and performs a delayed retry mechanism up to three times. After embedding, the system performs line-by-line validation of vector dimensions, data types, and numerical validity to ensure the integrity and reliability of the embedded data.
[0064] It should be noted that, unlike existing methods, this embodiment uses a Deepseek R1 large language model deployed locally on Ollam to implement some functions. Furthermore, this model is a technical solution for applying artificial intelligence to pollution reduction and carbon reduction policies. Specifically, this embodiment has made the following adjustments: Input Model Settings. The model input includes the user-submitted question and policy fragments most relevant to the question, indexed from the pollution reduction and carbon reduction knowledge base using an algorithm improved based on FAISS technology. Output Results. The model output is a natural language answer to the above two inputs. Integration Mechanism with the Pollution Reduction and Carbon Reduction Field. This embodiment closely integrates with pollution reduction and carbon reduction in terms of knowledge base construction, policy retrieval, and question-answering scenario fusion. First, it acquires and processes policy texts and builds the knowledge base; second, based on FAISS, this embodiment optimizes the policy retrieval effect; finally, it inserts the retrieved policy text content as context into the Prompt, achieving semantically enhanced question answering.
[0065] E2: Constructing a semantic index library. To achieve efficient retrieval of semantic vectors, this embodiment embeds the generated text blocks into vectors to construct a structured vector index library. Distance metrics in vector space are used to calculate and match the similarity between user queries and knowledge content. This step organizes abstract semantic representations into a searchable data structure, significantly improving the response speed and accuracy of the question-answering system.
[0066] This embodiment is based on the open-source FAISS solution with some modifications and can achieve the following functions: Text block structure binding. In this embodiment, each embedded vector is bound to a structured policy text block (including source file name, page number, and paragraph number) to achieve semantic traceability of the search results.
[0067] FAISS is designed in a modular fashion. The FAISS search function is modularized and can be reused as an independent component in WebSocket to implement multiple question-and-answer sessions.
[0068] By combining the content retrieved by FAISS with the user's question, semantically enhanced question answering can be achieved.
[0069] Supplementing fault tolerance mechanisms. Anomaly handling is incorporated into all stages, including querying, embedding, and index loading, to ensure robust system operation. Specific implementation methods include the following steps (E21-E25): E21: Vector Matrix Assembly. All text block embedding vectors are stacked into a two-dimensional matrix (of the form [N,D], where N is the number of text blocks and D is the embedding dimension) using the numpy.vstack() operation. This matrix serves as input for constructing the vector indexes.
[0070] E22: Introducing the FAISS vector retrieval framework. The system uses Facebook's open-source FAISS (FacebookAISimilaritySearch) library to build a vector index for nearest neighbor search. The selected IndexFlatL2 type uses Euclidean distance (L2) as the similarity metric, suitable for high-performance semantic retrieval in small to medium-scale scenarios.
[0071] E23: Index Building and Adding Operations. After initializing the index structure, call the `index.add()` method to add the embedded vector matrix to the index. The system will automatically sort and organize the vectors according to the internal data structure, and the index will then be ready for querying.
[0072] E24: ID Mapping and Primary Key Binding Mechanism. To achieve a one-to-one correspondence between vectors and original text blocks, this embodiment can use the IndexIDMap structure to implement the primary key binding function, that is, to set a unique identifier for each vector, ensuring that the retrieval results can accurately retrieve the content of the text block.
[0073] E25: Index persistent storage mechanism. The constructed vector index is saved as an index file using the faiss.write_index() method, and stored locally along with the corresponding text block set pkl file in a specified path for easy loading, updating, or migration deployment.
[0074] E3: Incremental Construction and Deduplication Logic. To enhance the system's sustainability and document management efficiency, this embodiment supports a dynamic update mechanism for the knowledge base. This involves incrementally adding new document content to the existing corpus while avoiding duplicate blocks through content comparison, thereby constructing a timely and unique knowledge system. Specific implementation methods include the following steps E31-E35: E31: New Document Block Screening Process. After receiving a new policy document, the system first converts it into a set of text blocks and generates a unique identifier for each text block; E32: Semantic Similarity Deduplication. New text blocks are semantically similar to existing indexed text blocks in the knowledge base using vector methods, with cosine similarity as the metric. When the similarity exceeds a set threshold, the text block is considered duplicate content, and the system automatically skips the embedding and indexing operations for that block. E33: Incremental addition to the index structure. For text blocks determined to be non-duplicate, the system dynamically adds the new embedding vector to the existing index structure by calling the index.add() or index.merge_from() interface, avoiding rebuilding the entire database and improving system efficiency; E34: Text and vector libraries are updated synchronously. In addition to updating the vector index, the text block set pkl is also expanded synchronously to ensure that the text and index structures match and the numbering is consistent, avoiding access misalignment or content mismatch. E35: Version Management and Rollback Support. All incremental build processes generate unique version numbers (such as chunks_v2.0.pkl, index_v2.0.index). The system supports version-based backup and rollback operations, ensuring that the system can be restored to a specified state in case of accidental updates or system failures.
[0075] E4: The knowledge block and index association storage mechanism: To ensure that the knowledge base can correctly map vector results back to the original policy text during semantic retrieval, this embodiment designs a stable bidirectional mapping mechanism between vectors and text blocks, and achieves structured management and long-term availability of knowledge data through local persistent storage. The specific implementation includes the following steps E41-E45: E41: Unified Data Structure Design. All text blocks are organized into a data structure containing the following fields: {"source": filename, "page": page number, "block_id": block number, "text": content}, used to track the source of the text and its physical location in the document, facilitating result interpretation and location.
[0076] E42: Dual-file persistence scheme. The collection of text blocks is serialized into a pkl file using the Python standard pickle library, and the embedded index structure is saved as an index file using the FAISS tool. Both are stored in the same directory, forming a one-to-one data pair.
[0077] E43: Load-time consistency check mechanism. Each time the index file and text block file are loaded, the system performs a length consistency check (e.g., len(chunks) == index.ntotal). If they do not match, an error message is triggered to prevent runtime access misalignment.
[0078] E44: Supports batch loading for fast processing. All data is stored in binary compressed format. The system uses memory mapping (such as mmap or numpy.memmap) to achieve fast reading and processing of large-scale corpora, reducing I / O overhead.
[0079] E45: Supports platform independence and portability. All path parameters are configurable, and the data structure and index format are compatible with mainstream operating systems, enabling deployment from one server to another, ensuring cross-platform availability.
[0080] Through structured storage and consistency verification mechanisms, this embodiment achieves precise binding and efficient retrieval of semantic vectors and original text blocks, providing data support for semantic interpretation and content tracing, and ensuring the integrity and reliability of the knowledge base system.
[0081] E5: System Robustness and Fault Tolerance Mechanism. To ensure the stability and reliability of the system in actual operation, this embodiment introduces a complete set of fault tolerance and robustness designs, including mechanisms for handling model call anomalies, data consistency checks, and operational status feedback, thereby effectively improving the maintainability and anti-interference capability of the system. The specific implementation includes the following steps E51-E55: E51: Embedding failure retry mechanism. When a call to the embedding model interface (such as http: / / localhost:11434 / api / embeddings) fails, the system automatically triggers retry logic, retrying 3 times by default, with a delay of several seconds each time. If multiple failures occur, the log is recorded and the text block is marked as "embedding failed".
[0082] E52: Model Status Detection Interface. The system exposes the model status detection interface / status, which determines the availability of the local model by pinging the model's embedded API and feeds back the running status to the front-end page, prompting the user whether the model is currently in a ready state.
[0083] E53: Embedding result integrity verification. After each embedding, the system will check the dimension, data type, and numerical range (e.g., whether it is NaN or Inf) of the returned vector to ensure that the result conforms to the model specification; if an abnormal vector is found, it will be discarded and recorded immediately.
[0084] E54: Breakpoint recovery mechanism during the knowledge index building process. When the knowledge index building process is interrupted or terminated due to a crash, the system automatically records the current progress (such as the number of blocks completed), and can resume from the breakpoint in the next round of startup to avoid repeated processing.
[0085] E55: Operation Log Recording and Anomaly Alarms. The system records various critical events (such as index loading failure, model call timeout, I / O errors, etc.) into the log file, and can optionally connect to an alarm module (such as sending email or message notifications) to achieve rapid problem location and tracking.
[0086] Through the above technical design, this embodiment, while processing large-scale unstructured corpora and calling local large models, possesses good system robustness, traceability, and operational security, ensuring long-term stable operation in offline or private deployment environments.
[0087] Specifically, in step S103, a localized semantic retrieval mechanism is designed. After constructing the semantic vector index, a localized semantic retrieval mechanism is further designed to ensure that the user's input question can accurately and efficiently match relevant policy content in an offline environment. This mechanism achieves "text search based on meaning" through semantic vector comparison, breaking away from the limitations of traditional keyword matching and providing accurate contextual support for large language models.
[0088] The goal of the localized retrieval module is to perform embedding calculations of user queries in a local environment, conduct high-dimensional semantic matching with embedded indexes in the knowledge base, and return the most relevant set of policy text blocks. The specific implementation includes the following steps F1-F5: F1: User Query Embedding Generation. The purpose of this step is to transform the user's natural language question into a structured vector representation so that similarity can be calculated with the pre-stored embedding vectors in the knowledge base. The specific implementation includes the following steps F11-F14: F11: Users can input free-form natural language questions through the front-end interface or API; F12: The system calls the locally deployed embedded model API (such as http: / / localhost:11434 / api / embeddings), constructing the request body in the format {"model":"deepseek-r1","prompt":user question}; F13: The model returns a JSON object containing an embedding field, which corresponds to a floating-point array; F14: The system encapsulates the array in NumPy format and processes it uniformly as np.array(vector, dtype=np.float32) to ensure that it can be read by the FAISS interface; if the return value is empty, the dimension is incorrect, or it is not a numeric type, the system interrupts the retrieval process and prompts that the embedding has failed.
[0089] F2: Semantic Vector Alignment and Nearest Neighbor Search. This step is used to implement the core operation of local semantic retrieval. Its goal is to retrieve the policy text block that is closest to the user query in the embedded vector space according to the distance metric principle, thereby constructing a highly relevant contextual input for the large language model to generate the answer. The specific implementation includes the following steps F21-F23: F21: The system first takes the question input by the user and generates a corresponding query vector (denoted as query_vector) through the locally deployed embedded model. Its dimensions are consistent with the vectors already established in the knowledge base (e.g., both are 768 dimensions). F22: The system calls the FAISS search engine's .search() method to perform a vector comparison operation on the query vector. The specific calling method is as follows: Where, index is a pre-built vector index object; top_k is the set number of returned results; D is a two-dimensional array representing the Euclidean distance between the returned results and the query vector, the smaller the distance, the closer the semantics; I is the corresponding index array, whose elements are integers, indicating the position number of the result in the original text block combination.
[0090] F23: The system extracts the corresponding text chunk content (such as chunks[I[0][i]]) from the local corpus based on the returned index array I, and sorts, filters and post-processes it in combination with the distance value D, providing it as a candidate context for subsequent response generation modules.
[0091] Through this step, this embodiment utilizes local computing to complete an accurate nearest neighbor search in a high-dimensional semantic space, avoiding the limitations of keyword matching, significantly improving the accuracy and response efficiency of semantic understanding, and providing basic support for achieving high-quality policy Q&A.
[0092] F3: Similarity Filtering and Result Ranking. This step is used to filter the initial search results returned by FAISS, removing semantically irrelevant text blocks to ensure the accuracy and consistency of the final constructed context. The specific implementation includes the following steps F31-F33: F31: The system parses the distance value array D returned by FAISS, sorts it in ascending order of distance, and prioritizes keeping the closest text blocks; F32: Sets the distance threshold parameter. The system only retains results that meet the threshold condition. If all results exceed this value, it returns a "no matching results" message to prevent the large language model from receiving irrelevant content. F33: When there are multiple results with extremely high semantic similarity, the system supports merging them into a "cluster representative block" for display and generation, preventing duplicate content from interfering with answer generation.
[0093] F4: Context Concatenation and Prompt Construction. The goal of this step is to concatenate multiple related text blocks into coherent contextual content in order to construct a complete large language model for the Prompt input, thereby achieving accurate policy question-and-answer generation. The specific implementation includes the following steps F41-F44: F41: The system extracts the corresponding content from the original text block set based on the corresponding position in the index array I, forming an initial context list; F42: If a text block has few characters (e.g., less than 200 characters), the system will automatically find adjacent blocks (e.g., block_id±1) and concatenate them to enhance the integrity of the context. F43: The concatenated content is connected by \n to form a unified string "context", which is then combined with the user's question to form the prompt. F44: This prompt will be fed into the large language model to generate a response, which is a key connecting step between semantic retrieval and response.
[0094] F5: Query caching and logging mechanism. This step is used to improve the efficiency of repeated queries and supports system behavior tracking and subsequent optimization analysis. The specific implementation includes the following steps F51-F54: F51: The system standardizes user questions (e.g., removes spaces, lowercases) and then calculates their hash value (e.g., SHA256) as a unique identifier; F52: If the identifier already exists in the cache dictionary, the system directly returns the previous search results and context combination, skipping the model call process and reducing the computational burden; F53: All retrieval processes and results are recorded in the log system. The log content includes: timestamp, original query text, hit block number, similarity distance, whether the cache was hit, etc. F54: Log files can be in JSON or CSV format, which facilitates later analysis of user behavior, optimization of threshold settings, and corpus update strategies.
[0095] Through the above steps, the invention constructs a complete, closed-loop localized semantic retrieval mechanism, realizing the entire process from user input to extraction of highly relevant policy content. This mechanism balances semantic accuracy, operational efficiency, and system maintainability, and is one of the core components supporting offline intelligent question answering capabilities.
[0096] Specifically, in step S103, after completing semantic retrieval and context construction, this embodiment further generates a response using a locally deployed Large Language Model (LLM). The main function of this module is to construct prompts from the query statement and retrieved relevant policy text blocks, and generate natural language responses that conform to semantic logic using a local model. This module runs entirely in a local environment, ensuring that data remains within the local domain, responses are stable, and generation results are controllable. The specific implementation includes the following steps J1-J4: J1: Prompt word construction. This step is used to merge the retrieved policy corpus blocks with user question content to construct the model input. The specific implementation includes the following steps J11-J12: J11: The system receives the context content and user question that were assembled in the previous step; J12: Construct prompt words according to a fixed template. After the prompt words are concatenated into strings, they are converted into UTF-8 encoding and used as input data for the local large language model.
[0097] J2: Local Model Invocation and Parameter Setting. This step is used to send a generation request to the locally deployed inference engine and set the necessary parameters. The specific implementation includes the following steps J21-J23: J21: The default model interface address is http: / / localhost:11434 / api / generate, which is provided by the local Ollam platform; J22: The system sends the request body in JSON format; J23: Requests are sent using the requests.post(...,stream=True) method, which supports streaming response content and avoids excessive memory usage caused by returning large amounts of text at once.
[0098] J3: Streaming Response Analysis and Assembly. This step is responsible for analyzing and assembling the model's response results step by step into a complete answer. The specific implementation includes the following steps J31-J34: J31: The model response is a series of JSON strings transmitted line by line; J32: The system reads response data line by line using the response.iter_lines() method and appends fragments from each response field to the total response string in real time; J33: If the returned JSON contains the "done":true field, it indicates that the model response is complete; J34: Each response fragment is pushed to the front end in real time to enable real-time display and improve user experience.
[0099] J4: Exception Handling and Generation Stability Mechanism. To ensure that the generation process is not interrupted, this embodiment designs a robust exception handling mechanism, specifically including the following steps J41-J43: J41: If the model interface connection fails (e.g., port closed, response timeout), the system records the exception log and returns a unified error message (e.g., "Generation failed, please check the model status"). When J42:JSON decoding fails, the system will skip the line and continue parsing the next one, avoiding the entire process being interrupted by a single failure. J43: The system provides the / status interface to detect the model's running status. If a 503 status code is returned, the generation task will be paused.
[0100] Specifically, in step S103, in order to achieve real-time, smooth, and continuous question-and-answer interaction between the user and the system, this embodiment designs a bidirectional communication interface mechanism based on the WebSocket protocol, combined with streaming response capabilities and a browser visual operation interface, so that the user can input query content in real time and receive the answer generated by the model word by word.
[0101] This module primarily addresses issues such as high latency in traditional HTTP requests, uninterrupted question-and-answer sessions, and discontinuity between the front-end and back-end. It also provides stability and exception handling capabilities, making it suitable for intelligent question-and-answer scenarios related to pollution reduction and carbon reduction policies. The specific implementation includes the following steps H1-H5: H1: WebSocket Interface Establishment and User Connection Initialization. This step is used to implement real-time bidirectional communication between the user's browser frontend and the system backend, for subsequent question-and-answer command transmission and response data return. The specific implementation includes the following steps H11-H14: H11: The backend is based on the FastAPI framework and registers WebSocket routes under the path / ws / chat; H12: After the webpage is loaded on the front end, its JavaScript client initiates a connection request through the standard WebSocket protocol; H13: The backend calls awaitwebsocket.accept() to explicitly accept the connection and requests a handshake to establish it; H14: The system also initializes an empty list chat_history=[] to store the questions and answers of the current session.
[0102] H2: Receive user queries and perform validity checks. Ensure user input is valid and prevent invalid input such as null values or incorrect formats from affecting subsequent system processes. Specific implementation includes the following steps H21-H23: H21: The backend uses awaitwebsocket.receive_text() to receive JSON data sent by the frontend; H22: Use json.loads(data) to parse the content and extract the "query" field; H23: The system determines whether the field is empty or contains only whitespace. If it is empty, it immediately sends an error message to the front end: "System problem, cannot be empty." and skips this round of processing.
[0103] H3: Perform semantic retrieval and organize context. From the constructed semantic vector index library, find the policy content most relevant to the user to support answer generation. Specific implementation includes the following steps H31-H34: H31: The system call search_faiss_index(index, chunks, query, top_k=5) is used, where index is the loaded FAISS vector library and chunks is the set of original text blocks; H32: The function returns the top-K results, each of which is a triple (index number, distance value, matched text); H33: The system extracts the text portion text_chunk from the result and organizes it into context context="\n".join(text_chunks) to generate prompt words; H34: If the result is empty or the distance value is too large (indicating semantic irrelevance), the system may terminate the process or prompt "No matching content found"; H4: Construct the Prompt and enable streaming response generation. The question and context are merged to form a Prompt that conforms to the language model input specifications, and the response is generated using a local LLM. Specific implementation steps include H41-H43: H41: The system uses a fixed format to concatenate the Prompt, calls the local model interface, and sends the application model information and Prompt as a JSON request; H42: When stream=True is enabled in the request parameters, the model returns a response in real time in segmented JSON format; H43: The system uses response.iter_lines() to stream-parse and extract the "response" field in real time. It then pushes the content to the front end segment by segment using awaitwebsocket.send_text(chunk) and finally returns as the end marker.
[0104] H5: Anomaly Detection and Connection Maintenance Mechanism. If an anomaly occurs during model calls or communication, the system can reliably detect and report it, preventing connection interruptions or page crashes. Specific implementation methods include the following steps H51-H52: H51: Automatically captures exceptions such as JSON decoding failure, model request error, network timeout, etc. The exception information is extracted into a string using str(e) and pushed to the front end with a labeled prompt via WebSocket; H52: If a disconnection occurs, the system exits the current session loop without disrupting the main thread.
[0105] Example 4 is an embodiment of this example, which provides a system for constructing an offline question-and-answer database of pollution reduction and carbon reduction guidelines based on a large language model, including: The data collection and preprocessing module is used to collect text data related to pollution reduction and carbon reduction, and to preprocess the text data to generate a standardized set of text blocks. The vector index construction module is used to convert each text block in the text block set into a vector representation through a semantic embedding model, and to construct and store the corresponding vector index and text block set; The question-and-answer generation module receives a question input by the user, converts the question into a query vector, retrieves the text block most similar to the query vector from the vector index, and performs semantic matching between the most similar text block and the question using the large language model to generate an answer. The system feedback and update module is used to update the question and answer database based on user feedback information.
[0106] This embodiment also provides an electronic device applicable to a method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model, comprising: a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model as proposed in the above embodiment.
[0107] This embodiment also provides a storage medium storing a computer program that, when executed by a processor, implements a method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model as proposed in the above embodiment.
[0108] The storage medium proposed in this embodiment and the method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer library based on a large language model proposed in the above embodiments belong to the same inventive concept. Technical details not described in detail in this embodiment can be found in the above embodiments, and this embodiment has the same beneficial effects as the above embodiments.
[0109] Based on the above description of the implementation methods, those skilled in the art can clearly understand that the present invention can be implemented using software and necessary general-purpose hardware, and of course, it can also be implemented using hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk, or optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of the various embodiments of the present invention.
[0110] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.
Claims
1. A method for constructing an offline question-and-answer database of pollution reduction and carbon reduction guidelines based on a large language model, characterized in that: include, Data preparation and standardization: Collect text data related to pollution reduction and carbon reduction, and preprocess the text data to generate a standardized set of text blocks; Vector index construction: Each text block in the text block set is converted into a vector representation through a semantic embedding model, and the vector index corresponding to the text block set is constructed and stored; Semantic retrieval and question answering generation: Receive a question input by a user, convert the question into a query vector, retrieve the text block most similar to the query vector from the vector index, and perform semantic matching between the most similar text block and the question using the large language model to generate an answer; System feedback and incremental updates: The question and answer database is updated based on user feedback or new data.
2. The method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model as described in claim 1, characterized in that: The preprocessing includes identifying non-text elements in the text data; After deleting the identified non-text elements, the remaining text is divided into several text blocks with complete semantics. After uniformly encoding the text blocks, they are stored to form a standardized set of text blocks.
3. The method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model as described in claim 2, characterized in that: The process of uniformly encoding and storing text blocks to form a standardized set of text blocks includes generating identification information for each text block that can identify its source and location. The identification information is bound to the corresponding text block to form a structured data record, and the structured data record is stored in a local file to form a searchable collection of text blocks.
4. The method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model as described in claim 3, characterized in that: The system receives natural language questions input by users and converts the questions into query vectors through a semantic embedding model to achieve a numerical representation of the question's semantics. In a pre-built vector index, one or more text blocks most similar to the query vector are retrieved by calculating a similarity metric, so as to accurately locate the relevant context from the knowledge base; The most similar text block retrieved is combined with the user's original question to construct a prompt word, which is then input into a locally deployed large language model. The large language model performs deep semantic matching and understanding of the policy context and the user's question to generate a natural language answer that conforms to semantic logic.
5. The method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer database based on a large language model as described in claim 4, characterized in that: When updating the question-and-answer database, the difference between the semantic vector of the newly added text block and the existing vector is calculated, and the difference is compared with the existing text block to determine whether it is a duplicate text block. If it is determined to be non-duplicate, the newly added text block and its vector are added to the question-and-answer database, and an incrementing version number is assigned to the updated question-and-answer database.
6. A system for constructing an offline question-and-answer database of pollution reduction and carbon reduction criteria based on a large language model, comprising applying the method for constructing an offline question-and-answer database of pollution reduction and carbon reduction criteria based on a large language model as described in any one of claims 1 to 5, characterized in that, include: The data collection and preprocessing module is used to collect text data related to pollution reduction and carbon reduction, and to preprocess the text data to generate a standardized set of text blocks. The vector index construction module is used to convert each text block in the text block set into a vector representation through a semantic embedding model, and to construct and store the corresponding vector index and text block set; The question-and-answer generation module receives a question input by the user, converts the question into a query vector, retrieves the text block most similar to the query vector from the vector index, and performs semantic matching between the most similar text block and the question using the large language model to generate an answer. The system feedback and update module is used to optionally update the question-and-answer database based on dialogue information.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer library based on a large language model, as described in any one of claims 1 to 5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the method for constructing an offline pollution reduction and carbon reduction criteria question-and-answer library based on a large language model, as described in any one of claims 1 to 5.