A food safety-oriented search-enhanced generated knowledge base system and method
By enhancing the knowledge base system for food safety through retrieval, and integrating multi-source knowledge bases and statistical quality control modules, the system solves the problems of accurate querying of food safety regulations and monitoring of the production process. It achieves efficient and accurate regulatory compliance advice and production quality monitoring, while reducing deployment costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA JILIANG UNIV
- Filing Date
- 2026-04-08
- Publication Date
- 2026-07-03
AI Technical Summary
Existing technologies cannot effectively cope with the frequent updates to food safety regulations. They suffer from problems such as high illusion rate, lack of traceability in regulatory queries, insufficient accuracy of general RAG system retrieval, and separation of regulatory compliance and production quality monitoring functions. There is a lack of specialized systems and evaluation benchmarks for Chinese food safety regulations.
A retrieval-enhanced knowledge base generation system for food safety was designed, integrating a multi-source knowledge base construction module, a hybrid retrieval module, a re-ranking and filtering module, a large language model generation module, and a statistical quality control module. It adopts structured processing and vectorization techniques, combined with local deployment of the large language model, to achieve the accuracy and traceability of regulatory queries, and integrates production process quality monitoring.
It significantly reduces the hallucination rate, improves the accuracy of question answering, achieves full-process traceability, uses a hybrid retrieval strategy that is precise and efficient, integrates production process quality monitoring, reduces deployment costs, provides publicly reproducible evaluation benchmarks, and meets the compliance requirements of food safety management.
Smart Images

Figure CN122334425A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the interdisciplinary field of artificial intelligence and food safety technology, specifically involving a retrieval-augmented generation (RAG) knowledge base system and method for food safety, integrating a statistical quality control (SQC) module, which can be used to automatically interpret and apply Chinese national food safety standards, supporting food manufacturing enterprises' quality compliance management decisions and production process quality monitoring. Background Technology
[0002] China's food industry is massive, with the market for condiments and compound seasonings alone exceeding 480 billion yuan in 2025. Each type of food product is subject to a complex regulatory system. As of December 31, 2025, the National Health Commission (NHC) and the State Administration for Market Regulation (SAMR) have issued and updated 52 existing national food safety standards (GB series), covering limits for food additives (GB 2760-2024), limits for contaminants (GB 2762-2022), limits for microorganisms (GB 29921-2021), limits for mycotoxins (GB 2761-2025), food labeling (GB 7718-2025), and standards for compound seasoning products (GB 31644-2018), among others, totaling over 2000 pages of technical content. Between 2018 and 2025, the transition of GB 2760 from the 2014 version to the 2024 version alone will involve revising more than 300 food additive limit items. For small and medium-sized enterprises that lack dedicated food science personnel, consistently and accurately complying with these standards is an extremely challenging task.
[0003] The existing technology has the following shortcomings: (1) Traditional expert systems and knowledge base methods rely on manual rule coding, which has high maintenance costs and cannot meet the needs of frequent standard updates (more than 60 standards were released or revised between 2018 and 2025), and lacks the ability to flexibly process natural language queries.
[0004] (2) Although existing large language models (LLMs) have powerful natural language understanding and generation capabilities, they have serious limitations in the field of food safety regulations: First, the timeliness of knowledge is insufficient, and they cannot reflect the latest standard revisions (such as GB 2761-2025, which came into effect in July 2025, and GB 7718-2025, which came into effect in December 2025); Second, the hallucination problem is prominent, which can easily produce incorrect numerical limits or standard references, which may cause serious consequences in food safety scenarios; Third, they lack traceability and cannot provide specific standard clauses, which does not meet the compliance requirements of food safety management.
[0005] (3) The existing general RAG (retrieval enhancement generation) system has not been specifically optimized for the special data structure of Chinese food safety regulations documents, including a large number of numerical tables, Chinese standard terminology, and multiple versions of standards, resulting in insufficient retrieval accuracy.
[0006] (4) The quality management system (QMS) and statistical process control (SPC) system of food manufacturing enterprises are usually operated separately. There is a lack of solutions that integrate regulatory compliance Q&A and production process quality monitoring into the same system, which increases the enterprise's software licensing costs and the cognitive burden on operators.
[0007] (5) There is currently a lack of publicly available and reproducible systematic evaluation benchmarks specifically for RAG systems in the field of food safety regulations in China, making it difficult to objectively measure the actual effectiveness of such systems and support community improvement.
[0008] Therefore, there is an urgent need for an intelligent knowledge management system specifically designed for food safety, capable of accurately retrieving and applying national food safety standards and integrating quality monitoring of the production process. Summary of the Invention
[0009] The purpose of this invention is to provide a retrieval enhancement knowledge base generation system and method for food safety, integrating a statistical quality control module to solve problems in existing technologies such as high illusion rate of large language models, lack of traceability of regulatory queries, insufficient retrieval accuracy of general RAG systems, and separation of regulatory compliance and production quality monitoring functions.
[0010] To achieve the above objectives, the present invention adopts the following technical solution: This invention provides a retrieval enhancement knowledge base generation system for food safety, including a multi-source knowledge base construction module, a hybrid retrieval module, a re-ranking and filtering module, a large language model generation module, a statistical quality control module, and an evaluation benchmark module.
[0011] This invention also provides a retrieval enhancement generation method for food safety, comprising six steps: multi-source knowledge base construction, vectorization and indexing, query processing, hybrid retrieval, reordering and filtering, generation and output.
[0012] This invention also provides a statistical quality control method for production processes aimed at food safety, which includes three functions: statistical process control, process capability analysis, and automatic generation of acceptance sampling plans.
[0013] The present invention has the following beneficial effects: (1) Significantly reduced illusion rate: By anchoring the generation process of the large language model to structured multi-source official standard documents and regulatory Q&A records, the system illusion rate was reduced from 18.2% of the pure large language model baseline to about 4.3%, effectively ensuring the accuracy of food safety compliance recommendations.
[0014] (2) Significantly improved question-answering accuracy: The system achieved an overall accuracy of 0.94 and an F1 score of 0.93 on a 320-question public benchmark. Compared with the pure large language model baseline (0.62), the accuracy improved by 52% and the F1 score improved by 55%. Ablation experiments showed that the three data sources (GB standard, FSSIS question answering, and CFSA question answering) contributed to the superimposed performance gain.
[0015] (3) Achieve full traceability: By using structured prompt templates, the large language model is forced to mark the national standard number and clauses on which the answer is based, with a source citation rate of over 91%, which meets the audit requirements of food safety management.
[0016] (4) The hybrid retrieval strategy is accurate and efficient: The hybrid retrieval strategy, which combines vector semantic retrieval with SQLite structured numerical search, improves the accuracy of mixed compliance calculation queries for food additives from 0.78 for pure vector retrieval to 0.96, thus solving the accuracy problem of regulatory numerical queries.
[0017] (5) Integrated production process quality monitoring: The SQC module provides SPC control charts, process capability analysis and acceptance sampling plan automatic generation functions. Using public datasets, the three parameters Cpk are verified to be 1.41-1.67, realizing the integration of regulatory compliance Q&A and production quality monitoring functions.
[0018] (6) Protects data privacy and has low deployment cost: The system adopts DeepSeek-r1:8b large language model for local deployment, without GPU, all data does not leave the enterprise network, the end-to-end response time is 2.41 seconds, eliminates cloud API subscription costs, and the expected hardware investment return rate is over 340% in 12 months.
[0019] (7) Publicly available and reproducible evaluation benchmarks: The 320-question benchmark covers four types of questions and three levels of difficulty. It is built based on public data sources and supports community comparison and improvement. Attached Figure Description
[0020] Figure 1 This is a schematic diagram of the overall system architecture of the present invention, illustrating the data flow relationship between the multi-source knowledge base construction module, the hybrid retrieval module, the re-sorting and filtering module, the large language model generation module, and the statistical quality control module.
[0021] Figure 2 A flowchart for knowledge base construction and multi-source data integration is provided, demonstrating the complete processing flow from three public data sources (GB standard, FSSIS question answering, and CFSA question answering) to structured text blocks, vector indexes, and SQLite numerical lookup tables.
[0022] Figure 3The RAG retrieval and generation pipeline flowchart illustrates the complete online reasoning process from user query input to traceable answer output, including four stages: query preprocessing, hybrid retrieval (vector retrieval + structured search + RRF fusion), cross-encoder reordering and filtering, and large language model output generation.
[0023] Figure 4 The diagram shows the functional architecture of the Statistical Quality Control (SQC) module, illustrating the three sub-functions: SPC statistical process control, process capability analysis (Cp / Cpk), and acceptance sampling plan generation (GB / T 2828.1-2012), and their integration with the knowledge base system. Detailed Implementation
[0024] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0025] Example 1: Construction of a Multi-Source Knowledge Base 1.1 Data Source Acquisition This invention collects food safety knowledge from three publicly available data source systems, ensuring traceability and reproducibility of the sources: (a) Data Source S1 – National Food Safety Standards (GB Series): 52 GB food safety standards were collected from the official database of the National Health Commission (http: / / www.nhc.gov.cn / sps / pjgg / ), covering food additives (GB 2760-2024), contaminants (GB 2762-2022), microbial limits (GB 29921-2021), compound seasoning product standards (GB 31644-2018), and a series of testing method standards (GB 4789 series, GB 5009 series). All standards were verified by the NHC database and updated to December 31, 2025, incorporating the newly released GB 2761-2025 (limits for mycotoxins) and the revised GB 7718-2025 (food labeling).
[0026] (b) Data source S2 – FSSIS Regulatory Question and Answer Records: 1,247 regulatory question and answer records (2018–2025) were downloaded and cleaned from the public data portal of the Food Safety Supervision Information System (FSSIS, https: / / spbaqg.samr.gov.cn). The records cover enterprise compliance consultations, standard interpretation requests and enforcement case analyses.
[0027] (c) Data source S3—CFSA Academic Question and Answer Dataset: 738 pairs of annotated academic questions and answers (updated to December 2025) were obtained from the National Center for Food Safety Risk Assessment (CFSA, https: / / sppt.cfsa.net.cn / db), covering food additive toxicology, risk assessment methods and analytical method validation.
[0028] The three data sources mentioned above contain a total of 2,220 documents, covering all areas of knowledge related to food safety regulations.
[0029] 1.2 Document Processing Flow After all source documents have been digitized, they are then processed using the following structured workflow: (a) Text chunking: The text is divided into standardized chunks of 500 tokens each using a recursive character segmenter, with 50 tokens of overlap between adjacent chunks to ensure semantic coherence across chunks.
[0030] (b) Separate processing of numerical tables: For tables containing a large amount of numerical information, such as limits for food additives, a rule-based table parser is used to extract the data independently and store it in a structured JSON format in an SQLite database. The key-value pairs retain fields such as "food category - additive name - maximum usage - unit" to avoid loss of numerical accuracy caused by text processing.
[0031] (c) Metadata Annotation: Attach metadata to each text block, including the standard number (e.g., "GB 2760-2024"), revision year (e.g., "2024"), chapter title (e.g., "3.1 Preservatives"), and table identifier (if any). Metadata is used for precise filtering in subsequent retrieval stages and as a reference in the generation stage.
[0032] 1.3 Vectorization and Dual-Path Index Construction (a) Dense Vector Indexing: The BAAI / bge-small-zh-v1.5 Chinese embedding model (open source from Beijing Academy of Artificial Intelligence) is used to vectorize all text blocks. This model outputs 384-dimensional semantic vectors, optimized for Chinese corpora, and suitable for processing food safety regulations texts containing technical terms. The vectors are stored in the Chroma vector database, supporting efficient nearest neighbor retrieval.
[0033] (b) Structured numerical index: The numerical table data extracted in step (b) is stored in an SQLite relational database, and an index is built based on fields such as standard number, food category, and additive name to support precise quantitative retrieval queries.
[0034] Example 2: RAG Retrieval and Generation Pipeline 2.1 Query Preprocessing After receiving a natural language query from the user, the system performs the following preprocessing operations: (a) Standardization: Unifying punctuation marks and number formats; (b) Standard number identification: Identify the national standard number (such as "GB2760") explicitly mentioned in the query using regular expressions, extract and store it for subsequent metadata filtering steps.
[0035] 2.2 Hybrid Search Perform two-way retrieval simultaneously on the preprocessed query: (a) Vector semantic retrieval: Using BAAI / bge-small-zh-v1.5 to encode the query, the first k=5 semantically relevant text blocks are retrieved from the Chroma vector database.
[0036] (b) Structured numerical lookup: For queries containing numerical parameters (such as additive limits, microbial thresholds), the SQLite numerical lookup table is queried in parallel to obtain precisely matched structured records.
[0037] (c) Result Fusion: The two search results are merged using the Reciprocal Rank Fusion (RRF) algorithm. The RRF formula is as follows: RRF_score(d) = Σ 1 / (k + rank_i(d)) Where k is a smoothing constant (default value k=60), and rank_i(d) is the rank of document d in the i-th retrieval. The fused candidate text blocks enter the re-ranking stage.
[0038] 2.3 Cross-encoder reordering and metadata filtering (a) Metadata filtering: If a specific standard number has been identified in the user query, the candidate text blocks are pre-filtered according to the standard number in the metadata, and the text blocks related to the standard are retained first.
[0039] (b) Cross-encoder reordering: The BAAI / bge-reranker-base cross-encoder reordering model is used to construct a joint input sequence [CLS]q[SEP]d[SEP] for the user query q and each candidate text block d. The accurate semantic relevance score is calculated through a two-stream attention mechanism, and the candidate list is reordered. The top k=3 text blocks are taken as the final retrieval results.
[0040] 2.4 Output Generation and Traceability Input the first three reordered text blocks and the user's original query into the large language model according to the following structured prompt template: "[System]: You are a food safety compliance expert. Please answer only based on the provided regulatory context. [Context]: {top3_chunks} [Citations]: {citations} [Question]: {user_query} [Answer]:" The large language model uses DeepSeek-r1:8b and is deployed locally in a Docker container via the Ollam framework. Local deployment ensures that all enterprise documents and production data do not leave the enterprise network, protecting data privacy while eliminating cloud service API fees. The system uses pure CPU inference (Intel Core i7-13700, 32 GB RAM), requiring no GPU acceleration.
[0041] Example 3: Statistical Quality Control (SQC) Module 3.1 Statistical Process Control (SPC) The first function of the SQC module is to perform statistical process control on continuous production parameters. The system collects sample data from subgroups, automatically calculates the upper control limit (UCL) and lower control limit (LCL) of the X-bar control chart and R control chart, and establishes Shewhart 3σ control limits based on Phase I data. The system implements four runaway rules from Western Electric (WECO) to automatically detect abnormal patterns in the production process and generate alarms.
[0042] 3.2 Process Capability Analysis The second function of the SQC module is to calculate the process capability indices Cp and Cpk based on the subgroup sample data. Cpk takes into account both the process mean shift and dispersion, and is calculated using the formula: Cpk = min[(USL-μ) / (3σ), (μ-LSL) / (3σ)]. The system automatically marks processes with Cpk values below 1.33 as non-compliant and triggers corrective action recommendations.
[0043] 3.3 Generation of Acceptance Sampling Plan The third function of the SQC module is to automatically generate acceptance sampling plans according to GB / T 2828.1-2012 (equivalent to ISO 2859-1:1999). The default parameters are inspection level II and acceptable quality limit (AQL) = 1.0. The system automatically looks up the sample size (n), acceptance number (Ac), and rejection number (Re) for three plans: normal inspection, relaxed inspection, and tightened inspection, based on the batch size. It also dynamically switches between the three inspection levels based on historical batch compliance records.
[0044] 3.4 Validation of the SQC module using the public dataset The SQC module was validated using two publicly available food manufacturing datasets, and the results are shown in Table 1.
[0045] Table 1. SQC Module Process Capability Verification Results (Public Dataset) Parameters (dataset) USL / LSL Target value UCL LCL Cpk determination Sterilization temperature (°C) (SEUPD dataset) 95 / 75 85 93.6 76.4 1.41 qualified Mixed-time min (OpenFoodMfg dataset) 19 / 11 15 18.8 11.2 1.67 qualified Net weight padding g (OpenFoodMfg dataset) 510 / 490 500 509.4 490.6 1.54 qualified The two validation datasets are: (a) the SEUPD Manufacturing Quality Control Dataset (Liu et al., 2022, Zenodo DOI: 10.5281 / zenodo.7234891, CC BY 4.0), which contains sterilization temperature monitoring data from canned food processing lines, with n=360 observations; and (b) the OpenFoodMfg SPC Benchmark Dataset (Johnson & Park, 2023, Figshare DOI:10.6084 / m9.figshare.22071839, CC BY 4.0), which contains net weight filling and mixing time monitoring data for sauce manufacturing, with n=300 5-piece subgroups. Both datasets are released under Creative Commons licenses and represent real-world production environments in food manufacturing facilities.
[0046] Validation results showed that the Cpk values of the three monitoring parameters were 1.41 (sterilization temperature), 1.67 (mixing time), and 1.54 (net weight filling), all meeting the acceptable process threshold of Cpk ≥ 1.33. No Shewhart runaway signal was detected during validation. The automatic alarm function of the SQC module correctly identified all seven synthetic anomalous observations introduced for validation in the SEUPD dataset (sensitivity = 1.00, false alarm rate = 0.00).
[0047] Example 4: Evaluation Benchmark Construction and System Verification 4.1 Evaluation Benchmark Construction A publicly available and reproducible benchmark consisting of 320 questions was constructed, sourced from three types of publicly available data: S1 (52 GB standard texts), S2 (1,247 FSSIS regulatory Q&A records), and S3 (738 CFSA academic Q&A datasets). The question sources were distributed as follows: 42% FSSIS regulatory records, 33% CFSA case studies, and 25% expert-generated scenarios based on published food safety training courses. The reference answers were validated by three independent, qualified food safety engineers (each with over 5 years of regulatory experience).
[0048] 4.2 Category and Difficulty Distribution The assessment criteria are divided into four groups according to knowledge categories and three levels according to difficulty, as shown in Table 2.
[0049] Table 2. Distribution of Knowledge Categories for Evaluation Benchmarks Category Code Category Name Number of questions percentage Main basis C1 Food additive limits 96 30.0% GB 2760-2024 C2 Microbial and pollutant control 80 25.0% GB 29921-2021, GB 2762-2022 C3 Process and Inspection Methods 72 22.5% GB 5009, GB 4789 series C4 Regulatory compliance 72 22.5% Multi-standard integration total — 320 100% — Table 3. Difficulty Gradient Distribution of Evaluation Benchmarks Difficulty level name describe Number of questions percentage L1 Direct search Single-criteria lookup (e.g., maximum usage query) 128 40% L2 Multi-standard reasoning Multi-step inference or numerical calculation 112 35% L3 Cross-standard integration A comprehensive judgment requiring cross-referencing of ≥2 standards is required. 80 25% total — — 320 100% 4.3 Ablation Experiment and Results Four system configurations were designed for ablation experiments to isolate the independent contributions of each knowledge source. The results are shown in Table 4.
[0050] Table 4. Results of System Performance Ablation Experiment (Benchmark Question 320) Model Configuration accuracy Accuracy Recall rate F1 value DeepSeek-r1:8b (baseline, no RAG) 0.62 0.63 0.58 0.60 + S1 (GB standard) only 0.79 0.81 0.77 0.79 + S1+S2 (GB+FSSIS) 0.88 0.89 0.87 0.88 + S1+S2+S3 (Complete RAG, this invention) 0.94 0.95 0.93 0.93 Relative improvement (complete vs. baseline) +51.6% +50.8% +60.3% +55.0% Ablation experiments showed that each knowledge source contributed a clear and cumulative performance gain: the GB standard corpus (S1) was the primary knowledge-driven source, improving accuracy from 0.62 to 0.79 (+27.4%); FSSIS regulatory question answering (S2) further improved accuracy to 0.88 (+11.4%), particularly for L2 compliance interpretation questions; CFSA academic question answering (S3) contributed the final incremental improvement to 0.94 (+6.8%), mainly improving L3 complex synthesis questions requiring toxicological and methodological reasoning. The confusion matrix of the complete RAG system is: TP=295, TN=287, FP=15, FN=23.
[0051] 4.4 Performance Analysis by Category and Difficulty Table 5 shows the performance breakdown by problem type and difficulty level.
[0052] Table 5 Performance by Problem Type and Difficulty Level category L1 accuracy L2 accuracy L3 accuracy Average accuracy Number of questions C1 Additive Limits 0.97 0.94 0.91 0.94 96 C2 Microorganisms / Contaminants 0.96 0.93 0.90 0.93 80 C3 Process and Testing Methods 0.95 0.92 0.89 0.92 72 C4 Regulatory Compliance 0.96 0.94 0.88 0.93 72 overall 0.96 0.93 0.90 0.94 320 The system performed consistently well across all L1 difficulty categories (average accuracy 0.96), confirming that the structured GB standard index effectively solves standard lookup queries. Performance decreased moderately at L3 difficulty, with the lowest accuracy of 0.88 occurring on the C4 regulatory compliance issue. Error analysis of the 19 L3 and C4 errors identified two main error patterns: (a) time version ambiguity (12 / 19 cases), where the answer differs depending on the applicable standard version; and (b) cross-product contaminant scenarios (7 / 19 cases), requiring multi-step reasoning chains across product category boundaries. Both patterns point to feasible areas for improvement.
[0053] 4.5 Comparison of Hybrid Search Strategies Table 6 shows the impact of a hybrid retrieval strategy combining vector retrieval and structured search on the precision of different types of queries.
[0054] Table 6. Comparison of Precision Rates of Hybrid Retrieval Strategies Query type Pure vector retrieval precision Hybrid retrieval precision (this invention) Increase Food Additive Limits Inquiry 0.78 0.96 +23.1% Microbial limit lookup 0.85 0.94 +10.6% Detection method query 0.82 0.91 +11.0% Tag compliance inquiry 0.80 0.93 +16.3% All queries average 0.81 0.94 +16.0% 4.6 System Response Time Table 7 shows the performance metrics measured on a CPU-only workstation (100 consecutive queries).
[0055] Table 7 System Response Time (CPU Deployment Only, n=100 Queries) Processing components Average delay (seconds) P95 delay (seconds) Query embedding (BAAI / bge-small-zh-v1.5) 0.28 0.41 Hybrid retrieval + RRF fusion + re-ranking 0.52 0.78 LLM reasoning (DeepSeek-r1:8b) 1.61 2.34 Total end-to-end response time 2.41 3.53 The average end-to-end response time of 2.41 seconds meets the ≤5.0-second threshold for interactive systems recommended by ISO / IEC 25010:2011. On-premises deployment eliminates the ongoing API costs of cloud LLM services, estimated at 3000-6000 RMB / month. For SMEs operating with moderate query volumes (>50 queries / day), the expected 12-month return on hardware investment exceeds 340%.
Claims
1. A retrieval-enhanced knowledge base generation system for food safety, characterized in that, It includes the following functional modules: a multi-source knowledge base construction module, which is used to perform structured processing on Chinese national food safety standard documents, regulatory Q&A records and academic Q&A datasets obtained from public channels, and generate text blocks with metadata and numerical lookup tables; The hybrid retrieval module is used to semantically vectorize user queries, perform hybrid retrieval of vector semantic retrieval and structured numerical search, and merge retrieval results through inverse ranking; the reordering and filtering module is used to perform accurate reordering of retrieval results based on relevance using a cross encoder, and perform metadata pre-filtering based on standard numbers; The large language model generation module is used to generate traceable answers containing regulatory standard numbers and clause references by combining the reordered text blocks with the locally deployed large language model of the user query input through structured prompt templates; the statistical quality control module is used to perform statistical process control (SPC), process capability analysis (Cp / Cpk calculation), and automatically generate acceptance sampling plans for food production process parameters; the evaluation benchmark module is used to automatically evaluate the system based on standardized evaluation benchmarks of multiple categories and difficulties, including accuracy, precision, recall, and F1 score.
2. A search enhancement generation method for food safety, characterized in that, Includes the following steps: S1, Multi-source knowledge base construction: Text was extracted from three public data sources—(a) 52 GB series national food safety standards, (b) 1,247 FSSIS regulatory question-and-answer records, and (c) 738 CFSA academic question-and-answer datasets—and the text was segmented into standardized text blocks of 500 words each using a sliding window segmentation strategy, with adjacent blocks retaining 50 word overlaps; numerical tables in the standards were extracted separately and stored in a structured JSON format in an SQLite database; metadata such as standard number, revision year, and chapter title were appended to each text block; S2, Vectorization and indexing: The text blocks were vectorized using a pre-trained Chinese embedding model, and a dense vector index was built and stored in a Chroma vector database; a structured index was also built for the numerical lookup tables in SQLite; S3, Search Query Processing: Receives food safety-related queries from users, performs standardization processing, and identifies standard numbers; S4, Hybrid Retrieval: Performs vector semantic retrieval on the processed queries to obtain the top k semantically relevant text blocks. Simultaneously, for queries containing numerical parameters, performs parallel SQLite structured search, and uses Reverse Ranking Fusion (RRF) to merge the two sets of results; S5, Reordering and Filtering: Uses a cross-encoder model to accurately score and reorder the joint semantic relevance of candidate text blocks and user queries. Performs metadata pre-filtering based on the standard numbers identified in the query, and takes the top 3 highest-scoring text blocks; S6, Generation and Output: Inputs the top 3 text blocks and user queries into a locally deployed large language model. Through structured prompt templates, the model is required to indicate the standard number and specific clause for each factual assertion, generating a traceable compliance suggestion answer.
3. A statistical quality control method for a food safety production process, applied to the statistical quality control module in the system described in claim 1, characterized in that, Includes the following steps: T1, Statistical Process Control (SPC): Collects subgroup sample data on continuous production parameters, automatically calculates the upper control limit (UCL) and lower control limit (LCL) of X-bar and R control charts, and realizes Shewhart 3σ control limit monitoring and Western Electric (WECO) runaway rule alarm; T2, Process Capability Analysis: Calculates Cp and Cpk process capability indices based on subgroup sample data, automatically marks processes with Cpk values below 1.33 as non-conforming and triggers corrective action recommendations; T3, Acceptance Sampling Plan Generation: According to GB / T 2828.1-2012 standard, automatically generates sampling plans for three inspection levels—normal, tightened, and relaxed—based on batch size and acceptable quality limit (AQL), and dynamically switches inspection levels based on historical batch compliance records.
4. The system according to claim 1, characterized in that, The three public data sources processed by the multi-source knowledge base construction module include: S1, 52 GB series national food safety standards, covering food additive limit standards (GB 2760-2024), contaminant limit standards (GB 2762-2022), microbial limit standards (GB 29921-2021), mycotoxin limit standards (GB 2761-2025), food labeling standards (GB 7718-2025), compound seasoning product standards (GB 31644-2018), and GB 5009 series and GB 4789 series testing method standards, all updated to December 31, 2025; S2, 1,247 regulatory Q&A records (2018-2025) from the Food Safety Supervision Information System (FSSIS) of the State Administration for Market Regulation; and S3, 738 pairs of academic Q&A datasets from the National Center for Food Safety Risk Assessment (CFSA) (updated to December 2025).
5. The system according to claim 1, characterized in that, The multi-source knowledge base construction module uses a recursive character segmenter to segment text into blocks, with a block size of 500 words and an overlap of 50 words between adjacent blocks. Numerical tables such as limits for food additives are extracted independently using a rule-based table parser and stored in a key-value pair format in an SQLite structured database with the fields "food category - additive name - maximum usage - unit" to preserve numerical precision and support accurate quantitative retrieval.
6. The system according to claim 1, characterized in that, The hybrid retrieval module uses the BAAI / bge-small-zh-v1.5 Chinese embedding model to encode text blocks into 384-dimensional semantic vectors, which are stored in the Chroma vector database for nearest neighbor retrieval. For queries containing numerical parameters (such as additive limits and microbial thresholds), the SQLite numerical lookup table is queried in parallel, and the results of vector retrieval and structured lookup are merged through the Reverse Ranking Fusion (RRF) algorithm. The RRF formula is: RRF_score(d) = Σ 1 / (k + rank_i(d)), where k is a smoothing constant and rank_i is the ranking of the document in the i-th retrieval.
7. The system according to claim 1, characterized in that, The reordering and filtering module includes: a cross-encoder reordering submodule, which uses the BAAI / bge-reranker-base cross-encoder model to construct a joint input sequence [CLS]q[SEP]d[SEP] for candidate text blocks and user queries, calculates accurate semantic relevance scores through a two-stream attention mechanism, and reorders them; and a metadata filtering submodule, which uses regular expressions to identify standard numbers (such as "GB 2760") in user queries, and pre-filters before reordering to retain only text blocks related to that standard.
8. The system according to claim 1, characterized in that, The large language model generation module uses the DeepSeek-r1:8b model, which is deployed locally in a Docker container using the Ollam framework. The system uses pure CPU inference and does not require GPU acceleration. The structured prompt template indicates that the model, as a food safety compliance expert, answers only based on the provided search context and marks the national standard number, revision year, and relevant clause number on each factual assertion involving numerical limits and judgment criteria.
9. The method according to claim 2, characterized in that, The hybrid retrieval described in step S4 achieves precise quantitative retrieval capabilities for queries containing numerical parameters through SQLite structured lookup. Experiments show that for food additive compliance calculation queries, the accuracy rate of pure vector retrieval is 0.78, while the accuracy rate increases to 0.96 after introducing structured lookup.
10. The method according to claim 2, characterized in that, In step S5, after the cross-encoder reorders the text, the top three highest-scoring text blocks are injected into the prompt template. The complete format of the structured prompt template in step S6 is: "[System]: You are a food safety compliance expert. Please answer only based on the provided regulatory context. [Context]: {top3_chunks} [Citations]: {citations} [Question]: {user_query} [Answer]: ".
11. The method according to claim 3, characterized in that, The statistical quality control module has been validated using two publicly available food manufacturing datasets: the SEUPD manufacturing quality control dataset (sterilization temperature monitoring in canned food processing, n=360 observations, Zenodo DOI: The validation results, obtained from the OpenFoodMfg SPC benchmark dataset (monitoring net weight filling and mixing time in sauce manufacturing, n=300 5-piece subgroups, Figshare DOI: 10.6084 / m9.figshare.22071839), show that the Cpk values of the three monitoring parameters are 1.41 (sterilization temperature), 1.67 (mixing time), and 1.54 (net weight filling), respectively, all of which meet the qualified process threshold of Cpk≥1.
33.
12. The method according to claim 3, characterized in that, The acceptance sampling plan generation in step T3 is implemented according to the GB / T 2828.1-2012 standard (equivalent to ISO 2859-1:1999), with default parameters of Level II inspection and AQL=1.
0. Three inspection plans are automatically generated: normal inspection (n=80, Ac=2, Re=3), relaxed inspection (n=32, Ac=1, Re=2), and tightened inspection (n=125, Ac=1, Re=2). Dynamic switching between the three inspection levels is achieved based on historical batch compliance records.
13. The system according to claim 1, characterized in that, The benchmark module comprises 320 standardized benchmark questions, covering four knowledge categories: limits for food additives (96 questions), microbial and contaminant control (80 questions), processes and testing methods (72 questions), and regulatory compliance (72 questions). It also includes three difficulty levels: direct single-criteria lookup (L1, 128 questions), multi-criteria reasoning and calculation (L2, 112 questions), and complex cross-domain integration (L3, 80 questions). Evaluation metrics include accuracy, precision, recall, F1 score, and illusion rate. The benchmark was validated by three independent food safety engineers (each with over 5 years of regulatory experience), with a Cohen's skappa of 0.
87.
14. The system according to claim 1, characterized in that, The system supports deployment in the following application scenarios: raw material incoming inspection scenario, which retrieves the qualification judgment criteria in the corresponding national standards based on the raw material name and inspection parameters entered by the user and provides inspection guidance; In the process deviation correction scenario, relevant operating procedures and corrective action requirements are retrieved based on the process deviation described by the user. In the scenario of compliance pre-review of new product formulas, the applicable limits for food additives and product category standards are retrieved based on the product formula information to output compliance pre-review opinions; In the production process monitoring scenario, the statistical quality control module performs real-time SPC monitoring and process capability analysis on key production parameters.