Chemical enterprise knowledge base construction method and device, electronic equipment and storage medium

By constructing a knowledge base for chemical enterprises using a large language model and a RAG generation model, the problems of low retrieval efficiency and difficulty in dynamic updating of knowledge bases for chemical enterprises are solved. This enables efficient and accurate knowledge management and emergency response suggestions, thereby improving the intelligence and digitalization level of enterprises.

CN120822595AInactive Publication Date: 2025-10-21CHENGDU GREATECH ELECTRONIC TECHNOLOGY CO LTD

Patent Information

Application Number
CN202511316668.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-16
Publication Date
2025-10-21
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The chemical enterprise knowledge base suffers from low retrieval efficiency, difficulty in dynamic updates, and struggles to adapt to regulatory updates and technological developments. Furthermore, the existing system lacks intelligent processing capabilities, making it difficult to generate accurate answers.

Method used

By using a large language model embedding mechanism to map document data to a high-dimensional vector space, and combining it with a RAG generative model for semantic retrieval and answer generation, a knowledge base for chemical enterprises is constructed, enabling dynamic updates and multi-round interactions.

Benefits of technology

It improved the retrieval efficiency and accuracy of answers in the knowledge base, enhanced the knowledge utilization efficiency and safety management level of chemical enterprises, reduced knowledge management costs, and improved emergency response capabilities and production safety.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120822595A_ABST
    Figure CN120822595A_ABST
Patent Text Reader

Abstract

The invention relates to a chemical enterprise knowledge base construction method and device, electronic equipment and a storage medium, and the method comprises the steps: obtaining a document data set of a chemical enterprise, and sorting the document data set into independent knowledge units; and mapping each piece of document data to a high-dimensional vector space through an embedding mechanism of a large language model to generate an embedded vector, and storing the embedded vector and the corresponding document identifier into a vector database. Calling an embedded function to convert a natural language query text input by a user into a high-dimensional query vector, and calculating a similarity score between the high-dimensional query vector and each embedded vector in the vector database through vector similarity measurement so as to select associated document data with the similarity score exceeding a first threshold value. And splicing the natural language query text and the context of the associated document data into the input of an RAG generation model, generating an answer through a large language model, and constructing a knowledge base based on the generated answer in combination with the associated document data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of chemical industry and data management technology, and in particular to a method, device, electronic equipment and storage medium for constructing a chemical enterprise knowledge base. Background Art

[0002] With the rapid development of the chemical industry, production processes are becoming increasingly complex, and equipment operation requirements are becoming increasingly stringent. Chemical companies are also facing increasing demands for safety and knowledge management. In chemical production, various standard operating manuals, safety data (such as chemical MSDS), equipment maintenance instructions, and emergency response plans play a vital role. However, this knowledge is often scattered across various documents and systems, making it difficult to quickly retrieve and effectively apply. At the same time, chemical companies need to dynamically update and efficiently manage massive amounts of data in their daily operations to respond to new regulations, new processes, and unexpected incidents.

[0003] Existing knowledge bases for chemical companies primarily rely on traditional information retrieval and knowledge management methods, including keyword search, rule matching, and manual knowledge base updates. These methods typically focus on static knowledge storage, with knowledge base content typically consisting of fixed documents (such as PDF files and manuals), making it difficult to support dynamic updates or intelligent processing. Distributed knowledge data is distributed across various storage systems, lacking unified integration and resulting in low retrieval efficiency.

[0004] Traditional knowledge base construction involves searching traditional databases and using full-text search methods, which are difficult to effectively handle large-scale knowledge bases. This is especially true when data volumes grow rapidly, as retrieval speed and accuracy decline. Furthermore, existing knowledge bases often rely on manual maintenance, resulting in lagging knowledge updates and inability to adapt to regulatory updates or technological developments within chemical companies. Furthermore, traditional search and question-answering systems can only match explicit information from user queries, making it difficult to understand deeper semantics within the context. They also lack the ability to generate accurate answers based on the integration of multiple knowledge points and struggle to dynamically generate knowledge content based on user queries, such as emergency response plans or process optimization recommendations. Summary of the Invention

[0005] Based on this, it is necessary to provide a chemical enterprise knowledge base construction method, device, electronic equipment and storage medium that can effectively overcome the shortcomings of existing technical solutions in retrieval efficiency, dynamic update, intelligent generation capabilities, etc., and provide a new solution for the intelligent knowledge management of chemical enterprises.

[0006] The present invention provides a method for constructing a chemical enterprise knowledge base, the method comprising:

[0007] Acquire a document data set of a chemical enterprise, and organize the document data set into independent knowledge units;

[0008] Mapping each document data to a high-dimensional vector space through the embedding mechanism of the large language model to generate an embedding vector, and storing the embedding vector and its corresponding document identifier in a vector database;

[0009] Calling an embedding function to convert a natural language query text input by a user into a high-dimensional query vector, and calculating a similarity score between the high-dimensional query vector and each embedding vector in the vector database using a vector similarity metric, so as to select associated document data whose similarity score exceeds a first threshold;

[0010] The natural language query text and the context of the associated document data are spliced ​​as input to the RAG generation model, an answer is generated through the large language model, and a knowledge base is constructed based on the generated answer and the associated document data;

[0011] Among them, each document data contains chemical safety information, operating specification information and accident case information. The knowledge unit includes multiple attributes, namely text content, metadata and category; the RAG generation model is constructed based on the Transformer architecture.

[0012] In one embodiment, mapping each document data into a high-dimensional vector space through an embedding mechanism of a large language model to generate an embedding vector, and storing the embedding vector and its corresponding document identifier in a vector database includes:

[0013] The knowledge unit corresponding to each document data is mapped to a high-dimensional vector space through the embedding mechanism of the large language model to generate an embedding vector. The embedding formula is:

[0014]

[0015] Where, , is the embedding vector, dimension is d, represents a real vector space of d;

[0016] Storing the generated embedding vector and the corresponding document identifier in a vector database, and constructing an index in the vector database;

[0017] The generated embedding vector and the corresponding document identifier are stored in the vector database in the following storage structure:

[0018]

[0019] Where, is a vector database, For associated documents Its vector representation .

[0020] In one embodiment, calling the embedding function to convert the natural language query text input by the user into a high-dimensional query vector, and calculating the similarity score between the high-dimensional query vector and each embedding vector in the vector database using a vector similarity measure to select associated document data having a similarity score exceeding a first threshold, includes:

[0021] The natural language query text is converted into the high-dimensional query vector through an embedding function, and the embedding function expression is:

[0022]

[0023] Where, is a high-dimensional query vector, and , represents a d-dimensional real vector space, is the embedding function, query text for natural language;

[0024] The similarity score between the high-dimensional query vector and all embedded vectors in the vector database is calculated by using the cosine similarity metric, where the expression of the cosine similarity metric is:

[0025]

[0026] Where, is the similarity score, is the dot product, which is used to measure the directional similarity of two vectors. is the vector norm, used for normalization.

[0027] In one embodiment, the calling of the embedding function converts the natural language query text input by the user into a high-dimensional query vector, and calculates a similarity score between the high-dimensional query vector and each embedding vector in the vector database using a vector similarity metric to select associated document data having a similarity score exceeding a first threshold, further comprising:

[0028] The document data is sorted according to the similarity score to obtain a sorting result from large to small similarity scores, and the top k related document data are selected from the sorting. The sorting formula is:

[0029]

[0030] Where, is the first k associated document data selected, is a high-dimensional query vector, is the vector representation of the document.

[0031] In one embodiment, the process of splicing the context of the natural language query text and the associated document data as input to a RAG generation model, generating answers using a large language model, and building a knowledge base based on the generated answers in combination with the associated document data, includes:

[0032] Input the context of the natural language query text and associated document data into the Transformer model for tokenization to convert the context of the natural language query text and associated document data into multiple discrete tokens, and convert each token into a corresponding vector representation through an embedding layer;

[0033] The self-attention mechanism is called to process the vector representation of each tag through linear transformation to obtain the query vector, key vector and value vector, and the similarity between the query vector and the key vector is calculated to obtain the attention score.

[0034] In one embodiment, the Transformer model further includes a feedforward neural network layer, which includes two linear layers and an activation function. The expression of the feedforward neural network layer is:

[0035]

[0036] Where, is the output of the feedforward neural network layer, is the activation function, is the weight matrix of the linear transformation, is the bias term, Embedding vector for the input Token;

[0037] The process of splicing the context of the natural language query text and the associated document data as input to the RAG generation model, generating answers through a large language model, and building a knowledge base based on the generated answers and the associated document data may also include:

[0038] The vector representation of each token is processed through multiple layers of attention and feedforward neural network layers to obtain a contextual representation of each token, and the contextual representation is mapped to the dimensions of the vocabulary through a linear transformation to form a probability distribution for generating new words.

[0039] In one embodiment, the method further comprises:

[0040] Acquire new document data, and convert the new document data into new embedding vectors, so as to add the new embedding vectors to the vector database;

[0041] A document identifier of expired document data is obtained, and the expired document data is removed from the vector database according to the document identifier.

[0042] The present invention also provides a device for constructing a chemical enterprise knowledge base, the device comprising:

[0043] A document integration module is used to obtain a document data set of a chemical enterprise and organize the document data set into independent knowledge units;

[0044] A data storage module is used to map each document data into a high-dimensional vector space through the embedding mechanism of the large language model to generate an embedding vector, and store the embedding vector and its corresponding document identifier in a vector database;

[0045] a document retrieval module, configured to call an embedding function to convert a natural language query text input by a user into a high-dimensional query vector, and calculate a similarity score between the high-dimensional query vector and each embedding vector in the vector database using a vector similarity metric, so as to select associated document data whose similarity score exceeds a first threshold;

[0046] An answer generation module, configured to combine the context of the natural language query text and the associated document data as input to the RAG generation model, generate answers using a large language model, and construct a knowledge base based on the generated answers and the associated document data;

[0047] Among them, each document data contains chemical safety information, operating specification information and accident case information. The knowledge unit includes multiple attributes, namely text content, metadata and category; the RAG generation model is constructed based on the Transformer architecture.

[0048] The present invention also provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, it implements any of the above-described methods for constructing a chemical enterprise knowledge base.

[0049] The present invention also provides a computer storage medium storing a computer program, wherein when the computer program is executed by a processor, the method for constructing a chemical enterprise knowledge base as described above is implemented.

[0050] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method for constructing a chemical enterprise knowledge base as described above is implemented.

[0051] The above-mentioned chemical enterprise knowledge base construction method, device, electronic device and storage medium, through vector database technology, realizes efficient semantic retrieval of large-scale knowledge bases, which can support the rapid discovery of relevant content. Combined with retrieval enhancement generation (RAG) technology, multiple knowledge points are integrated according to user queries to generate more accurate answers, which can be applied to complex problems and emergency response suggestions. Multi-round interaction and intelligent support can support multiple rounds of interaction between users and knowledge bases, improving the efficiency and intelligence level of knowledge application. In addition, this method constructs a chemical enterprise knowledge base by constructing RAG and a large language model, which can more accurately generate professional knowledge and emergency response suggestions related to chemical production and safety management, improve the knowledge utilization efficiency and safety management level of chemical enterprises, significantly reduce the knowledge management costs in enterprise operations, enhance the emergency response capabilities and production safety of chemical enterprises, promote the intelligent and digital transformation of enterprises, and at the same time bring relatively significant economic and social benefits. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction is given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0053] Figure 1 A schematic diagram of the process of constructing a chemical enterprise knowledge base provided by the present invention;

[0054] Figure 2 This is a schematic diagram of the overall process of the method for constructing a chemical enterprise knowledge base in a specific embodiment provided by the present invention;

[0055] Figure 3 A schematic diagram of the data preparation and document vectorization process of the method for building a chemical enterprise knowledge base in a specific embodiment of the present invention;

[0056] Figure 4 A schematic diagram of the query and document retrieval process of the method for constructing a chemical enterprise knowledge base in a specific embodiment of the present invention;

[0057] Figure 5 A schematic diagram of a dynamic knowledge update process of a method for constructing a chemical enterprise knowledge base in a specific embodiment of the present invention;

[0058] Figure 6 This is a schematic diagram of the structure of the chemical enterprise knowledge base construction device provided by the present invention;

[0059] Figure 7 This is a diagram of the internal structure of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0060] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.

[0061] The following combination Figures 1 to 7 The present invention describes the chemical enterprise knowledge base construction method, device, electronic equipment and storage medium.

[0062] like Figure 1 As shown, in one embodiment, a method for constructing a chemical enterprise knowledge base includes the following steps:

[0063] Step S110 : obtaining a document data set of a chemical enterprise, and organizing the document data set into independent knowledge units.

[0064] Among them, each document data contains chemical safety information, operating specification information and accident case information, and the knowledge unit includes multiple attributes, namely text content, metadata and category.

[0065] In step S120 , each document data is mapped to a high-dimensional vector space through the embedding mechanism of the large language model to generate an embedding vector, and the embedding vector and its corresponding document identifier are stored in a vector database.

[0066] In some embodiments, the method for constructing a chemical enterprise knowledge base provided by the present invention maps each document data to a high-dimensional vector space through the embedding mechanism of a large language model to generate an embedding vector, and stores the embedding vector and its corresponding document identifier in a vector database, specifically comprising the following steps:

[0067] Step S121: Map the knowledge unit corresponding to each document data to a high-dimensional vector space through the embedding mechanism of the large language model to generate an embedding vector. The embedding formula is:

[0068]

[0069] Where, , is the embedding vector, dimension is d, represents a real vector space of d;

[0070] Step S122: Store the generated embedding vector and the corresponding document identifier in a vector database, and construct an index in the vector database.

[0071] The generated embedding vector and the corresponding document identifier are stored in the vector database in the following storage structure:

[0072]

[0073] Where, is a vector database, For associated documents Its vector representation .

[0074] In step S130, an embedding function is called to convert the natural language query text input by the user into a high-dimensional query vector, and a similarity score between the high-dimensional query vector and each embedding vector in the vector database is calculated using a vector similarity metric to select associated document data whose similarity score exceeds a first threshold.

[0075] In some embodiments, the chemical enterprise knowledge base construction method provided by the present invention calls an embedding function to convert a natural language query text input by a user into a high-dimensional query vector, and calculates a similarity score between the high-dimensional query vector and each embedded vector in the vector database using a vector similarity metric to select associated document data whose similarity score exceeds a first threshold. The method specifically includes the following steps:

[0076] Step S131: convert the natural language query text into a high-dimensional query vector through an embedding function. The embedding function expression is:

[0077]

[0078] Where, is a high-dimensional query vector, and , represents a d-dimensional real vector space, is the embedding function, Query text for natural language.

[0079] Step S132: Calculate the similarity scores between the high-dimensional query vector and all embedded vectors in the vector database using the cosine similarity metric. The expression of the cosine similarity metric is:

[0080]

[0081] Where, is the similarity score, is the dot product, which is used to measure the directional similarity of two vectors. is the vector norm, used for normalization.

[0082] In some embodiments, the chemical enterprise knowledge base construction method provided by the present invention calls an embedding function to convert a natural language query text input by a user into a high-dimensional query vector, and calculates a similarity score between the high-dimensional query vector and each embedded vector in the vector database through a vector similarity metric to select associated document data whose similarity score exceeds a first threshold, and specifically further includes the following steps:

[0083] Step S133: sort the document data according to the similarity score to obtain a sorting result from the largest to the smallest similarity score, and select the top k related document data from the sorting. The sorting formula is:

[0084]

[0085] Where, is the first k associated document data selected, is a high-dimensional query vector, is the vector representation of the document.

[0086] In step S140 , the context of the natural language query text and the associated document data is spliced ​​as the input of the RAG generation model, an answer is generated through the large language model, and a knowledge base is constructed based on the generated answer and the associated document data.

[0087] Among them, the RAG generation model is built based on the Transformer architecture.

[0088] In some embodiments, the method for constructing a chemical enterprise knowledge base provided by the present invention combines the context of natural language query text and associated document data as input to a RAG generation model, generates answers through a large language model, and constructs a knowledge base based on the generated answers and associated document data, which includes the following steps:

[0089] In step S210, the context of the natural language query text and the associated document data is input into the Transformer model for tokenization processing to convert the context of the natural language query text and the associated document data into multiple discrete tokens, and each token is converted into a corresponding vector representation through the embedding layer.

[0090] In step S220, the self-attention mechanism is called to process the vector representation of each tag through linear transformation to obtain the query vector, key vector and value vector, and the similarity between the query vector and the key vector is calculated to obtain the attention score.

[0091] The Transformer model also includes a feedforward neural network layer, which contains two linear layers and an activation function. The expression of the feedforward neural network layer is:

[0092]

[0093] Where, is the output of the feedforward neural network layer, is the activation function, is the weight matrix of the linear transformation, is the bias term, It is the input Token embedding vector.

[0094] In step S230 , the vector representation of each token is processed through multiple layers of attention and feedforward neural network layers to obtain a contextual representation of each token, and the contextual representation is mapped to the dimension of the vocabulary through a linear transformation to form a probability distribution for generating new words.

[0095] In some embodiments, the method for constructing a chemical enterprise knowledge base provided by the present invention further includes the following steps:

[0096] Step S310 : acquiring newly added document data and converting the newly added document data into newly added embedding vectors, so as to add the newly added embedding vectors into the vector database.

[0097] Step S320: Obtain document identifiers of expired document data, and remove the expired document data from the vector database according to the document identifiers.

[0098] The above-mentioned method for constructing a knowledge base for chemical enterprises uses vector database technology to achieve efficient semantic retrieval of large-scale knowledge bases, which can support the rapid discovery of relevant content. Combined with retrieval-augmented generation (RAG) technology, it integrates multiple knowledge points based on user queries to generate more accurate answers, which can be applied to complex problems and emergency response suggestions. Multi-round interaction and intelligent support can support multiple rounds of interaction between users and the knowledge base, improving the efficiency and intelligence level of knowledge application. In addition, this method constructs a knowledge base for chemical enterprises by constructing RAG and a large language model, which can more accurately generate professional knowledge and emergency response suggestions related to chemical production and safety management, improve the knowledge utilization efficiency and safety management level of chemical enterprises, significantly reduce the knowledge management costs in enterprise operations, enhance the emergency response capabilities and production safety of chemical enterprises, promote the intelligent and digital transformation of enterprises, and at the same time bring relatively significant economic and social benefits.

[0099] Combine Figures 2 to 5 As shown, in a specific embodiment, the method for constructing a chemical enterprise knowledge base provided by the present invention includes steps 1 to 5:

[0100] Step 1: Data preparation and preprocessing.

[0101] Data preparation: Collect document data of chemical companies Organized into independent knowledge units, each document Contains content related to chemical safety, operating specifications, accident cases, etc.

[0102] Data characteristics: For text content, such as a paragraph or sentence.

[0103] Knowledge Unit It can be represented by multiple attributes, namely ,in, For text content, for metadata (source, time, etc.), The category (chemical, equipment operation, etc.).

[0104] Document vectorization: Each document is vectorized by embedding the large language model. Mapping to a high-dimensional vector space to generate an embedding vector , embedded formula:

[0105]

[0106] Where, is the embedding vector with dimension d, Represents a d-dimensional real vector space. Embedding function Usually based on deep learning training models, high-dimensional semantic vectors are generated using text features. The embedding vector retains the document The semantic information of the document is used to make the vectors of similar documents have a smaller distance in the vector space.

[0107] Build vector database: generate embedding vectors and the corresponding document identifier Stored in the vector database, the storage structure is as follows:

[0108]

[0109] Where, is a vector database, For associated documents Its vector representation .

[0110] Index building: To speed up vector retrieval, build an index in the vector database .

[0111] In this embodiment, document data is converted into a high-dimensional vector representation using the embedding mechanism of a large language model. The user's query is then converted into a query vector using the same embedding mechanism. Cosine similarity is typically used to measure similarity with vectors in the database. After calculating the similarity, the system ranks the documents based on the scores and selects the most relevant documents as search results. This approach allows for the rapid and efficient retrieval of the most relevant documents within a vast knowledge base.

[0112] Step 2: User query input and vectorization.

[0113] User query vectorization: users enter natural language queries , such as "How to deal with hydrogen sulfide leakage?". By embedding the function , query Convert to high-dimensional vector :

[0114]

[0115] Where, is a high-dimensional query vector, and , represents a d-dimensional real vector space, is the embedding function, Query text for natural language.

[0116] Vector similarity measurement: Calculate the query vector through vector similarity measurement With all vectors in the database Similarity score , and its similarity measurement formula is cosine similarity:

[0117]

[0118] Where, is the similarity score, is the dot product, which is used to measure the directional similarity of two vectors. is the vector norm, used for normalization.

[0119] Step 3: Document retrieval and semantic matching.

[0120] Document sorting and selection: Sort documents based on similarity scores and select the top k most relevant documents , and its sorting formula is:

[0121]

[0122] Where, is the first k associated document data selected, is a high-dimensional query vector, is the vector representation of the document.

[0123] Step 4: Generate answers and context.

[0124] RAG retrieves the context As conditional input, it provides contextual information to the generative model, thereby generating more accurate answers.

[0125] Construct the generated input: transform the user query and the retrieved context Concatenate as input to the generative model: , Represents a splicing operation.

[0126] Generate the answer using a large language model: Generate the answer A using a large language model: ,in, It is a generative model based on the Transformer architecture.

[0127] Tokenization and Embedding Representation: In the Transformer model, the input text is tokenized. After tokenization, the text is converted into discrete tokens. Each token is converted into a vector representation through the embedding layer. . Let the Token sequence be, and its corresponding embedding vector is , where the embedding vector is composed of the pre-trained embedding matrix Get: , these embedding vectors will serve as input to the Transformer model.

[0128] Self-Attention: The core computation in the Transformer model is the self-attention mechanism. Through this mechanism, the model can calculate the relationship between each position in the input sequence. Each token's input vector undergoes a linear transformation to obtain the query, key, and value vectors. The calculation formula is: ,in, is the weight matrix, and X is the input Token embedding vector.

[0129] After that, the similarity between the query and the key is calculated to get the attention score. The commonly used similarity metric is the dot product, which is calculated as:

[0130]

[0131] Where, is the attention score, is the dimension of the key vector, Represents the dot product of the query and the key.

[0132] Next, the attention weight is obtained through the softmax function:

[0133]

[0134] Then, the sum value vector is weighted using the attention weights :

[0135]

[0136] The output Will be used as the context representation of the current Token.

[0137] Multi-head self-attention: To enhance the expressiveness of the model, Transformer usually uses a multi-head self-attention mechanism. Multi-head attention divides the input query, key, and value into multiple "heads" for parallel calculation, and finally merges the outputs of multiple heads. Assume there are h heads, and the output of each head is , then the final multi-head attention output is: ,in is the output weight matrix.

[0138] Feedforward Neural Network: In each layer of Transformer, in addition to the self-attention layer, there is also a feedforward neural network (FFN) layer. FFN usually consists of two linear layers and an activation function. The specific calculation formula is:

[0139]

[0140] Where, is the output of the feedforward neural network layer, is the activation function, is the weight matrix of the linear transformation, is the bias term, It is the input Token embedding vector.

[0141] Decoding and Generation: After the output of the Transformer is processed by multiple layers of self-attention and feedforward neural networks, the resulting contextual representation of each token is obtained. These contextual representations are mapped to the dimensions of the vocabulary through linear transformation to form a probability distribution. , used to generate the next word:

[0142]

[0143] Where, It is the context representation of the current Token. is the weight matrix mapped to the vocabulary, is the bias term.

[0144] In this way, the generative model can predict the next token based on the generated partial sequence until a complete answer is generated.

[0145] Temperature sampling and randomness generation:

[0146] During the generation process, in order to control the randomness of the generated text, the temperature parameter is usually used. The temperature parameter T controls the smoothness of the generated probability distribution:

[0147]

[0148] in, is the temperature parameter. When it is low, the model is more inclined to generate words with high probability (the generation result is more certain); when When higher, the generated results are more random, containing more variation and diversity.

[0149] Step 5: Dynamic update and maintenance of the knowledge base.

[0150] Incremental update: for newly added documents , generate embedding vector And add to the database:

[0151]

[0152] Delete expired documents: Based on document identifier Remove expired documents:

[0153]

[0154] In this embodiment, a large language model is combined with retrieval enhancement generation technology. By combining the large language model with the retrieval function of the vector database, the deficiencies of the traditional chemical enterprise knowledge base in retrieval, generation and updating are solved. Specifically, the query is first vectorized through the large language model, and then the RAG technology is used to retrieve relevant documents from the vector database, and accurate answers are generated based on the retrieved context. Dynamic knowledge update mechanism combining vector database with large language model. By combining the large language model and RAG technology, this method not only achieves efficient knowledge retrieval and generation, but also proposes a mechanism of incremental learning and real-time update to ensure that the knowledge base of chemical enterprises can be continuously improved with industry changes and regulatory updates.

[0155] The chemical enterprise knowledge base construction device provided by the present invention is described below. The chemical enterprise knowledge base construction device described below and the chemical enterprise knowledge base construction method described above can be referenced to each other.

[0156] like Figure 6 As shown, in one embodiment, a device for constructing a knowledge base for a chemical enterprise includes a document integration module 610 , a data storage module 620 , a document retrieval module 630 and an answer generation module 640 .

[0157] The document integration module 610 is used to obtain a document data set of a chemical enterprise and organize the document data set into independent knowledge units.

[0158] The data storage module 620 is used to map each document data to a high-dimensional vector space through the embedding mechanism of the large language model to generate an embedding vector, and store the embedding vector and its corresponding document identifier in a vector database.

[0159] The document retrieval module 630 is used to call the embedding function to convert the natural language query text input by the user into a high-dimensional query vector, and calculate the similarity score between the high-dimensional query vector and each embedding vector in the vector database through the vector similarity measurement to select associated document data whose similarity score exceeds a first threshold.

[0160] The answer generation module 640 is used to splice the context of natural language query text and associated document data as input to the RAG generation model, generate answers through the large language model, and build a knowledge base based on the generated answers and associated document data.

[0161] Among them, each document data contains chemical safety information, operating specification information and accident case information. The knowledge unit includes multiple attributes, namely text content, metadata and category. The RAG generation model is built based on the Transformer architecture.

[0162] In this embodiment, the data storage module 620 of the chemical enterprise knowledge base construction device provided by the present invention is specifically used for:

[0163] The knowledge unit corresponding to each document data is mapped to a high-dimensional vector space through the embedding mechanism of the large language model to generate an embedding vector. The embedding formula is:

[0164]

[0165] Where, , is the embedding vector, dimension is d, represents a real vector space of d;

[0166] The generated embedding vectors and corresponding document identifiers are stored in a vector database, and an index is built in the vector database.

[0167] The generated embedding vector and the corresponding document identifier are stored in the vector database in the following storage structure:

[0168]

[0169] Where, is a vector database, For associated documents Its vector representation .

[0170] In this embodiment, the document retrieval module 630 of the chemical enterprise knowledge base construction device provided by the present invention is specifically used to:

[0171] The natural language query text is converted into a high-dimensional query vector through the embedding function. The embedding function expression is:

[0172]

[0173] Where, is a high-dimensional query vector, and , represents a d-dimensional real vector space, is the embedding function, Query text for natural language.

[0174] The similarity score between the high-dimensional query vector and all embedded vectors in the vector database is calculated by the cosine similarity measure. The expression of the cosine similarity measure is:

[0175]

[0176] Where, is the similarity score, is the dot product, which is used to measure the directional similarity of two vectors. is the vector norm, used for normalization.

[0177] In this embodiment, the document retrieval module 630 of the chemical enterprise knowledge base construction device provided by the present invention is further configured to:

[0178] Sort the document data by similarity score, get the sorting result from large to small similarity score, and select the top k related document data from the sorting. The sorting formula is:

[0179]

[0180] Where, is the first k associated document data selected, is a high-dimensional query vector, is the vector representation of the document.

[0181] In this embodiment, the chemical enterprise knowledge base construction device provided by the present invention further includes a model processing module for:

[0182] The context of the natural language query text and associated document data is input into the Transformer model for tokenization to convert the context of the natural language query text and associated document data into multiple discrete tokens, and each token is converted into a corresponding vector representation through the embedding layer.

[0183] The self-attention mechanism is called to process the vector representation of each tag through linear transformation to obtain the query vector, key vector and value vector, and the similarity between the query vector and the key vector is calculated to obtain the attention score.

[0184] In this embodiment, the device for constructing a chemical enterprise knowledge base provided by the present invention, the Transformer model further includes a feedforward neural network layer, which includes two linear layers and an activation function. The expression of the feedforward neural network layer is:

[0185]

[0186] Where, is the output of the feedforward neural network layer, is the activation function, is the weight matrix of the linear transformation, is the bias term, It is the input Token embedding vector.

[0187] Also includes vocabulary building modules for:

[0188] The vector representation of each token is processed through multiple layers of attention and feedforward neural network layers to obtain the contextual representation of each token, and the contextual representation is mapped to the dimension of the vocabulary through linear transformation to form a probability distribution for generating new words.

[0189] In this embodiment, the chemical enterprise knowledge base construction device provided by the present invention further includes a document updating module for:

[0190] New document data is obtained and converted into new embedding vectors, so as to add the new embedding vectors to the vector database.

[0191] Obtain document identifiers of expired document data, and remove the expired document data from the vector database according to the document identifiers.

[0192] Figure 7 The following is a schematic diagram of the physical structure of an electronic device. The electronic device may be a smart terminal, and its internal structure diagram may be as follows: Figure 7 As shown. The electronic device includes a processor, an internal memory, and a network interface connected via a system bus. The processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a method for constructing a chemical enterprise knowledge base is implemented, which includes:

[0193] Obtain document data sets from chemical companies and organize them into independent knowledge units;

[0194] Each document data is mapped to a high-dimensional vector space through the embedding mechanism of the large language model to generate an embedding vector, and the embedding vector and its corresponding document identifier are stored in a vector database;

[0195] Calling an embedding function to convert the natural language query text input by the user into a high-dimensional query vector, and calculating a similarity score between the high-dimensional query vector and each embedding vector in the vector database using a vector similarity metric, so as to select associated document data whose similarity score exceeds a first threshold;

[0196] The natural language query text and the context of the associated document data are spliced ​​together as the input of the RAG generation model, the answer is generated through the large language model, and the knowledge base is built based on the generated answer and the associated document data;

[0197] Among them, each document data contains chemical safety information, operating specification information and accident case information. The knowledge unit includes multiple attributes, namely text content, metadata and category. The RAG generation model is built based on the Transformer architecture.

[0198] Those skilled in the art will understand that Figure 7 The structure shown in the figure is merely a block diagram of a portion of the structure related to the solution of the present invention, and does not constitute a limitation on the electronic device to which the solution of the present invention is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.

[0199] In another aspect, the present invention further provides a computer storage medium storing a computer program, which, when executed by a processor, implements a method for constructing a chemical enterprise knowledge base, the method comprising:

[0200] Obtain document data sets from chemical companies and organize them into independent knowledge units;

[0201] Each document data is mapped to a high-dimensional vector space through the embedding mechanism of the large language model to generate an embedding vector, and the embedding vector and its corresponding document identifier are stored in a vector database;

[0202] Calling an embedding function to convert the natural language query text input by the user into a high-dimensional query vector, and calculating a similarity score between the high-dimensional query vector and each embedding vector in the vector database using a vector similarity metric, so as to select associated document data whose similarity score exceeds a first threshold;

[0203] The natural language query text and the context of the associated document data are spliced ​​together as the input of the RAG generation model, the answer is generated through the large language model, and the knowledge base is built based on the generated answer and the associated document data;

[0204] Among them, each document data contains chemical safety information, operating specification information and accident case information. The knowledge unit includes multiple attributes, namely text content, metadata and category. The RAG generation model is built based on the Transformer architecture.

[0205] In another aspect, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium, and when the processor executes the computer instructions, a method for constructing a chemical enterprise knowledge base is implemented, the method comprising:

[0206] Obtain document data sets from chemical companies and organize them into independent knowledge units;

[0207] Each document data is mapped to a high-dimensional vector space through the embedding mechanism of the large language model to generate an embedding vector, and the embedding vector and its corresponding document identifier are stored in a vector database;

[0208] Calling an embedding function to convert the natural language query text input by the user into a high-dimensional query vector, and calculating a similarity score between the high-dimensional query vector and each embedding vector in the vector database using a vector similarity metric, so as to select associated document data whose similarity score exceeds a first threshold;

[0209] The natural language query text and the context of the associated document data are spliced ​​together as the input of the RAG generation model, the answer is generated through the large language model, and the knowledge base is built based on the generated answer and the associated document data;

[0210] Among them, each document data contains chemical safety information, operating specification information and accident case information. The knowledge unit includes multiple attributes, namely text content, metadata and category. The RAG generation model is built based on the Transformer architecture.

[0211] Those skilled in the art will understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory.

[0212] By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0213] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0214] The above-described embodiments merely illustrate several implementations of the present invention, and while their descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art would be able to make numerous variations and improvements without departing from the spirit of the present invention, all of which fall within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be determined by the appended claims.

Claims

1. A method for constructing a chemical enterprise knowledge base, characterized in that: The method comprises: Acquire a document data set of a chemical enterprise, and organize the document data set into independent knowledge units; Mapping each document data to a high-dimensional vector space through the embedding mechanism of the large language model to generate an embedding vector, and storing the embedding vector and its corresponding document identifier in a vector database; Calling an embedding function to convert a natural language query text input by a user into a high-dimensional query vector, and calculating a similarity score between the high-dimensional query vector and each embedding vector in the vector database using a vector similarity metric, so as to select associated document data whose similarity score exceeds a first threshold; The natural language query text and the context of the associated document data are spliced ​​as input to the RAG generation model, an answer is generated through the large language model, and a knowledge base is constructed based on the generated answer and the associated document data; Among them, each document data contains chemical safety information, operating specification information and accident case information. The knowledge unit includes multiple attributes, namely text content, metadata and category; the RAG generation model is constructed based on the Transformer architecture.

2. The method for constructing a chemical enterprise knowledge base according to claim 1, characterized in that: The embedding mechanism of the large language model is used to map each document data to a high-dimensional vector space to generate an embedding vector, and the embedding vector and its corresponding document identifier are stored in a vector database, including: The knowledge unit corresponding to each document data is mapped to a high-dimensional vector space through the embedding mechanism of the large language model to generate an embedding vector. The embedding formula is: Where, , is the embedding vector, dimension is d, represents a real vector space of d; Storing the generated embedding vector and the corresponding document identifier in a vector database, and constructing an index in the vector database; The generated embedding vector and the corresponding document identifier are stored in the vector database in the following storage structure: Where, is a vector database, For associated documents Its vector representation .

3. The method for constructing a chemical enterprise knowledge base according to claim 2, characterized in that: The calling embedding function converts the natural language query text input by the user into a high-dimensional query vector, and calculates a similarity score between the high-dimensional query vector and each embedding vector in the vector database by a vector similarity metric to select associated document data whose similarity score exceeds a first threshold, including: The natural language query text is converted into the high-dimensional query vector through an embedding function, and the embedding function expression is: Where, is a high-dimensional query vector, and , represents a d-dimensional real vector space, is the embedding function, query text for natural language; The similarity score between the high-dimensional query vector and all embedded vectors in the vector database is calculated by using the cosine similarity metric, where the expression of the cosine similarity metric is: Where, is the similarity score, is the dot product, which is used to measure the directional similarity of two vectors. is the vector norm, used for normalization.

4. The method for constructing a chemical enterprise knowledge base according to claim 3, characterized in that: The embedding function is called to convert the natural language query text input by the user into a high-dimensional query vector, and a similarity score between the high-dimensional query vector and each embedding vector in the vector database is calculated using a vector similarity metric to select associated document data having a similarity score exceeding a first threshold. The method further includes: The document data is sorted according to the similarity score to obtain a sorting result from large to small similarity scores, and the top k related document data are selected from the sorting. The sorting formula is: Where, is the first k associated document data selected, is a high-dimensional query vector, is the vector representation of the document.

5. The method for constructing a chemical enterprise knowledge base according to claim 1, characterized in that: The process of splicing the context of the natural language query text and the associated document data as input to the RAG generation model, generating answers through a large language model, and building a knowledge base based on the generated answers and the associated document data previously includes: Input the context of the natural language query text and associated document data into the Transformer model for tokenization to convert the context of the natural language query text and associated document data into multiple discrete tokens, and convert each token into a corresponding vector representation through an embedding layer; The self-attention mechanism is called to process the vector representation of each tag through linear transformation to obtain the query vector, key vector and value vector, and the similarity between the query vector and the key vector is calculated to obtain the attention score.

6. The method for constructing a chemical enterprise knowledge base according to claim 5, characterized in that: The Transformer model also includes a feedforward neural network layer, which includes two linear layers and an activation function. The expression of the feedforward neural network layer is: Where, is the output of the feedforward neural network layer, is the activation function, is the weight matrix of the linear transformation, is the bias term, Embedding vector for the input Token; The process of splicing the context of the natural language query text and the associated document data as input to the RAG generation model, generating answers through a large language model, and building a knowledge base based on the generated answers and the associated document data may also include: The vector representation of each token is processed through multiple layers of attention and feedforward neural network layers to obtain a contextual representation of each token, and the contextual representation is mapped to the dimensions of the vocabulary through a linear transformation to form a probability distribution for generating new words.

7. The method for constructing a chemical enterprise knowledge base according to any one of claims 1 to 6, characterized in that: The method further comprises: Acquire new document data, and convert the new document data into new embedding vectors, so as to add the new embedding vectors to the vector database; A document identifier of expired document data is obtained, and the expired document data is removed from the vector database according to the document identifier.

8. A chemical enterprise knowledge base construction device, characterized in that: The device comprises: A document integration module is used to obtain a document data set of a chemical enterprise and organize the document data set into independent knowledge units; A data storage module is used to map each document data into a high-dimensional vector space through the embedding mechanism of the large language model to generate an embedding vector, and store the embedding vector and its corresponding document identifier in a vector database; a document retrieval module, configured to call an embedding function to convert a natural language query text input by a user into a high-dimensional query vector, and calculate a similarity score between the high-dimensional query vector and each embedding vector in the vector database using a vector similarity metric, so as to select associated document data whose similarity score exceeds a first threshold; An answer generation module, configured to combine the context of the natural language query text and the associated document data as input to the RAG generation model, generate answers using a large language model, and construct a knowledge base based on the generated answers and the associated document data; Among them, each document data contains chemical safety information, operating specification information and accident case information. The knowledge unit includes multiple attributes, namely text content, metadata and category; the RAG generation model is constructed based on the Transformer architecture.

9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method for constructing a chemical enterprise knowledge base according to any one of claims 1 to 7 are implemented.

10. A computer storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method for constructing a chemical enterprise knowledge base according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Intelligent document query method and system for enterprise knowledge base

    CN118779404A

  • Intelligent question answering method and device based on large language model and computer equipment

    CN120086328A

  • Power distribution network first-aid repair operation safety inspection scheme generation method, system and related device

    CN120123483A

Cited By

  • Power document generation method, system and equipment based on sentence drawing retrieval and medium

    CN120996014A

  • Activation direction searching system and method based on generative model

    CN121051231A

  • Query method and system based on data lake house

    CN121935276A