A method, system, equipment, and medium for quantitative Raman spectroscopy analysis combining a large language model.

CN122570745APending Publication Date: 2026-08-14SUZHOU YITAN INSTRUMENT TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-04-30
Publication Date
2026-08-14

AI Technical Summary

Technical Problem

[0005]本发明提供了一种结合大语言模型的拉曼光谱定量分析方法、系统、设备及介质,以解决现有技术中拉曼光谱定量分析对分析情境变化的适应性差、训练成本高昂、知识利用率低以及模型可解释性不足等技术缺陷

Benefits of technology

[0019]本发明通过标准化预处理将原始光谱转化为统一可比的标准数据,减少了对大量校准样本的依赖。随后利用小波变换和谱峰拟合自动提取特征峰参数,并转换为结构化文本,从而显性化物理特征,替代传统人工经验与数据驱动的“黑箱”学习。基于此,构建包含多维度信息的结构化知识库,通过向量化检索实现情境感知的智能匹配;其与模型参数解耦的设计,使得在分析情境变化或新增物质时,仅更新知识库即可快速响应,无需重新训练模型。进一步,通过嵌入预设推理逻辑的提示模板,约束大语言模型遵循标准化、可追溯的分析路径生成定量结果。最终输出包含计算步骤、特征峰依据及不确定度评估的透明报告,并通过独立引擎验证,在保证高精度的同时满足可靠性与可解释性要求。整个系统仅需少量样本微调,实现了“一次构建、多次复用”的快速部署能力。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122570745A_ABST
    Figure CN122570745A_ABST
Patent Text Reader

Abstract

This invention discloses a method, system, device, and medium for quantitative Raman spectroscopy analysis combined with a large language model, relating to the interdisciplinary field of spectral analysis and artificial intelligence. The method includes: acquiring Raman spectral data corresponding to the sample to be tested and preprocessing it to obtain standard Raman spectral data; extracting features from the standard Raman spectral data to obtain structured feature text; searching for target quantitative relational units from a knowledge base based on the structured feature text and contextual information of the sample to be tested; generating contextual prompts based on the structured feature text and the target quantitative relational units using a preset prompt template; inputting the contextual prompts into a fine-tuned large language model; and outputting an analysis report of the sample to be tested through the fine-tuned large language model. This improves the adaptability of Raman spectroscopy quantitative analysis to contextual changes, knowledge utilization, and interpretability of model output, while reducing training costs and shortening the development cycle.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of interdisciplinary technology of spectral analysis and artificial intelligence, and in particular to a method, system, device and medium for quantitative Raman spectroscopy analysis that combines a large language model. Background Technology

[0002] Raman spectroscopy, a molecular vibrational spectroscopy method based on the Raman scattering effect, plays a crucial role in chemical analysis. The technical approaches to achieving quantitative analysis using Raman spectroscopy mainly fall into two categories: traditional chemometric methods, represented by partial least squares regression, and end-to-end learning methods based on deep neural networks.

[0003] However, existing technologies face multiple bottlenecks. First, model construction heavily relies on standard samples covering a full concentration range, but practically available samples are scarce and their preparation costs are high. Second, insufficient knowledge utilization: traditional methods rely on human experience, while deep learning methods lack effective integration of domain knowledge (such as material priors and contextual experience). Third, poor model interpretability, especially deep learning, which is like a "black box," unable to provide clear evidence based on characteristic peaks, making it difficult to meet the traceability needs of highly reliable industrial scenarios. Fourth, weak adaptability: models are usually designed for specific substances and contexts, and need to be rebuilt once conditions change, resulting in long deployment cycles and an inability to quickly respond to dynamic detection needs.

[0004] Therefore, existing technologies have significant shortcomings in terms of adaptability, cost, knowledge utilization, and interpretability of quantitative Raman spectroscopy. More advanced methods are needed to improve the adaptability, knowledge utilization, and model interpretability of quantitative Raman spectroscopy, while reducing costs. It is necessary to provide a quantitative Raman spectroscopy method that combines a large language model to solve the above problems. Summary of the Invention

[0005] This invention provides a method, system, device, and medium for quantitative Raman spectroscopy analysis that combines a large language model, in order to solve the technical defects of existing Raman spectroscopy quantitative analysis, such as poor adaptability to changes in the analysis context, high training costs, low knowledge utilization, and insufficient model interpretability.

[0006] In a first aspect, embodiments of the present invention provide a Raman spectroscopy quantitative analysis method combining a large language model, comprising:

[0007] The Raman spectral data corresponding to the sample to be tested is acquired, and the Raman spectral data is preprocessed to obtain standard Raman spectral data. Feature extraction is performed on the standard Raman spectral data to obtain structured feature text. Based on the structured feature text and the contextual information of the sample to be tested, the target quantitative relational unit is searched from a pre-constructed knowledge base. Based on the structured feature text and the target quantitative relational unit, contextual prompts are generated using a preset prompt template. The contextual prompts are input into a fine-tuned large language model, and the fine-tuned large language model outputs an analysis report of the sample to be tested.

[0008] Optionally, the construction of the knowledge base includes: extracting quantitative relationships of different substances under different contexts from multidimensional data source information; formatting and filling the quantitative relationships of different substances under different contexts into the data structure of the quantitative relationship unit; wherein, the data structure of the quantitative relationship unit is a data structure containing five core domains, namely, the substance information domain, the spectral feature domain, the quantitative relationship domain, the applicable condition domain, and the reliability index domain; and constructing a knowledge base based on each of the quantitative relationship units.

[0009] Optionally, after the knowledge base is constructed, the method further includes: performing hybrid vectorization encoding on each of the quantitative relation units in the knowledge base to generate a hybrid vector corresponding to each of the quantitative relation units; storing each of the hybrid vectors in a vector database and establishing an approximate nearest neighbor search index.

[0010] Optionally, based on the structured feature text and the contextual information of the sample to be tested, a quantitative relation unit corresponding to the structured feature text is searched from a pre-built knowledge base. This includes: encoding the structured feature text into a query vector; performing an approximate nearest neighbor search in a vector database to determine a preset number of mixed vectors with the highest similarity; searching for corresponding candidate quantitative relation units from the pre-built knowledge base based on the vector IDs corresponding to each mixed vector; and calculating the matching degree between each candidate quantitative relation unit and the contextual information of the sample to be tested and the structured feature text, and determining the candidate quantitative relation unit with the highest matching degree as the target quantitative relation unit.

[0011] Optionally, the step of calculating the matching degree between the candidate quantitative relation units and the contextual information of the sample to be tested and the structured feature text, and determining the candidate quantitative relation unit with the highest matching degree as the target quantitative relation unit, includes: calculating the spectral feature matching degree, contextual applicability, and knowledge quality of each candidate quantitative relation unit based on the contextual information of the sample to be tested and the structured feature text; determining the matching degree between the sample to be tested and each candidate quantitative relation unit based on the spectral feature matching degree, contextual applicability, and knowledge quality corresponding to each candidate quantitative relation unit; and determining the candidate quantitative relation unit with the highest matching degree as the target quantitative relation unit.

[0012] Optionally, based on the structured feature text and the target quantitative relation unit, contextual prompts are generated using a preset prompt template, including: based on the structured feature text and the target quantitative relation unit, contextual prompts are generated using a preset prompt template embedded with a preset logical chain; wherein, the preset logical chain strictly defines six steps for generating contextual prompts.

[0013] Optionally, the large language model can be fine-tuned, including:

[0014] The large language model is fine-tuned using a hybrid loss function that incorporates domain knowledge. This hybrid loss function is composed of a weighted average of concentration prediction loss, characteristic peak intensity-aware alignment loss, and logical consistency loss. The concentration prediction loss is used to calculate the relative error between the concentration value predicted by the large language model and the actual concentration value. The characteristic peak intensity-aware alignment loss is used to calculate the relative error between the theoretical quantitative peak intensity calculated from the concentration predicted by the large language model and the peak intensity actually measured by the Raman spectrum. The logical consistency loss is used to penalize logical errors present in the output of the large language model, where logical errors include at least: predicting concentrations outside the linear range without declaration, failing to report the influence of known interfering substances, and claiming the result is reliable when the applicable conditions are not met.

[0015] Secondly, embodiments of the present invention provide a Raman spectroscopy quantitative analysis system incorporating a large language model, the system being used to execute the Raman spectroscopy quantitative analysis method incorporating a large language model as described in any embodiment of the present invention, including:

[0016] The system comprises the following modules: a preprocessing module for acquiring Raman spectral data corresponding to the sample to be tested, preprocessing the Raman spectral data to obtain standard Raman spectral data; a feature extraction module for extracting features from the standard Raman spectral data to obtain structured feature text; a search module for searching for target quantitative relational units from a pre-built knowledge base based on the structured feature text and the contextual information of the sample to be tested; a generation module for generating contextual prompts based on the structured feature text and the target quantitative relational units, using a preset prompt template; and an output module for inputting the contextual prompts into a fine-tuned large language model and outputting an analysis report of the sample to be tested through the fine-tuned large language model.

[0017] Thirdly, embodiments of the present invention provide an electronic device, the electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to execute the Raman spectroscopy quantitative analysis method combining a large language model as described in any embodiment of the present invention.

[0018] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing computer instructions, which are used to cause a processor to execute and implement the Raman spectroscopy quantitative analysis method combining a large language model as described in any embodiment of the present invention.

[0019] This invention transforms raw spectra into uniform and comparable standard data through standardized preprocessing, reducing reliance on a large number of calibration samples. Subsequently, wavelet transform and peak fitting are used to automatically extract characteristic peak parameters, which are then converted into structured text, thus making physical features explicit and replacing traditional manual experience and data-driven "black box" learning. Based on this, a structured knowledge base containing multi-dimensional information is constructed, achieving context-aware intelligent matching through vectorized retrieval. Its decoupling design from model parameters allows for rapid response by simply updating the knowledge base when the analysis context changes or new substances are added, without retraining the model. Furthermore, by embedding prompt templates with pre-defined reasoning logic, the large language model is constrained to follow a standardized and traceable analysis path to generate quantitative results. The final output is a transparent report containing calculation steps, characteristic peak basis, and uncertainty assessment, verified by an independent engine, ensuring high accuracy while meeting reliability and interpretability requirements. The entire system requires only a small number of samples for fine-tuning, achieving rapid deployment capability of "build once, reuse many times".

[0020] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in 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.

[0022] Figure 1 A flowchart of a Raman spectroscopy quantitative analysis method combining a large language model is provided in Embodiment 1 of the present invention;

[0023] Figure 2 This is a flowchart of a Raman spectroscopy quantitative analysis method combining a large language model, provided in Embodiment 2 of the present invention.

[0024] Figure 3 This is a framework diagram of a Raman spectroscopy quantitative analysis system combining a large language model, provided in Embodiment 3 of the present invention. Detailed Implementation

[0025] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. 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.

[0026] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0027] Example 1:

[0028] Figure 1 This is a flowchart of a Raman spectroscopy quantitative analysis method combining a large language model, provided in Embodiment 1 of the present invention. This embodiment is applicable to the quantitative analysis of Raman spectra, and the method can be executed by a Raman spectroscopy quantitative analysis system combining a large language model. Figure 1 As shown, the method includes:

[0029] S110. Obtain the Raman spectral data corresponding to the sample to be tested, and preprocess the Raman spectral data to obtain standard Raman spectral data. S120. Extract features from the standard Raman spectral data to obtain structured feature text. S130. Based on the structured feature text and the contextual information of the sample to be tested, search for the target quantitative relational unit from a pre-built knowledge base. S140. Based on the structured feature text and the target quantitative relational unit, generate contextual prompts using a preset prompt template. S150. Input the contextual prompts into a fine-tuned large language model, and output an analysis report of the sample to be tested through the fine-tuned large language model.

[0030] In this embodiment, the original spectrum is transformed into standard data through preprocessing (such as baseline correction and normalization) to ensure data consistency; structured text is generated using feature extraction, enabling the spectral information to be parsed by the model; target quantitative relation units are intelligently retrieved from the knowledge base based on contextual information to achieve accurate matching with context awareness; contextual prompts are generated using preset prompt word templates to guide model reasoning; and a transparent and interpretable analysis report is output using a fine-tuned large language model. Through the decoupling design of the knowledge base and the model, only a small number of training samples (such as 3-5) are needed to establish quantitative relations, significantly reducing costs and development cycles. At the same time, multi-dimensional matching and logical constraints are used to enhance accuracy and reliability. The output results include a complete calculation process and reliability assessment, meeting the high standards required for industrial applications.

[0031] Example 2:

[0032] The technical solution in this embodiment is a further refinement based on the above embodiments.

[0033] Optionally, in step S110, acquiring the Raman spectral data corresponding to the sample to be tested and preprocessing the Raman spectral data to obtain standard Raman spectral data includes:

[0034] Acquire the Raman spectral data corresponding to the sample to be tested, and perform quality inspection on the Raman spectral data;

[0035] Specifically, the raw Raman spectrum file containing wavenumber and scattering intensity sequences is read, and the file format is JCAMP-DX or dual-column ASCII text format. The received raw Raman spectrum data undergoes quality checks, including: checking the monotonicity of the wavenumber sequence, checking the non-negativity of the intensity values, calculating the overall signal-to-noise ratio, and performing a signal-to-noise ratio check.

[0036] Specifically, after successfully reading the raw Raman spectral data, a quality check procedure is immediately triggered. This procedure first verifies the monotonicity of the wavenumber sequence to ensure it is strictly increasing and prevents wavenumber axis reversal or confusion due to data recording errors. The specific verification method involves reading the wavenumber sequence, extracting the wavenumber column from the raw data, and forming an array, for example, wavenumbers = [350.0, 350.5, 351.0, 351.5, ... , 1799.5, 1800.0]. Starting from the second element of the array, each wavenumber value is compared with its preceding value. For index i (from 1 to n-1), diff = wavenumbers[i] - wavenumbers[i-1]. If all diffs are greater than 0, the sequence is strictly monotonically increasing, and the verification passes. If any diff is less than or equal to 0, the sequence is not monotonically increasing, and the verification fails. If the verification fails, the spectral data is marked as invalid and an error message is displayed, thus avoiding the use of erroneous data for subsequent analysis.

[0037] Secondly, a non-negativity check is performed on all intensity values ​​in the intensity sequence; any negative intensity value is considered an invalid data point. Further, the overall signal-to-noise ratio of the original Raman spectrum is calculated using the ratio of the standard deviation of the signal interval to the noise interval. The signal interval can refer to the region containing the main characteristic peaks in the Raman spectrum data corresponding to the sample. For example, an automatic selection strategy can be used, calculating the intensity distribution of the entire spectrum and selecting the wavenumber range with the highest intensity values ​​in the top 10% as the signal interval. For known substances, the region containing their key characteristic peaks can be directly specified as the signal interval, for example, 1000 cm⁻¹-1200 cm⁻¹. The noise interval can refer to a flat region in the Raman spectrum data corresponding to the sample, where there is no obvious signal at either end. Within the selected noise range, the standard deviation of all intensity values ​​is calculated. Within the selected signal range, the standard deviation of the signal range is divided by the standard deviation of the noise range to obtain an estimated signal-to-noise ratio. If the calculated estimated signal-to-noise ratio is lower than the preset threshold, such as 3:1, the spectrum is judged to be of unacceptable quality. The original Raman spectrum data is marked and removed from the subsequent processing flow, and a warning is issued to the operator.

[0038] In this embodiment, a series of basic but critical validity checks are performed to ensure the intrinsic consistency and usability of the raw Raman spectral data.

[0039] The Raman spectral data that has passed the quality inspection are preprocessed to obtain standard Raman spectral data; wherein, the preprocessing may include: baseline correction, cosmic ray peak removal, standard interval truncation, normalization processing, and grid resampling.

[0040] Specifically, due to the scattering effects of fluorescent substances or substrate materials commonly present in the test samples, the Raman spectra of the test samples are often superimposed on a broad, varied background, which severely affects the accurate identification and intensity quantification of characteristic peaks. Therefore, an asymmetric least squares smoothing algorithm can be used for baseline correction to remove the broad background caused by sample fluorescence or substrate scattering. For example, in a specific parameter setting, the smoothing factor λ is set to 10. 7 The asymmetry factor p was set to 0.01. This algorithm adaptively identifies and fits the true baseline shape during iteration without distorting sharp Raman characteristic peaks. Subtracting this fitted baseline from the Raman spectrum of the sample yields a clean Raman spectrum free of fluorescence background interference, thus achieving efficient and accurate background subtraction. Cosmic rays are common random interferences in Raman spectroscopy measurements, manifesting as sharp pulses with extremely narrow widths (typically occupying only 1-3 data points) and extremely high intensity. Median filtering algorithms based on moving windows can be used to identify and remove these anomalous signals. For example, a sliding window with a width of 5 data points can be set. If the intensity value at the center of the window is significantly higher than the median of its neighboring points, that point is identified as a cosmic ray peak and replaced with the median or mean of its neighboring points.

[0041] To focus on the most information-rich molecular fingerprint region and ensure that the spectra of all input models have a unified horizontal axis, the wavenumber range of the original Raman spectra is truncated through a preset standard interval, which can be between 350 cm⁻¹ and 1800 cm⁻¹. This interval covers the characteristic vibrations of most organic compounds and biomolecules and is the core region for substance identification and quantification. To eliminate absolute signal intensity variations caused by differences in experimental conditions such as laser power fluctuations, integration time differences, or changes in instrument optical path efficiency, a maximum-minimum normalization method can be used to linearly transform the truncated spectral intensity sequence, mapping the maximum value to 1 and the minimum value to 0. The specific calculation formula is as follows:

[0042]

[0043] in, For original strength, and These represent the maximum and minimum values ​​of the spectral intensity sequence, respectively. Normalization preserves the relative peak shape information of the spectrum, which is fundamental for cross-sample, cross-time, and cross-instrument comparisons. Since different instruments may have varying spectral resolutions and data sampling intervals, to ensure dimensionality consistency of subsequent model inputs such as convolutional neural networks, a cubic spline interpolation algorithm can be used to accurately resample all normalized spectral data onto a standard, high-density wavenumber grid. This not only ensures dimensional uniformity of the spectral data but also maximizes the preservation of the smooth shape and physical meaning of the Raman spectrum. In a specific implementation, this standard grid can be defined as a starting wavenumber of 350.0 cm⁻¹, an ending wavenumber of 1800.0 cm⁻¹, and a wavenumber interval of 1.0 cm⁻¹, thereby generating a normalized one-dimensional vector containing 1451 data points. Thus, the original Raman spectral data is transformed into a standard numerical spectrum with uniform dimensionality, background subtraction, and intensity normalization.

[0044] In this embodiment, by preprocessing the raw Raman spectral data that has passed quality inspection, non-targeted variations introduced by the instrument, environment and the sample itself are eliminated, so that the spectral data returns to an ideal and comparable state, ensuring that the spectral data of all input models have a unified dimension and data structure.

[0045] Optionally, in step S120, the feature extraction of the standard Raman spectral data to obtain structured feature text includes: determining the position of the characteristic peaks in the standard Raman spectral data using a continuous wavelet transform algorithm with the Mexican hat wavelet as the mother wavelet function based on the standard Raman spectral data; obtaining four characteristic peak parameter values ​​by fitting a Gaussian-Lorentz mixture function based on the characteristic peak positions; and converting each of the characteristic peak parameter values ​​into structured feature text using a predefined syntax template.

[0046] Specifically, the Continuous Wavelet Transform (CWT) algorithm can be used. The Mexican hat wavelet is chosen as the mother wavelet function because its shape is highly similar to the ideal Raman peak shape, enabling a strong response to characteristic peaks. The CWT algorithm performs multi-scale transformation on the standard Raman spectral data within a preset scale range (e.g., from scale parameter 1 to 64), generating a two-dimensional scale-wavenumber wavelet coefficient matrix. The existence of characteristic peaks is represented by local maxima in this matrix. By tracing the ridges formed by these maxima, the wavenumber position of each characteristic peak can be accurately located. Based on the length, amplitude, and other characteristics of the ridges, short and weak ridges caused by noise are filtered out, leaving each remaining effective ridge corresponding to a true characteristic peak. The wavenumber position of the ridge apex is the precise location of the peak. The multi-scale analysis characteristics of CWT make it insensitive to noise and effectively distinguish closely overlapping peaks in the spectrum.

[0047] After identifying all potential characteristic peak locations, a local window is defined around each peak, and a nonlinear least-squares fit is performed on the spectral data within this window using a Gaussian-Lorentz mixture function (Pseudo-Voigt function). This mixture function can flexibly describe various true peak shapes, from pure Gaussian to pure Lorentz. The output of the fitting process is the precise values ​​of four core peak parameters: peak center position (wavenumber), peak intensity (intensity), full width at half maximum (FWHM), and peak area (area) obtained by integrating the fitted curve.

[0048] In this embodiment, the characteristic peaks carrying chemical information are automatically and accurately identified from the continuous spectral curves using a continuous wavelet transform algorithm and a Gaussian-Lorentz mixture function, and their parameters are quantitatively described.

[0049] The value of each feature peak parameter is converted into structured feature text using a predefined syntax template.

[0050] Specifically, the sample information and the values ​​of each characteristic peak parameter can be converted into structured feature text according to a fixed predefined syntax template. For example, the fixed predefined syntax template format could be: "Sample Number: [ID]; Test Conditions: [Conditions]; Analysis Range: [Range]; Characteristic Peak List: [PEAK_AT: {Position 1}_INT: {Intensity 1}_FWHM: {Half Width 1}; PEAK_AT: {Position 2}_INT: {Intensity 2}_FWHM: {Half Width 2}; ...]; Overall Morphological Description: [Description]". This structured text representation, compared to pure natural language descriptions, retains all quantitative information and provides a clear analytical structure for subsequent model processing. The processed raw numerical spectra and structured feature text are stored together for later retrieval.

[0051] In this embodiment, all quantitative peak parameter information is fully preserved through key-value pairs, avoiding information loss and ambiguity in pure natural language descriptions. Furthermore, the use of delimiters (such as semicolons) and keywords (such as PEAK_AT) provides clear guidance for subsequent LLM parsing and information extraction.

[0052] Optionally, the construction of the knowledge base includes: extracting quantitative relationships of different substances under different contexts from multidimensional data source information; formatting and filling the quantitative relationships of different substances under different contexts into the data structure of the quantitative relationship unit; wherein, the data structure of the quantitative relationship unit is a data structure containing five core domains, namely, the substance information domain, the spectral feature domain, the quantitative relationship domain, the applicable condition domain, and the reliability index domain; and constructing a knowledge base based on each of the quantitative relationship units.

[0053] Specifically, multidimensional data sources include publicly available Raman spectroscopy standard databases (such as RRUFF™), scientific literature databases (such as PubMed, Scopus), and internally accumulated laboratory calibration datasets. To efficiently extract knowledge from massive amounts of unstructured literature, a BERT model pre-trained on scientific text can be used. This model can semi-automatically identify and extract information fragments related to quantitative relationships, applicable conditions, and interfering factors from papers. The extracted information is then manually reviewed, verified, and supplemented by domain experts, and finally formatted and populated into the QR Unit data structure. Each substance corresponds to an independent QR Unit in each specific context, and a knowledge base is built based on each quantitative relationship unit. Its data structure includes five main parts: substance information, spectral characteristics, quantitative relationships, applicable conditions, and reliability indicators, each defined as an information domain.

[0054] The material information field should include the common chemical name of the different substances obtained from databases or literature (e.g., "sildenafil"), the unique CAS registration number (e.g., "139755-83-2"), and the molecular formula (C64- ... 28 H 38 N6O 11 S) and precise molecular weight, etc. The spectral feature domain stores standard Raman spectra of different substances measured under standard reference conditions and processed through the same procedure as the aforementioned spectral data preprocessing stage. In addition, this domain also contains a list of key characteristic peaks, which not only lists the precise wavenumber positions of the main characteristic peaks of each substance, but also includes their corresponding molecular vibrational mode assignments (e.g., "1125 cm⁻¹: COH bending vibration"), providing a physicochemical basis for the interpretability of subsequent model outputs.

[0055] The quantitative relation domain meticulously records the quantitative peak positions, quantitative functions (e.g., I = k*C + b) and their parameters (k, b), linear range (Cmin, Cmax), limit of detection (LOD), and limit of quantitation (LOQ) for different substances. The quantitative peak position can refer to the precise wavenumber position of the quantitative characteristic peak. The quantitative function describes the specific mathematical form and parameters of the relationship between a parameter of the characteristic peak (e.g., peak height or peak area, I) and the substance concentration (C). For example, for the most common linear relationship I = k*C + b, this domain explicitly records the values ​​of the slope k and intercept b of the calibration curve. Crucially, this domain also records the linear dynamic range for which the quantitative relationship holds, i.e., the lower limit of concentration C_min and the upper limit of concentration C_max; finally, it also includes the limit of detection (LOD) and limit of quantitation (LOQ) of the quantitative method obtained from standard method validation.

[0056] The applicable conditions domain details the preconditions for the quantitative relationship to hold, including chemical environment, physical state, matrix effect, and interfering factors, through a structured list of parameters. For a more refined description, this domain is further divided into four subdomains. The chemical environment subdomain describes the chemical matrix of different substances under different specific conditions, given the quantitative relationship. For example, it specifies whether the matrix is ​​"deionized water," "0.1M phosphate buffer," or "microcrystalline cellulose (pharmaceutical excipient)"; the pH range, for example, pH 6.8-7.5; and the upper limit of ionic strength. The physical state subdomain records the physical forms of different substances under different specific conditions, given the quantitative relationship, such as solution, lyophilized powder, and hydrogel; and the range of ambient temperature fluctuations during measurement, for example, 20-25°C. The matrix effect subdomain lists, in whitelist form, known non-target substances that can coexist under this quantitative relationship without significant impact, along with their upper concentration limits. The interfering factors subdomain, in blacklist form, structurally records all known interfering substances that negatively impact this quantitative relationship. For each listed interfering substance, this subdomain provides a detailed description, including its interference mechanism, such as "the 855 cm⁻¹ peak of lactate overlaps with the 850 cm⁻¹ shoulder of the target substance," "bovine serum albumin (BSA) introduces a strong fluorescence background," or "a substance reacts chemically with the target substance, causing signal attenuation," etc.; the specific manifestations of the interference, such as "leading to a systematic overestimation of the quantitative peak intensity by 15%"; and, where possible, providing feasible correction strategies or suggestions, such as "it is recommended to use an auxiliary peak at 1460 cm⁻¹ for ratio correction" or "an additional background subtraction step is required."

[0057] The reliability metrics field provides metadata for each QR Unit to assess its reliability and applicability priority. This field records the data source for this quantitative relationship, which could be a specific scientific literature citation, an internal lab report number, or an entry ID in a public database. Furthermore, it includes two dynamically updated metrics: the historical call frequency of the QR Unit, and the average prediction accuracy calculated based on validation results from all historical call cases.

[0058] Furthermore, the same substance should have different QR units in different contexts. For example, "QR Unit of glucose in aqueous solution" and "QR Unit of glucose in serum" are two separate units.

[0059] In this embodiment, through the precise design of the five information domains mentioned above, the knowledge base transforms the tacit knowledge originally scattered in literature, experimental records, and the minds of experts into an explicit, structured, and computable knowledge asset. This allows the same substance to be associated with multiple different QR Units, each precisely corresponding to its quantitative behavior in different scenarios such as aqueous solutions, ethanol solutions, different pH values, or the presence of specific interfering substances, thereby constructing a vast and sophisticated quantitative knowledge network.

[0060] Optionally, after the knowledge base is constructed, the method further includes: performing hybrid vectorization encoding on each of the quantitative relation units in the knowledge base to generate a hybrid vector corresponding to each of the quantitative relation units; storing each of the hybrid vectors in a vector database and establishing an approximate nearest neighbor search index.

[0061] Specifically, to achieve efficient retrieval, a hybrid vectorization encoding is performed on each QR Unit in the knowledge base. The text fields of the QR Unit (substance description, applicable conditions, etc.) are encoded into a semantic vector V_text using a pre-trained scientific language model (such as SciBERT). The standard spectral numerical vector of the QR Unit is encoded into a spectral feature vector V_spectral using a pre-trained one-dimensional convolutional neural network (1D-CNN). The two vectors V_text and V_spectral are directly concatenated to form a longer hybrid vector. For example, a 768-dimensional text vector + a 256-dimensional spectral vector = a 1024-dimensional hybrid vector. Before concatenation, different weights can be assigned to different types of vectors to emphasize their importance; this embodiment does not impose limitations on this. The concatenated hybrid vector is L2 normalized, i.e., scaled to a unit length. L2 normalization of the hybrid vector ensures the fairness and accuracy of subsequent similarity calculations (such as using cosine similarity). All the mixed vectors and their corresponding QR Unit IDs are stored together in a vector database that supports efficient Approximate Nearest Neighbor (ANN) search.

[0062] As a concrete implementation, the FAISS library can be used as the vector database, and an index structure combining inverted files and product quantization (e.g., IndexIVFPQ) can be constructed. That is, during index construction, a clustering algorithm (such as k-means) can be used to divide the entire vector space into k partitions (e.g., 1024), each partition being called a "bucket" or "inverted list." The vector of each QR Unit is assigned to its own bucket. When a query vector arrives, this coarse quantizer first quickly determines which bucket(s) or buckets are most relevant (e.g., finding the one or two closest buckets), instantly narrowing the search range from millions to thousands or hundreds. Furthermore, product quantization divides the high-dimensional vector into multiple segments, quantizes each segment, and uses compressed encoding to represent the original vector. Therefore, calculating the distance between two vectors can be approximated as calculating the distance between their compressed encodings, resulting in extremely fast speed. The search process involves quickly calculating the distance (e.g., Euclidean distance or cosine similarity) between the query vector and the PQ codes of all QR Unit vectors within the bucket, once a relevant bucket is located. The N (e.g., 20) results with the smallest distance (or highest similarity) are retained and sorted from highest to lowest according to their similarity score with the query vector, resulting in a candidate list containing: unique identifiers for the N QR Units; and the similarity score (or distance value) between each QR Unit and the query vector.

[0063] In this embodiment, the search space is significantly reduced by using an inverted index, and distance calculation is accelerated by using product quantization, so as to achieve millisecond-level retrieval response on a knowledge scale of hundreds of millions.

[0064] Optionally, in step S130, based on the structured feature text and the contextual information of the sample to be tested, the target quantitative relation unit corresponding to the structured feature text is searched from a pre-built knowledge base, including: encoding the structured feature text into a query vector; performing an approximate nearest neighbor search in a vector database to determine a preset number of mixed vectors with the highest similarity; searching for corresponding candidate quantitative relation units from the pre-built knowledge base based on the vector IDs corresponding to each mixed vector; and calculating the matching degree between each candidate quantitative relation unit and the contextual information of the sample to be tested and the structured feature text, and determining the candidate quantitative relation unit with the highest matching degree as the target quantitative relation unit.

[0065] Specifically, a two-stage screening process, from coarse to fine, can be adopted. The first stage is the initial screening of candidates. The structured feature text of the sample to be tested is converted into a query vector using the same text encoder (such as SciBERT) used when building the knowledge base. Then, an ANN search is performed in the vector database. The goal of this search is to find the QR Units that are most similar to the Raman spectra of the sample to be tested in terms of semantic and spectral features. The candidates are sorted from high to low according to their similarity scores with the query vector, resulting in a list of candidate mixed vectors containing: unique identifiers (i.e., vector IDs) for N QR Units; and a similarity score (or distance value) between each QR Unit and the query vector. Based on the N vector IDs, the knowledge base is queried to obtain the complete, structured QR Unit information corresponding to the N vector IDs. This completes the initial narrowing of the pool.

[0066] The system acquires contextual information for the sample to be tested. This information comes from sources such as: known analytical conditions explicitly entered by the operator through a graphical user interface (GUI), including matrix type (e.g., selecting "aqueous solution," "serum," or "ethanol"), sample pH, and estimated target analyte concentration range. Preliminary contextual inferences are also made based on spectral characteristics. For example, detecting the presence of a broad peak representing the OH stretching vibration of water near ~3400 cm⁻¹ automatically determines whether the sample is an aqueous matrix; analyzing the overall signal-to-noise ratio and the normalized intensity of the strongest peak provides a preliminary estimate of the target analyte concentration (high, medium, or low). If the above information is insufficient, a set of preset default contextual values ​​is used, such as room temperature (25°C) and neutral pH (7.0). All collected or inferred contextual information is structured and stored for subsequent matching calculations.

[0067] Optionally, the step of calculating the matching degree between the candidate quantitative relation units and the contextual information of the sample to be tested and the structured feature text, and determining the candidate quantitative relation unit with the highest matching degree as the target quantitative relation unit, includes: calculating the spectral feature matching degree, contextual applicability, and knowledge quality of each candidate quantitative relation unit based on the contextual information of the sample to be tested and the structured feature text; determining the matching degree between the sample to be tested and each candidate quantitative relation unit based on the spectral feature matching degree, contextual applicability, and knowledge quality corresponding to each candidate quantitative relation unit; and determining the candidate quantitative relation unit with the highest matching degree as the target quantitative relation unit.

[0068] Specifically, the second level involves refined matching and re-ranking. For each candidate QRUnit selected in the first level, a more comprehensive overall matching score is calculated. This score is obtained by weighted averaging of scores from three different dimensions: spectral feature matching degree, contextual suitability, and knowledge quality.

[0069]

[0070] in, To determine the spectral feature matching degree, we can calculate the average deviation between the positions of the main characteristic peaks in the standard Raman spectrum corresponding to the test sample and the characteristic peak positions in the QR Unit standard spectrum; calculate the Pearson correlation coefficient between the two spectra in the characteristic region; and calculate the coverage of the characteristic peaks of the standard Raman spectrum corresponding to the test sample to the characteristic peaks of the QR Unit standard spectrum. Specifically, we standardize and weight-fuse these three indicators with different dimensions and meanings—average position deviation, Pearson correlation coefficient, and peak coverage—to obtain a comprehensive spectral feature matching degree score.

[0071] Specifically, the absolute value of the positional deviation between the standard Raman spectrum corresponding to the test sample and all matching characteristic peaks in the QR Unit standard spectrum is calculated, and then the average value is calculated; the smaller the deviation, the better. A maximum permissible deviation threshold is set. If the absolute value of the deviation is 0, the average positional deviation score is 1; if the absolute value of the deviation is greater than or equal to the maximum permissible deviation threshold, the average positional deviation score is 0; between 0 and the maximum permissible deviation threshold, the score decreases linearly. At the common characteristic peak positions, the intensity values ​​of the standard Raman spectrum and the standard spectrum corresponding to the test sample are extracted to form two vectors, and their Pearson correlation coefficient r is calculated. The range of r is [-1, 1]. The higher the correlation, the better. Since the Raman spectrum intensity should be positively correlated, the Pearson correlation coefficient is mapped to the interval [0, 1], that is, the Pearson correlation coefficient score can be... That is, when r = 1 (perfectly positive correlation), the score is 1; when r = 0 (no correlation), the score is 0.5; and when r = -1 (perfectly negative correlation), the score is 0. The proportion of peaks in the standard Raman spectrum corresponding to the sample being tested that can be matched in the standard spectrum (position deviation less than a threshold, such as 2 cm⁻¹) is calculated. This proportion is within the interval [0, 1], and therefore can be directly used as the peak coverage score.

[0072] The final spectral feature matching degree is obtained by weighted fusion based on scores of average positional bias, Pearson correlation coefficient, and peak number coverage:

[0073]

[0074] in, For spectral feature matching degree; The score is the average positional deviation. The Pearson correlation coefficient score; The score is based on the peak coverage rate. The peak position weight is used because the peak position is the "fingerprint" of material identification and is the most critical indicator, usually having the highest importance, for example, 0.5. The strength correlation weight reflects the consistency of concentration or measurement conditions and is an important auxiliary indicator with a moderate importance, such as 0.3. Coverage is important, but if the sample contains impurity peaks or fluorescence background causing additional peaks, it shouldn't be overly penalized. As long as the main characteristic peaks match, the coverage score won't be too low, therefore its weight is low, for example, 0.2. .

[0075] For context suitability, the degree of fit between the applicable conditions defined by the QR Unit and the current analytical context is quantified. This is achieved by checking all constraints in the applicable conditions domain item by item. For example, it determines whether the currently input matrix "human serum" matches "serum" or "serum-like matrix" as defined in the QR Unit; it checks whether the measured pH value (e.g., 7.2) falls within the allowable range defined by the QR Unit (e.g., 6.8-7.5); and it compares the estimated concentration magnitude with the linear dynamic range of the QR Unit. Furthermore, it checks whether characteristic peaks of interfering substances listed in the interference factors subdomain of the QR Unit are present in the measured spectrum. Each dimension of the match is assigned a score between 0 and 1, and the final context suitability score is calculated by the harmonic mean of these scores. Using the harmonic mean ensures that any severely mismatched condition (score of 0 or close to 0) is heavily penalized, causing a sharp drop in the final score.

[0076] The knowledge quality score can be directly taken from the historical prediction accuracy recorded in the QR Unit reliability index field. In a preferred embodiment, the weighting coefficient can be set to =0.4, =0.5, =0.1, to highlight the importance of contextual fit. The candidate quantitative relation unit with the highest matching degree is determined as the target quantitative relation unit. Furthermore, if the QR Unit with the highest score has a contextual suitability score... If the value is below a preset threshold (e.g., 0.6), it will be determined that there is no knowledge in the knowledge base that highly matches the current analysis scenario. In this case, a warning will be issued to the user, indicating that the reliability of the current analysis results may be low, and suggesting that new calibration data be added to the scenario to establish a new QR Unit.

[0077] In this embodiment, the intelligent matching process based on the comprehensive matching score comprehensively evaluates three dimensions: spectral feature matching degree, contextual applicability, and knowledge quality. It can automatically select the quantitative relationship unit that best matches the current context of the sample to be tested, thus solving the problem that traditional knowledge bases cannot handle contextual dependence.

[0078] Optionally, in step S140, after successfully retrieving a highly matching QR Unit, contextual prompts are generated based on the QR Unit and the target quantitative relation unit using a preset prompt template. This includes: generating contextual prompts based on the structured feature text and the target quantitative relation unit using a preset prompt template embedded with a preset logical chain; wherein the preset logical chain strictly defines six steps for generating contextual prompts.

[0079] Specifically, after successfully retrieving a highly matching QR Unit, the structured feature text and all relevant information from the target quantitative relational unit can be integrated into a structured, strongly constrained prompt word to guide the large language model in subsequent reasoning. This preset prompt word template internally encapsulates the standard operating procedure (SOP) for Raman spectroscopy quantitative analysis. The preset prompt word template consists of four parts: The first part is [Spectral Feature Text to be Measured], which directly embeds the structured feature text. The second part is [Current Analysis Context Information], listing the contextual information of the sample to be measured. The third part is [Retrieved Knowledge Context], the main body of the prompt word, presenting key information from the highly matching QR Unit (e.g., substance identification conclusions, recommended characteristic peaks for quantification, specific quantitative functions and their parameters, complete descriptions of applicable conditions, and a list of potential interfering substances and precautions) to the model in a clear and readable text format. The fourth part is [Analysis Task Instructions], which is not an open-ended question but rather a series of precise, step-by-step instructions requiring the large language model to strictly follow the preset logical chain for thinking and output.

[0080] The logical chain is defined as follows: "Step 1: Compare the list of characteristic peaks of the spectrum to be measured with the standard characteristic peaks provided in the knowledge context (i.e., QRUnit) to confirm the substance's identity. Step 2: Accurately read the normalized intensity value from the numerical data of the spectrum to be measured according to the quantitative peak position specified in the knowledge context (i.e., QR Unit). Step 3: Check whether the current analysis context fully meets the applicable conditions declared in the knowledge context (i.e., QR Unit). Step 4: Use the quantitative function and parameters provided in the knowledge context (i.e., QR Unit), substitute the intensity value read in Step 2, and perform concentration calculation. Step 5: Based on the linear range and potential interfering information, perform cross-validation and uncertainty assessment on the calculation results. Step 6: Summarize and output the analysis process and final conclusions of all the above steps strictly according to the predefined JSON format." By setting highly restrictive instructions, the randomness of the large language model is suppressed to the greatest extent, ensuring the rigor and determinism of its reasoning process.

[0081] Furthermore, in the second step of the quantitative peak intensity reading, the primary quantitative peak specified by the QR Unit (usually the most intense and stable characteristic peak) is used first; the large language model is required to actively determine the state of the primary peak ("not obvious" or "interfered with"). When the primary peak is unreliable, the large language model must explain the reason and automatically switch to the auxiliary quantitative peak. This approach mimics the thought process of an expert seeking alternatives when encountering a problem, ensuring the robustness of the analysis. In the fourth step of concentration calculation, the concentration C is solved step by step using the quantitative function I = k*C + b, i.e., a purely deterministic mathematical formula is executed. ,in The intensity value is read in the second step, and the uncertainty is estimated based on the signal-to-noise ratio (SNR). SNR is a key indicator of measurement quality. A lower SNR means a lower intensity value. The greater the uncertainty, the greater the uncertainty of the final concentration result C. A confidence interval (e.g., 60.6 ± 2.1 μg / mL) is provided for the concentration result, rather than an absolutely accurate number. The output of step six above includes a complete result of substance identification, concentration result, calculation process, judgment criteria, and reliability assessment.

[0082] Optionally, the large language model is fine-tuned to enable it to perform quantitative Raman spectroscopy analysis using the contextual cue words. This includes fine-tuning the large language model using a hybrid loss function that incorporates domain knowledge. The hybrid loss function is composed of a weighted average of concentration prediction loss, characteristic peak intensity perception alignment loss, and logical consistency loss. The concentration prediction loss is used to calculate the relative error between the concentration value predicted by the large language model and the actual concentration value. The characteristic peak intensity perception alignment loss is used to calculate the relative error between the theoretical quantitative peak intensity calculated from the concentration predicted by the large language model and the peak intensity actually measured by the Raman spectroscopy. The logical consistency loss is used to penalize logical errors present in the output of the large language model. These logical errors include, at a minimum, undeclared predicted concentrations exceeding the linear range, failure to report the influence of known interfering substances, and claiming the results are reliable when the applicable conditions are not met.

[0083] Specifically, the goal of fine-tuning the large language model is to transform a general, powerful pre-trained large language model into a domain expert model proficient in quantitative Raman spectroscopy analysis through efficient and targeted training. An open-source large language model based on a Transformer decoder architecture can be selected as the base model, with its parameter size preferably between 7 billion and 13 billion, to achieve a balance between maintaining powerful inference capabilities and controlling deployment costs. The fine-tuning technique can employ Low-Rank Adaptation (LoRA). Specifically, a trainable low-rank matrix pair A and B can be connected in parallel next to each self-attention module and query, value, and other linear projection matrices in the feedforward network of the Transformer structure of the model. During fine-tuning, the main parameters (weights W) of the pre-trained model are completely frozen; only the parameters of the low-rank matrices A and B can be updated. During forward propagation, the input x undergoes a transformation of Wx + BAx. In one specific implementation, the low-rank dimension r is set to 8 or 16, while the scaling factor alpha is set to 16. The low-rank adaptive method requires training only a very small number of parameters, significantly reducing the need for training data and computational resources (e.g., GPU memory).

[0084] The training data required for fine-tuning can be efficiently generated using a "seed sample + physical data augmentation" strategy. For each substance covered in the knowledge base, 3 to 5 standard sample Raman spectra with known accurate concentrations covering low, medium, and high concentrations within its linear dynamic range are carefully selected from the corresponding experimental data as seed data. Subsequently, data augmentation can be performed based on the fundamental physical principle of Raman spectral signal superposition. For an ideal solution system following the Lambert-Beer law, two seed samples of the same substance and the same matrix at different concentrations can be linearly combined to generate a large number of synthetic spectra with precise concentration labels. For example, the spectrum S1 with concentration C1 and the spectrum S2 with concentration C2 can be linearly combined to generate a new spectrum Snew=aS1+(1-a)S2 with a corresponding concentration of aC1+(1-a)C2, where a is an arbitrary constant between 0 and 1.

[0085] Furthermore, for complex cases such as biological matrices where nonlinear effects may exist, empirical correction factors can be introduced. The correction coefficient can be determined by fitting a small number of real intermediate concentration samples. Specifically, complex biological matrices (nonlinear) can be understood as follows: in biological matrices such as serum and cell lysates, target molecules may interact with other components such as proteins, causing changes in their Raman scattering efficiency. Alternatively, the matrix itself may generate a fluorescence background, which nonlinearly annihilates the Raman signal. This manifests as the calibration curve (concentration-intensity relationship) no longer being a perfect straight line, but potentially curved. When initially predicting samples in biological matrices based on ideal solution data, a systematic and reproducible deviation is found between the predicted concentration and a few samples with known concentrations. This deviation pattern indicates the presence of nonlinear effects. For this specific biological matrix (e.g., "human serum"), researchers prepare a small number (3-5) of standard samples covering key concentration ranges (e.g., low, medium, high). These samples have known real concentrations. The actual spectral intensity of these real samples can be obtained using a Raman spectrometer. Meanwhile, based on the original linear function, the predicted intensity is calculated using the actual concentration. Fit a simple function to describe and The relationship between these factors is represented by the function called the "empirical correction factor". Linear correction: Where α and β are correction coefficients, which can be easily obtained from 3-5 samples through linear regression. The empirical correction factor ƒ is a linear function: ƒ(I) = α * I + β.

[0086] After determining the correction factor ƒ, for any unknown sample in this biological matrix, the original linear function can be used based on the measured intensity. Calculate an "uncorrected concentration". ;Will Substitute into the theoretical formula get The theoretical formula, based on the Lambert-Beer law and Raman scattering theory, states that under ideal conditions, the Raman spectrum peak intensity I is proportional to the sample concentration C. A correction factor is applied to calculate the corrected theoretical intensity. reuse Using the original linear function (I=k*C+b), the final correct concentration can be calculated. Finding the optimal balance between theoretical simplicity and practical complexity by introducing empirical correction factors is a key technology for achieving high-precision quantitative analysis.

[0087] Furthermore, to enhance the robustness of the large language model, data perturbations simulating real-world measurement noise can be applied to all raw and synthetic spectral data. This includes adding different levels of Gaussian white noise (e.g., signal-to-noise ratios from 100:1 to 10:1) to simulate detector random noise, and adding a slowly varying quadratic polynomial function to simulate baseline drift. Each final generated training sample contains three parts: a complete input prompt word constructed according to the aforementioned preset prompt word template; a standard answer output conforming to a predetermined JSON format, calculated from the actual concentration. This standard JSON answer includes fields such as substance identification, concentration calculation, judgment criteria, and reliability assessment; and auxiliary information metadata for calculating specific loss terms, which records the sample's actual quantitative peak intensity, main quantitative peak position, and quantitative function parameters.

[0088] The large language model is fine-tuned using a hybrid loss function that incorporates domain knowledge. This loss function... It consists of three weighted components: concentration prediction loss, characteristic peak intensity sensing alignment loss, and logical consistency loss.

[0089]

[0090] in, This refers to the concentration prediction loss at the macroscopic level. It can be determined by directly comparing the final predicted concentration values ​​given in the JSON output of a large language model. Compared with the true concentration value of the training samples The loss is calculated using the square of the relative error between the two, i.e. The concentration prediction loss ensures that the final numerical results output by the large language model are accurate overall.

[0091] Alignment loss is based on characteristic peak intensity. This can be determined based on the concentration predicted by the model. Using the quantitative function parameters (such as slope k and intercept b) obtainable from the knowledge context of its input, the theoretically corresponding quantitative peak intensity is calculated in reverse. From the auxiliary information metadata of the training sample, the actual intensity of the quantitative peak as measured on the original spectrum is read. The alignment loss is the square of the relative error between the two intensity values, i.e. This loss term establishes a physical constraint loop from the predicted concentration to the spectral characteristic intensity. And the weights of this loss term... It is not a fixed hyperparameter, but a context-matching score with the current training samples. Related dynamic functions, such as a sigmoid function That is, when the knowledge in the knowledge base highly matches the sample context ( When the alignment is close to 1, a strong alignment constraint will be imposed, forcing the model's predictions to be strictly consistent with the spectral features at the physical level; while when the context matching is low ( If the prior knowledge is lower, the constraint is correspondingly weakened, allowing the model greater flexibility when prior knowledge is not fully applicable and preventing inaccurate prior knowledge from misleading the model's learning process. By using feature peak intensity-aware alignment loss, the model is forced to "see" and "understand" the key physical features in the spectral data during inference, rather than guessing results through black-box statistical correlations. Furthermore, the weights of this loss can be dynamically adjusted according to the contextual matching degree of the knowledge, ensuring reliable learning and generalization under limited sample conditions.

[0092] To address logical consistency loss, a series of pre-defined rules penalize various logical errors in the model's output that violate physical laws or knowledge base constraints. These pre-defined rules are understood as translating expert experience and knowledge base constraints into a series of hard "if...then..." statements. Essentially, these rules act as a "logic policeman," checking the rationality of the large language model's output during training. Once a violation is detected, the behavior of the large language model is corrected by adding penalty terms. For example, if the large language model predicts a concentration... Exceeding the upper limit of the linear range defined in the QR Unit However, the generated JSON report does not mark "out of linear range" in the corresponding warning field, which will trigger a warning proportional to max(0, The penalty term is applied to the large language model. Similarly, if a large language model fails to declare a potential interference in its report when the interference is known to exist, or claims that the analysis results are highly reliable when the applicable conditions are clearly not met, logical inconsistencies will be penalized according to predefined rules. Furthermore, the training data is divided into training and validation sets in an appropriate ratio. During training, an early stopping strategy is used to monitor the total loss on the validation set. When the validation set loss no longer decreases for several consecutive rounds, the training is stopped early, and the optimal model is saved.

[0093] In this embodiment, through the multiple constraints of the hybrid loss function composed of concentration accuracy, physical feature alignment and logical consistency, and the control of the early stopping strategy, the large language model can efficiently learn a general, physically-compliant and logically rigorous spectral quantitative analysis capability on a very small number of seed samples, and can generalize well to new substances and new situations that have never been seen in training.

[0094] Optionally, in step S150, the contextual prompts are input into the fine-tuned large language model, and the analysis report of the sample to be tested is output through the fine-tuned large language model.

[0095] Specifically, the contextual cues of the sample to be tested are input into a finely tuned large language model for inference. During inference, a deterministic sampling strategy can be employed, for example, setting the temperature parameter to a very small value (e.g., 0.1) and disabling top-k or nullus sampling, to ensure that for identical inputs, the large language model always generates stable and consistent outputs. The raw output generated by the large language model is a text containing its complete analytical logic chain, appended with a JSON object strictly following a predefined format. A built-in parser precisely extracts this JSON object from the text and rigorously validates its internal field structure and data type to ensure it conforms to a predefined schema.

[0096] Due to the potential for "illusions" or minor errors in mathematical calculations by large language models, a crucial independent deterministic computation verification engine was introduced as a post-verification mechanism. This engine is a completely isolated, non-AI mathematical computation unit. Key parameters, including "the location of the characteristic peak used for quantitative analysis" and "the intensity value of the peak measured from the spectrum," can be extracted from the validated JSON object output by the large language model. "and quantitative function parameters adopted from the knowledge base, such as slope k and intercept b." Perform mathematical calculations independently. Concentration value The final concentration prediction value given directly in JSON by the large language model Perform a high-precision comparison. If the relative deviation between the two values ​​is less than a first preset threshold (e.g., 0.1%), the analysis is marked as "calculation verification passed". If the deviation is greater than or equal to the first preset threshold but less than a second preset threshold (e.g., 2%), the deviation is stated in the report and the verification value is used. As the final result, if the deviation is greater than or equal to the second preset threshold, it indicates a mathematical inconsistency between the reasoning process of the large language model and its final declared calculation result. In this case, a calculation anomaly alarm will be triggered immediately, the analysis result will be automatically marked as "awaiting manual review," and the final analysis report will be rejected. The calculation process of the verification engine is fully recorded in the report appendix to ensure the auditability of the entire analysis process.

[0097] Simultaneously, a range check is performed. If the concentration exceeds the union of the linear ranges of all QR Units in the knowledge base, a corresponding warning is issued. Specifically, each QR Unit's quantitative relationship has a valid concentration range, for example, 10-100 μg / mL. Outside this range, the linear relationship I=k*C+b may no longer hold, and the result is unreliable. The linear ranges of all relevant QR Units in the knowledge base are merged to form the broadest known concentration range. If the predicted concentration value is large... This exceeds the union range of 1-120 μg / mL, for example... =0.5μg / mL or If the concentration is 150 μg / mL, a warning will be displayed in the analysis report: "Warning: The predicted concentration (150 μg / mL) is outside the linear range (1-120 μg / mL) of all known calibration curves in the knowledge base. The reliability of this result may be extremely low. It is recommended to remeasure after dilution or concentration, or to use other methods for confirmation."

[0098] In this embodiment, the "model reasoning-independent verification" dual-path mechanism perfectly combines the powerful contextual understanding and logical reasoning capabilities of the large language model with the absolute accuracy of traditional calculation programs, ensuring the reliability of every value in the final report.

[0099] All validated analysis results will be rendered into a complete, hierarchical, and easy-to-read PDF or HTML analysis report using a report template engine, based on their structured JSON information. The report content may include: an execution summary on the first page summarizing key information such as substance name, final concentration result, confidence level, and concentration result level (e.g., high concentration, low concentration). The subsequent detailed quantitative results section may include: quantitative peak information, the quantitative function used, and detailed concentration calculation steps (…). The judgment criteria section uses graphics and text to show the feature comparison between the Raman spectrum of the sample under test and the standard Raman spectrum of the knowledge base, and fully presents the core content of the applied QR Unit and the details of its matching degree evaluation with the current sample context information.

[0100] The reliability assessment section analyzes the confidence level of the analysis results from multiple dimensions, specifically including substance identification confidence, context applicability confidence, quantitative calculation confidence, and data quality confidence. Substance identification confidence refers to the degree of matching between the measured spectrum and the standard spectrum in the QR Unit. This confidence level is assessed based on at least one of the following: high score for characteristic peak position deviation < 2 cm⁻¹, high score for characteristic peak coverage > 90%, and overall spectral similarity (e.g., correlation coefficient). For example, the substance identification confidence level can be 99%, based on all major characteristic peak position deviations < 1.5 cm⁻¹ and 100% coverage. Context applicability confidence refers to the degree of matching between the context information of the current sample and the "applicable conditions" defined in the QR Unit. This confidence level is assessed based on at least one of the following: matrix matching (complete match / partial match / no match), whether the pH and temperature are within allowable ranges, and whether characteristic peaks of known interfering substances are detected. For example, the confidence level for scenario applicability can be 100%, based on perfect matrix matching, pH 6.5 falling within the 5.0-7.0 range, and no detected known interfering substances. Quantitative calculation confidence can refer to the mathematical rigor and consistency of the concentration calculation process; this confidence assessment is based on at least one of the following: validation engine consistency, the relative deviation between the model's predicted value and the independent validation engine's calculated value (e.g., <0.1%); signal-to-noise ratio, the signal-to-noise ratio of the quantitative peak (e.g., >30:1 is excellent); linear range check, whether the predicted concentration is within the linear range defined by the QR Unit. For example, the confidence level for quantitative calculation can be 100%, based on a 0.05% deviation between the predicted and validated values, a signal-to-noise ratio of 35, and the concentration being within the linear range. Data quality confidence can refer to the quality of the unprocessed Raman spectral data of the test sample; this confidence assessment is based on at least one of the following: the overall spectrum's signal-to-noise ratio, baseline flatness, presence or absence of cosmic ray peaks, etc. For example, the data quality confidence can be 95%, based on an excellent overall signal-to-noise ratio and a corrected baseline.

[0101] Based on the "Interference Factors" subdomain of the matched QR Unit and the automated analysis of the Raman spectral morphology of the sample, all possible interfering substances are listed, and their potential impact is explained. For example, potential interfering factors include: high concentrations of sugars, which may cause a 5-10% reduction in the 1033 cm⁻¹ peak intensity. Coexisting substances may present unknown fluorescence background, which has been corrected for baseline. A final comprehensive rating is given based on all the above information. For example, if all dimensions have high confidence, no identified interfering factors, and good computational consistency, the comprehensive rating is high (multi-dimensional confidence > 90%). If most dimensions are good, but there are some minor issues, such as acceptable but not optimal context matching, moderate signal-to-noise ratio, or the possibility of slight interference, the comprehensive rating is medium (multi-dimensional confidence 70%-90%). If key dimensions have low confidence, such as low confidence in substance identification, severe context mismatch, computational inconsistency, or detection of strong interference, the comprehensive rating is low (multi-dimensional confidence < 70%). The computation records and comparison results of the independent deterministic computation verification engine will be attached as a technical appendix at the end of the report, ensuring end-to-end auditability and traceability of the entire analysis process.

[0102] Optionally, after the fine-tuned large language model outputs the analysis report of the sample to be tested, the system further includes: using an automated quality control mechanism to issue warnings for predictions with confidence levels below a set threshold, and providing handling suggestions for concentrations exceeding the linear range. Feedback and continuous optimization mechanisms support long-term performance improvement of the large language model. Operators can perform final confirmation or correction on each analysis report generated by the large language model. Analysis cases confirmed as correct will have their spectra, context, used knowledge, and final results automatically added to the knowledge base. Cases corrected by operators will trigger an error analysis process, generating an error work order and recording the error type for subsequent optimization of the large language model and knowledge base. Incremental fine-tuning is performed periodically using accumulated feedback data, and a mixed training strategy of new and old data is adopted to prevent catastrophic forgetting of the large language model. The knowledge base can also be dynamically updated and expanded based on new quantitative relationships, new substances, or new interfering factors discovered in practice. When a laboratory establishes quantitative relationships between new substances under specific conditions, technicians can add new QR Units through the management interface, vectorize and encode these new QR Units, and insert them into the vector database. This new knowledge becomes effective immediately without requiring any model retraining. Once the new knowledge is stored and vectorized, it can be immediately retrieved and used by subsequent analysis tasks. The entire process eliminates the need for model retraining, effectively reducing deployment time and maintenance costs, and fully demonstrating the system flexibility and scalability resulting from the decoupling of knowledge and models.

[0103] In one specific embodiment Figure 2This is a flowchart illustrating a quantitative Raman spectroscopy analysis method combining a large language model, as provided in Embodiment 2 of the present invention. Figure 2 As shown, the method includes five core stages: Stage 1: Data processing and feature extraction, which processes the raw Raman spectroscopy data into a standardized numerical format and extracts key features to convert them into text descriptions that can be understood by a large language model;

[0104] Phase Two: Construction and Management of a Context-Aware Knowledge Base. This phase involves building a Raman spectroscopy knowledge base centered on quantitative relationships and supporting context-aware retrieval, introducing quantitative relationship units. Phase Three: Knowledge Retrieval and Fusion. Based on the characteristics and context of the spectrum to be measured, the most relevant quantitative relationship units are retrieved from the knowledge base and integrated into the model input. Phase Four: Fine-tuning the Large Language Model using a hybrid loss function. Phase Five: The fine-tuned large language model provides interpretable prediction outputs, generating a transparent analysis report containing concentration values, the complete calculation process, judgment criteria, and reliability assessments. The large language model is continuously optimized based on the analysis report, and the context-aware knowledge base is updated.

[0105] Example 3:

[0106] Figure 3 This is a framework diagram of a Raman spectroscopy quantitative analysis system combining a large language model, provided in Embodiment 3 of the present invention. Figure 3 As shown, the system includes:

[0107] The preprocessing module 210 is used to acquire the Raman spectral data corresponding to the sample to be tested, and preprocess the Raman spectral data to obtain standard Raman spectral data; the feature extraction module 220 is used to extract features from the standard Raman spectral data to obtain structured feature text; the search module 230 is used to search for target quantitative relational units from a pre-built knowledge base based on the structured feature text and the contextual information of the sample to be tested; the generation module 240 is used to generate contextual prompts based on the structured feature text and the target quantitative relational units, using a preset prompt template; and the output module 250 is used to input the contextual prompts into a fine-tuned large language model, and output the analysis report of the sample to be tested through the fine-tuned large language model.

[0108] Optionally, the system also includes: a building module for:

[0109] Quantitative relationships of different substances under different contexts are extracted from information from multidimensional data sources; the quantitative relationships of different substances under different contexts are formatted and filled into the data structure of the quantitative relationship unit; wherein, the data structure of the quantitative relationship unit is a data structure containing five core domains, namely, the substance information domain, the spectral feature domain, the quantitative relationship domain, the applicable condition domain, and the reliability index domain; a knowledge base is constructed based on each of the quantitative relationship units.

[0110] Optionally, building modules are also used for:

[0111] Each quantitative relation unit in the knowledge base is encoded using hybrid vectorization to generate a hybrid vector corresponding to each quantitative relation unit; each hybrid vector is stored in a vector database, and an approximate nearest neighbor search index is established.

[0112] Optionally, the lookup module 230 is specifically used for:

[0113] The structured feature text is encoded into a query vector, and an approximate nearest neighbor search is performed in the vector database to determine a preset number of mixed vectors with the highest similarity. Based on the vector IDs corresponding to each mixed vector, the corresponding candidate quantitative relation units are searched from the pre-built knowledge base. Based on the contextual information of the sample to be tested and the structured feature text, the matching degree is calculated with each candidate quantitative relation unit, and the candidate quantitative relation unit with the highest matching degree is determined as the target quantitative relation unit.

[0114] Optionally, the lookup module 230 is also used for:

[0115] Based on the contextual information of the sample to be tested and the structured feature text, the spectral feature matching degree, contextual applicability, and knowledge quality are calculated for each of the candidate quantitative relationship units. Based on the spectral feature matching degree, contextual applicability, and knowledge quality corresponding to each candidate quantitative relationship unit, the matching degree between the sample to be tested and each candidate quantitative relationship unit is determined. The candidate quantitative relationship unit with the highest matching degree is determined as the target quantitative relationship unit.

[0116] Optionally, module 240 is generated, specifically for:

[0117] Based on the structured feature text and the target quantitative relation unit, contextual prompts are generated by embedding a preset prompt template with a preset logical chain; wherein, the preset logical chain strictly defines six steps for generating contextual prompts.

[0118] Optionally, the system also includes: a fine-tuning module for:

[0119] The large language model is fine-tuned using a hybrid loss function that incorporates domain knowledge. This hybrid loss function is composed of a weighted average of concentration prediction loss, characteristic peak intensity-aware alignment loss, and logical consistency loss. The concentration prediction loss is used to calculate the relative error between the concentration value predicted by the large language model and the actual concentration value. The characteristic peak intensity-aware alignment loss is used to calculate the relative error between the theoretical quantitative peak intensity calculated from the concentration predicted by the large language model and the peak intensity actually measured by the Raman spectrum. The logical consistency loss is used to penalize logical errors present in the output of the large language model, where logical errors include at least: predicting concentrations outside the linear range without declaration, failing to report the influence of known interfering substances, and claiming the result is reliable when the applicable conditions are not met.

[0120] The Raman spectroscopy quantitative analysis system combining a large language model provided in the embodiments of the present invention can execute the Raman spectroscopy quantitative analysis method combining a large language model provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the method execution.

[0121] Example 4:

[0122] This invention provides an electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the Raman spectroscopy quantitative analysis method combining a large language model as described in any embodiment of this invention.

[0123] In some embodiments, a Raman spectroscopy quantitative analysis method incorporating a large language model can be implemented as a computer program. The computer program for implementing the method of the present invention can be written using any combination of one or more programming languages. In the context of the present invention, a computer-readable storage medium stores computer instructions for causing a processor to execute and implement the Raman spectroscopy quantitative analysis method incorporating a large language model provided by the present invention.

[0124] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0125] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A quantitative Raman spectroscopy method combining a large language model, characterized in that, include: Acquire the Raman spectral data corresponding to the sample to be tested, and preprocess the Raman spectral data to obtain standard Raman spectral data; Feature extraction is performed on the standard Raman spectral data to obtain structured feature text; Based on the structured feature text and the contextual information of the sample to be tested, the target quantitative relationship unit is searched from the pre-built knowledge base; Based on the structured feature text and the target quantitative relation unit, contextual prompts are generated using a preset prompt template. The contextual prompts are input into the fine-tuned large language model, and the fine-tuned large language model outputs the analysis report of the sample to be tested.

2. The method according to claim 1, characterized in that, The construction of the knowledge base includes: Extracting quantitative relationships between different substances in different contexts from information from multidimensional data sources; The quantitative relationships of the different substances under different situations are formatted and filled into the data structure of the quantitative relationship unit; wherein, the data structure of the quantitative relationship unit is a data structure containing five core domains, namely, the substance information domain, the spectral feature domain, the quantitative relationship domain, the applicable conditions domain, and the reliability index domain; A knowledge base is constructed based on each of the aforementioned quantitative relational units.

3. The method according to claim 2, characterized in that, After the knowledge base is built, it also includes: Each quantitative relation unit in the knowledge base is subjected to hybrid vectorization encoding to generate a hybrid vector corresponding to each quantitative relation unit; Each of the hybrid vectors is stored in a vector database, and an approximate nearest neighbor search index is established.

4. The method according to claim 1, characterized in that, Based on the structured feature text and the contextual information of the sample to be tested, quantitative relational units corresponding to the structured feature text are searched from a pre-built knowledge base, including: The structured feature text is encoded into a query vector, and an approximate nearest neighbor search is performed in the vector database to determine a preset number of mixed vectors with the highest similarity. Based on the vector ID corresponding to each of the hybrid vectors, the corresponding candidate quantitative relation units are searched from the pre-constructed knowledge base; Based on the contextual information of the sample to be tested and the structured feature text, the matching degree is calculated with each of the candidate quantitative relationship units, and the candidate quantitative relationship unit with the highest matching degree is determined as the target quantitative relationship unit.

5. The method according to claim 4, characterized in that, The step of calculating the matching degree between the contextual information of the sample to be tested and the structured feature text and each of the candidate quantitative relation units, and determining the candidate quantitative relation unit with the highest matching degree as the target quantitative relation unit, includes: Based on the contextual information of the sample to be tested and the structured feature text, the spectral feature matching degree, contextual applicability and knowledge quality are calculated for each of the candidate quantitative relationship units. Based on the spectral feature matching degree, contextual applicability, and knowledge quality corresponding to each of the candidate quantitative relationship units, the matching degree between the sample to be tested and each of the candidate quantitative relationship units is determined. The candidate quantitative relation unit with the highest matching degree is determined as the target quantitative relation unit.

6. The method according to claim 1, characterized in that, Based on the structured feature text and the target quantitative relation unit, contextual prompts are generated using a preset prompt template, including: Based on the structured feature text and the target quantitative relation unit, contextual prompts are generated by embedding a preset prompt template with a preset logical chain; wherein, the preset logical chain strictly defines six steps for generating contextual prompts.

7. The method according to claim 1, characterized in that, Fine-tuning the large language model includes: The large language model is fine-tuned using a hybrid loss function that incorporates domain knowledge. The hybrid loss function is composed of a weighted sum of concentration prediction loss, feature peak intensity-aware alignment loss, and logical consistency loss. The concentration prediction loss is used to calculate the relative error between the concentration value predicted by the large language model and the actual concentration value. The characteristic peak intensity sensing alignment loss is used to calculate the relative error between the theoretical quantitative peak intensity calculated from the concentration predicted by the large language model and the peak intensity actually measured by the Raman spectrum. The logical consistency loss is used to penalize logical errors present in the output of the large language model, wherein the logical errors include at least: predicting concentrations that exceed the linear range without declaring them, failing to report the effects of known interfering substances, and claiming the results are reliable when the applicable conditions are not met.

8. A Raman spectroscopy quantitative analysis system combining a large language model, characterized in that, The system is used to perform the Raman spectroscopy quantitative analysis method combining a large language model as described in any one of claims 1-7, comprising: The preprocessing module is used to acquire the Raman spectral data corresponding to the sample to be tested, and to preprocess the Raman spectral data to obtain standard Raman spectral data. The feature extraction module is used to extract features from the standard Raman spectral data to obtain structured feature text; The search module is used to search for target quantitative relation units from a pre-built knowledge base based on structured feature text and contextual information of the sample to be tested. The generation module is used to generate contextual prompts based on the structured feature text and the target quantitative relation unit, using a preset prompt template. The output module is used to input the contextual prompts into the fine-tuned large language model and output the analysis report of the sample to be tested through the fine-tuned large language model.

9. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, which enables the at least one processor to perform the Raman spectroscopy quantitative analysis method combining a large language model as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the Raman spectroscopy quantitative analysis method combining a large language model as described in any one of claims 1-7.