Steel supply chain knowledge reply method and system based on RAG technology
By constructing a vector library and using a hybrid retrieval method, combined with the TF-IDF model and semantic segmentation technology, the problems of inaccuracy and information interference in large-scale model question answering in the steel industry were solved, and accurate responses to steel supply chain knowledge were achieved.
Patent Information
- Application Number
- CN202410974923.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-19
- Publication Date
- 2024-11-15
AI Technical Summary
Existing large-scale models suffer from inaccurate answers and an inability to provide up-to-date answers when information exceeds the training data range in steel industry question answering. Furthermore, RAG technology is subject to interference in the complex and diverse knowledge retrieval of the steel supply chain, affecting the response performance.
We employ a hybrid retrieval method and a reciprocal ranking fusion algorithm, combined with TF-IDF model and semantic segmentation technology, to construct a vector library and generate segmented keywords. Through vector embedding model, we transform query text into question vectors and perform fusion ranking of multiple retrieval methods to ensure the accuracy and relevance of the responses.
It improved the accuracy and focus of knowledge responses in the steel supply chain, reduced interference, and achieved precise responses to user queries.
Smart Images

Figure CN118964554A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of iron supply chain knowledge management, and in particular to a steel supply chain knowledge recovery method and system based on RAG technology. Background Art
[0002] With the rapid development of the Internet and big data technology, a huge amount of information and documents have been accumulated in the entire steel industry supply chain, providing solid data support for the development of the industry. In this context, effectively integrating and utilizing these resources to provide the industry with accurate and efficient question-and-answer services will further promote the development of the industry.
[0003] As an important breakthrough in the field of natural language processing, the big model provides new possibilities for question-answering services in the steel industry. Today, the big model has a good performance in answering common general text questions, but it still has certain limitations when it comes to highly specialized steel knowledge queries. On the one hand, due to the influence of the parameter scale and training data distribution of the big model itself, there are cases where inaccurate or even wrong answers are given to questions about steel knowledge; on the other hand, due to the timeliness of its own training data, when the information being consulted exceeds the scope of the model training data, the big model is also unable to give the latest and most accurate answer.
[0004] In view of the challenges faced by the above-mentioned large model in the application of question and answer in the steel industry, in order to enhance the reliability and accuracy of knowledge responses, RAG (Retrieval Augmented Generation) technology came into being. It injects external knowledge into the large model so that the large model generates responses based on the knowledge base content, thereby significantly improving the accuracy and relevance of the responses. Therefore, intelligent question and answer based on RAG technology has received widespread attention in the industry. Patent application CN118051587A discloses a method, device and medium for intelligent question and answer in the steel industry based on a large model. The method has the situation of wrong answers. Although RAG technology has advantages in theory, the supply chain of the steel industry usually involves multiple links such as raw material procurement, production and processing, and product distribution. Each link generates a large amount of professional knowledge and data, making the content of the entire supply chain knowledge document complex and diverse, resulting in a certain degree of interference in the RAG technology when retrieving and querying relevant information. Therefore, how to organically combine the complex and diverse steel supply chain knowledge with RAG retrieval, and then improve the response effect generated by the large model has become another challenge in the intelligent question and answer of the steel industry. Summary of the invention
[0005] The purpose of the present invention is to provide a steel supply chain knowledge response method and system based on RAG technology with accurate response.
[0006] The purpose of the present invention can be achieved by the following technical solutions:
[0007] A steel supply chain knowledge recovery method based on RAG technology includes the following steps:
[0008] Get the user's query text and convert it into a question vector;
[0009] Based on the question vector, a hybrid retrieval method is used to search a pre-built vector library to obtain a plurality of similar block data;
[0010] Integrate the query text and the block data into a pre-built reply prompt template and output it, wherein the block data includes block content and keywords;
[0011] The steps to build a vector library include:
[0012] Obtain knowledge documents and document classification labels of different types of steel supply chains, and use semantic segmentation methods to segment knowledge documents into different original block data;
[0013] Based on the different original block data, a TF-IDF model is used to extract document keywords, and the original block data is classified based on the guidance of the document keywords;
[0014] Based on the knowledge document, block classification and the preset number of block keywords, a block keyword generation task prompt template is constructed, and block keywords are further generated. The block keywords are spliced and mapped with the original block data into vectors with semantic features and stored in the vector library to complete the vector library construction process.
[0015] Furthermore, a vector embedding model is used to convert the query text into a question vector.
[0016] Furthermore, the step of obtaining a plurality of similar block data includes:
[0017] Based on the question vector, a plurality of retrieval methods are used to search the vector library respectively, and each retrieval method obtains a plurality of initial block data similar to the question vector and their similarity ranking;
[0018] Based on the similar multiple initial block data and their similarity ranking, a reciprocal sorting fusion algorithm is used to perform fusion sorting, and the top k block data are selected as the final multiple similar block data.
[0019] Furthermore, the retrieval method includes a vector retrieval method, a BM25 retrieval method, a local sensitive hashing method, a product quantization method and a graph-based approximate nearest neighbor search method.
[0020] Furthermore, the expression for fusion sorting by the inverse sorting fusion algorithm is:
[0021]
[0022] Among them, Score represents the result of the inverse sort fusion; n is the total number of retrieval methods; k is a constant with a value of 50, which is used to adjust the influence of the ranking; rank i is the ranking of the block data in the i-th retrieval method; Represents the inverse ranking score of each document in the i-th retrieval method.
[0023] Furthermore, the step of segmenting the different original block data includes:
[0024] The knowledge document is segmented according to line breaks, and the segmented knowledge document is segmented according to sentence-end punctuation to form the different original block data.
[0025] Furthermore, the step of extracting document keywords includes:
[0026] Based on the different block data, the TF-IDF value of the word is calculated using the TF-IDF model. The calculation expression of the TF-IDF value of the word is:
[0027]
[0028] Among them, n i,j is the number of occurrences of word i in block j, ∑ k n k,j is the sum of the occurrences of all words in block j, |D| is the total number of blocks, |{j:i∈j}| is the number of blocks containing word i, TF is the frequency of occurrence of the word in the document, and IDF represents the inverse frequency of occurrence in all documents;
[0029] Sort the TF-IDF values from large to small, and select multiple words with high TF-IDF values as document keywords.
[0030] Furthermore, the step of extracting document keywords also includes:
[0031] The document keywords selected by TF-IDF value are further screened using the daily word blacklist to obtain the final document keywords.
[0032] Furthermore, the step of classifying the original block data includes:
[0033] Building a document classification task prompt template based on the knowledge document, document keywords and document classification labels;
[0034] Based on the document classification task prompt template, the classification model is used to classify the original block data based on the document classification labels.
[0035] This embodiment also provides a steel supply chain knowledge response system based on RAG technology, including:
[0036] Acquisition module: used to obtain the user's query text and convert it into a question vector;
[0037] Retrieval module: used to search the pre-built vector library based on the question vector using a hybrid retrieval method to obtain multiple similar block data;
[0038] Reply module: used to integrate the query text and block data into a pre-built reply prompt template and output it, wherein the block data includes block content and keywords.
[0039] Compared with the prior art, the present invention has the following beneficial effects:
[0040] (1) When generating a reply, the present invention retrieves text content that is highly relevant to the user's query from the vector library, and then integrates the original query text with the highly relevant text content and keywords to ensure the generation of accurate and targeted replies. In the process of building the vector library, the text classification and keyword generation steps are used to promote the effective distinction of document content in the retrieval process, and reduce the interference caused by other document content when querying related information, thereby improving concentration and achieving accurate replies to user queries.
[0041] (2) The present invention combines multiple retrieval methods with a reciprocal sorting fusion algorithm. The multiple retrieval methods can perform retrieval from different aspects, giving full play to the advantages of different retrieval methods. Then, through fusion sorting, it is possible to retrieve block data with higher similarity from the vector library, thereby improving the accuracy of the reply. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 It is a schematic diagram of the method flow of the present invention. DETAILED DESCRIPTION
[0043] The present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments. This embodiment is implemented based on the technical solution of the present invention, and provides a detailed implementation method and specific operation process, but the protection scope of the present invention is not limited to the following embodiments.
[0044] This embodiment provides a steel supply chain knowledge recovery method based on RAG technology, such as Figure 1 As shown, the method comprises the following steps:
[0045] S1. Different block data are obtained based on semantic segmentation of steel industry knowledge documents.
[0046] Table 1 Example of document splitting results
[0047]
[0048] First, the original document is segmented according to line breaks. In order to quickly locate the text, the segmented content needs to be segmented according to the end punctuation (period, exclamation mark, etc.) to finally form different block data containing single sentence content. For the block data of steel documents, in order to provide richer context information, different block data are spliced with a length threshold of 512 to form steel knowledge original data with a certain degree of integrity for subsequent classification, keyword generation and RAG retrieval. The split results are shown in Table 1.
[0049] S2. Create classification labels and a blacklist of daily words.
[0050] Experts in the steel field develop classification labels and daily life word blacklists based on document catalog, content and other characteristics and industry experience. The results are shown in Table 2. Among them, the classification labels are used to complete the classification of different documents and fill in the slots to generate document keyword task prompt templates, and the daily life word blacklist is used to eliminate common daily life words in the extracted document keywords.
[0051] Table 2 Classification labels and daily word blacklist examples based on steel knowledge
[0052]
[0053] S3. Use the TF-IDF model to extract document keywords from different block data.
[0054] The TF-IDF model considers the frequency of a word in a document (TF) and the inverse document frequency (IDF) of the frequency of a word in all documents. TF represents the frequency of a word in a specific document; IDF reflects the distribution density of a word in the entire document collection, which is used to measure the amount of information it provides. It is calculated by dividing the number of all documents by the logarithm of the number of documents containing the word. The product of these two parameters can reflect the importance of the word to the document. For word i and block j, the calculation formula of TF-IDF is as follows:
[0055]
[0056] Among them, n i,j is the number of occurrences of word i in block j, ∑ k n k,jis the sum of the occurrences of all words in chunk j, |D| is the total number of chunks, and |{j:i∈j}| is the number of chunks containing word i.
[0057] The higher the TF-IDF value of a word, the greater the importance of the word in the document. After using the TF-IDF algorithm to obtain the document keywords, the common life words in the extracted document keywords are eliminated using the blacklist constructed in step S2, and these document keywords are sorted from large to small according to the TF-IDF value, and the 10 document keywords with the largest TF-IDF value are selected, thereby obtaining the 10 document keywords most relevant to the steel industry for text classification. Next, a document classification task prompt template as shown in Table 3 is constructed based on the input text, document keywords, and classification labels.
[0058] Table 3 Example of prompt template for steel knowledge document classification task
[0059]
[0060] S4. Generate classification for the block content according to the guidance of the document classification task prompt template.
[0061] With the help of the document classification task prompt template shown in Table 3, different block contents are classified on the existing classification labels based on keywords, where different block data corresponding to the same original data have the same classification, and different original data have different classifications. The classification result examples are shown in Table 4.
[0062] Table 4 Classification results examples
[0063]
[0064] S5. Construct a customized block keyword generation task prompt template for the steel industry.
[0065] According to the original data, field classification, and word quantity, a prompt template with steel industry characteristics is constructed as shown in Table 5. Among them, 'original data' is the original data of a certain document, 'classification' is the classification result corresponding to step S4, and {n} represents the total number of generated keyword results of n. This prompt template can effectively guide the large model to generate block keywords related to the original text by combining the characteristics of the steel industry classification field, wherein the large model represents the model constructed in the embodiment that can directly perform query responses.
[0066] Table 5 Example of the task prompt template for generating keywords for steel knowledge text block
[0067]
[0068] S6. Generate a task prompt template based on the block keywords to guide the large model to generate keywords corresponding to the blocks and perform vector embedding.
[0069] With the help of the block keyword generation task prompt template shown in Table 5, the large model is used to generate steel industry keywords related to the original data in the block, and the block keywords (in the form of specific keyword content followed by a colon) are assigned to the same original data and block data. The splicing result example is shown in Table 6. Finally, a vector embedding model (such as the bge-large-zh model) is used to map the spliced blocks into vectors with semantic features and store them in the vector library.
[0070] Table 6 Example of keyword generation results
[0071]
[0072] S7. Use the vector embedding model to convert the query text entered by the user into a question vector.
[0073] Vector embedding models (such as the bge-large-zh model) are used to vectorize user queries. The vector embedding model converts the natural language query input by the user into a dense numerical vector by understanding and encoding the semantic information in the text, which facilitates the subsequent similarity calculation between the query vector and the vectors in the vector library.
[0074] S8. Mixed use of retrieval and fusion ranking.
[0075] The retrieval method may include multiple methods, such as vector retrieval method, BM25 retrieval method, local sensitive hashing method, product quantization method and graph-based approximate nearest neighbor search method. This embodiment uses vector retrieval and BM25 retrieval methods, and uses the reciprocal rank fusion (RRF, Reciprocal Rank Fusion) algorithm to fusion sort the block results retrieved by the two methods and their order. The formula of RRF is as follows:
[0076]
[0077] Among them, Score represents the result of the inverse sort fusion; n is the total number of search methods, which is 2 here; k is a constant, usually 50, used to adjust the influence of the ranking; rank i is the ranking of the block in the i-th retrieval method; Represents the inverse ranking score of each document in the i-th retrieval method.
[0078] After obtaining the rearranged results and their rankings according to the RRF scores, the top k ranked blocks are selected for recall (the value of k can be adjusted according to the effect of the answer). Finally, the original user query, generated keywords and recalled related content are integrated into the large model reply prompt template shown in Table 7.
[0079] Table 7 Examples of large model reply prompt templates based on search results
[0080]
[0081] S9. The user enters the query text and receives an accurate response.
[0082] With the help of the prompt template shown in Table 7, the big model is used to generate accurate and factual responses to the user's steel knowledge query. Table 8 shows the response results for the steel professional knowledge query "What are the uses of channel steel?" Among them, the reference answer is the response made by the expert based on the question, and the big model answer is the big model's response to the question.
[0083] Table 8 Test results of “What are the uses of channel steel?”
[0084]
[0085] The embodiment of the present invention utilizes a large model, combined with the data characteristics of the steel industry, and develops a RAG method that can accurately respond to steel supply chain knowledge by adding keyword generation processing during the retrieval process. The text classification and keyword generation processing in the embodiment of the present invention fully combine the experience of the steel industry and document characteristics, and are highly original and professional. The method based on the embodiment of the present invention provides accurate business answers for enterprises through intelligent data analysis and mining, has extremely high technical practicality, and realizes the empowerment of business with artificial intelligence technology. The embodiment of the present invention adds two parts of multi-model classification and keyword generation to the retrieval documents, so that the retrieval process can be adapted to the steel industry according to the characteristics of the data itself, so that the large model can accurately respond to queries for steel professional knowledge.
[0086] Example 2
[0087] This embodiment provides a steel supply chain knowledge response system based on RAG technology, including:
[0088] Acquisition module: used to obtain the user's query text and convert it into a question vector;
[0089] Retrieval module: used to search the pre-built vector library based on the question vector using a hybrid retrieval method to obtain multiple similar block data;
[0090] Reply module: used to integrate the query text and block data into a pre-built reply prompt template and output it, wherein the block data includes block content and keywords.
[0091] The rest is the same as in Example 1.
[0092] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0093] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A steel supply chain knowledge recovery method based on RAG technology, characterized in that: The following steps are involved: Get the user's query text and convert it into a question vector; Based on the question vector, a hybrid retrieval method is used to search a pre-built vector library to obtain a plurality of similar block data; Integrate the query text and the block data into a pre-built reply prompt template and output it, wherein the block data includes block content and keywords; The steps to build a vector library include: Obtain knowledge documents and document classification labels of different types of steel supply chains, and use semantic segmentation methods to segment knowledge documents into different original block data; Based on the different original block data, a TF-IDF model is used to extract document keywords, and the original block data is classified based on the guidance of the document keywords; Based on the knowledge document, block classification and the preset number of block keywords, a block keyword generation task prompt template is constructed, and block keywords are further generated. The block keywords are spliced and mapped with the original block data into vectors with semantic features and stored in the vector library to complete the vector library construction process.
2. According to claim 1, a steel supply chain knowledge recovery method based on RAG technology is characterized in that: A vector embedding model is used to convert the query text into a question vector.
3. The steel supply chain knowledge recovery method based on RAG technology according to claim 1 is characterized in that: The step of obtaining a plurality of similar block data comprises: Based on the question vector, a plurality of retrieval methods are used to search the vector library respectively, and each retrieval method obtains a plurality of initial block data similar to the question vector and their similarity ranking; Based on the similar multiple initial block data and their similarity ranking, a reciprocal sorting fusion algorithm is used to perform fusion sorting, and the top k block data are selected as the final multiple similar block data.
4. The steel supply chain knowledge recovery method based on RAG technology according to claim 3 is characterized in that: The retrieval methods include a vector retrieval method, a BM25 retrieval method, a local sensitive hashing method, a product quantization method and a graph-based approximate nearest neighbor search method.
5. The steel supply chain knowledge recovery method based on RAG technology according to claim 3 is characterized in that: The expression for fusion sorting by the reciprocal sorting fusion algorithm is: Among them, Score represents the result of the inverse sort fusion; n is the total number of retrieval methods; k is a constant with a value of 50, which is used to adjust the influence of the ranking; rank i is the ranking of the block data in the i-th retrieval method; Represents the inverse ranking score of each document in the i-th retrieval method.
6. The steel supply chain knowledge recovery method based on RAG technology according to claim 1 is characterized in that: The step of segmenting the different original block data comprises: The knowledge document is segmented according to line breaks, and the segmented knowledge document is segmented according to sentence-end punctuation to form the different original block data.
7. The steel supply chain knowledge recovery method based on RAG technology according to claim 1 is characterized in that: The step of extracting keywords from the document includes: Based on the different block data, the TF-IDF value of the word is calculated using the TF-IDF model. The calculation expression of the TF-IDF value of the word is: Among them, n i,j is the number of occurrences of word i in block j, ∑ j n j,j is the sum of the occurrences of all words in block j, |D| is the total number of blocks, |{j:i∈j}| is the number of blocks containing word i, TF is the frequency of occurrence of the word in the document, and IDF represents the inverse frequency of occurrence in all documents; Sort the TF-IDF values from large to small, and select multiple words with high TF-IDF values as document keywords.
8. The steel supply chain knowledge recovery method based on RAG technology according to claim 1 is characterized in that: The step of extracting keywords from the document also includes: The document keywords selected by TF-IDF value are further screened using the daily word blacklist to obtain the final document keywords.
9. The steel supply chain knowledge recovery method based on RAG technology according to claim 1 is characterized in that: The step of classifying the original block data comprises: Building a document classification task prompt template based on the knowledge document, document keywords and document classification labels; Based on the document classification task prompt template, the classification model is used to classify the original block data based on the document classification labels.
10. A steel supply chain knowledge response system based on RAG technology, characterized in that: include: Acquisition module: used to obtain the user's query text and convert it into a question vector; Retrieval module: used to search the pre-built vector library based on the question vector using a hybrid retrieval method to obtain multiple similar block data; Reply module: used to integrate the query text and block data into a pre-built reply prompt template and output it, wherein the block data includes block content and keywords.
Citation Information
Patent Citations
Steel industry intelligent question and answer method and device based on large model and medium
CN118051587A
Cited By
Guided inquiry method and system based on large language model, electronic equipment and storage medium
CN119581065A
Versioning consistency verification system and method for language generation
CN120851036A
A versioned consistency checking system and method for language generation
CN120851036B
