Answer generation method, system and device based on RAG technology and storage medium
By building an enterprise knowledge base using RAG technology and employing a generative large language model, the problems of insufficient semantic understanding and timeliness of large models in traditional retrieval systems are solved, enabling accurate and personalized multimodal information retrieval and answer generation within the enterprise.
Patent Information
- Application Number
- CN202511067518.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-31
- Publication Date
- 2025-12-19
AI Technical Summary
Traditional enterprise internal retrieval systems cannot handle synonyms/polysemous words, ignore implicit semantics and document logical relationships, have poor usability, limited timeliness of large model knowledge and insufficient domain expertise, and are difficult to meet the precise retrieval needs of enterprises.
By employing RAG technology, an internal enterprise knowledge base is built to perform semantic similarity calculation and multimodal intent parsing. Combined with a generative large language model, answers are generated, supporting synonym recognition, polysemous word disambiguation, capturing implicit associations, and providing accurate answer location and personalized ranking.
It improves semantic understanding capabilities, enhances the usability of association mining and retrieval results, solves the timeliness and professionalism issues of large models, supports multimodal data retrieval, and improves information acquisition efficiency and decision support value.
Smart Images

Figure CN121168593A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of artificial intelligence technology, specifically relating to a method, system, device, and storage medium for generating answers based on RAG technology. Background Technology
[0002] Traditional enterprise internal retrieval systems rely on keyword matching (inverted index + Boolean logic) and TF-IDF / BM25 algorithms, which have three major drawbacks: 1) Lack of semantic understanding: unable to handle synonyms / polysemous words and does not support complex queries; 2) Weak association mining: ignores implicit semantics and document logical relationships; 3) Poor result usability: only returns a list of documents, lacking precise targeting and personalized ranking. Large-scale model applications are also limited: 1) Knowledge timeliness is constrained by the training data cutoff date; 2) Insufficient domain specialization, easily leading to factual errors. Both types of technologies struggle to meet the precise retrieval needs of enterprises. Summary of the Invention
[0003] In view of the above-mentioned shortcomings of the prior art, the present invention provides an answer generation method, system, device and storage medium based on RAG technology to solve the above-mentioned technical problems.
[0004] In a first aspect, the present invention provides an answer generation method based on RAG technology, comprising: Receive user-input question text; Based on the question text, semantic retrieval is performed in a pre-built knowledge base to calculate the semantic similarity between the question text and knowledge fragments in the knowledge base, and target knowledge fragments whose semantic similarity meets a preset threshold are retrieved. The question text and the target knowledge fragment are concatenated to form input prompt words; The input prompts are fed into a pre-trained generative large language model, which then generates and outputs the corresponding answer text.
[0005] In an optional implementation, based on the question text, semantic retrieval is performed in a pre-built knowledge base, and the semantic similarity between the question text and knowledge fragments in the knowledge base is calculated, including: By combining user roles and historical behavior data, multimodal intent parsing is performed on user input to obtain semantic vector representations; The generated semantic vector representation is input into the FAISS framework. The similarity between the semantic vector representation and the knowledge base vector is calculated using the Euclidean distance algorithm. Multiple text units with similarity higher than a preset threshold are filtered out, and the text units and metadata are returned in order of similarity.
[0006] In one optional implementation, the method for constructing the knowledge base includes: Define the scope of the enterprise's internal professional fields covered by the knowledge base, including corporate rules and regulations, financial processes, and human resources management documents; By connecting to the enterprise knowledge management system via an interface, it collects text data in HTML / PDF / WORD format and scanned images of flowcharts / reports; it performs tag stripping, special character filtering, and word deletion operations based on a predefined stop word list on the HTML text; Long texts are segmented into independent semantic units according to themes using a large language model; question-answer pairs corresponding to each semantic unit are generated based on preset prompt templates; and a bidirectional index between semantic units and knowledge graph nodes is established using entity relation extraction technology. The CLIP model is used to jointly encode text and images; Generate an index for the encoded text and images.
[0007] In an optional implementation, the method further includes: Data collected from the enterprise knowledge management system is cleaned using methods including: Perform character removal, date / unit standardization conversion, missing value filling, and duplicate data deletion on text data; Perform integrity verification, resolution standardization adjustment, and duplicate image recognition and removal based on perceptual hashing algorithm on image data.
[0008] In one optional implementation, generating an index for the encoded text and images includes: Semantic units, question-answer pairs, and their encoded vectorized representations are stored in the FAISS vector database; Store the original image in an object storage system; The metadata is associated with the vector index and the image storage path, including the source, timestamp, and author information.
[0009] In an optional implementation, the question text and the target knowledge fragment are concatenated to form input prompt words, including: Obtain user roles, fill user roles, user questions, and target knowledge fragments into a pre-set prompt word template to obtain input prompt words.
[0010] In an optional implementation, the input prompt words are fed into a pre-trained generative large language model, which then generates and outputs the corresponding answer text, including: By connecting to generative large models deployed in the cloud or locally through an abstraction layer framework, the integrated prompts and functional metadata of callable tools are input into the large model.
[0011] Secondly, the present invention provides an answer generation system based on RAG technology, comprising: The question receiving module is used to receive the question text input by the user; The knowledge retrieval module is used to perform semantic retrieval in a pre-built knowledge base based on the question text, calculate the semantic similarity between the question text and knowledge fragments in the knowledge base, and retrieve target knowledge fragments whose semantic similarity meets a preset threshold. The splicing module is used to splice the question text and the target knowledge fragment to form input prompt words; The answer generation module is used to input the input prompt words into a pre-trained generative large language model, which then generates and outputs the corresponding answer text.
[0012] Thirdly, a device is provided, comprising: Memory, used to store the answer generation program based on RAG technology; A processor, used to implement the steps of the RAG-based answer generation method as provided in the first aspect when executing the RAG-based answer generation program.
[0013] Fourthly, a computer-readable storage medium is provided, on which an answer generation program based on RAG technology is stored, wherein when the answer generation program based on RAG technology is executed by a processor, the answer generation program based on RAG technology implements the steps of the answer generation method based on RAG technology provided in the first aspect.
[0014] The beneficial effects of this invention lie in the fact that the answer generation method, system, device, and storage medium based on RAG technology provided by this invention achieve three major breakthroughs through a large language model: 1) Semantic understanding: supporting synonym recognition, polysemous word disambiguation, and complex queries; 2) Association mining: capturing implicit associations (such as "attendance anomalies" and "absenteeism handling process") by combining knowledge graphs; 3) Result optimization: providing accurate answer positioning and personalized ranking (based on user roles / historical behavior). It also addresses the pain points of large models: ensuring timeliness and professionalism through a domain knowledge base, and reducing "illusions" by combining retrieval facts. Additionally, it supports multimodal retrieval (text / image / voice), comprehensively improving the efficiency of enterprise information acquisition and decision support value. Attached Figure Description
[0015] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 This is a schematic flowchart of a method according to an embodiment of the present invention.
[0017] Figure 2 This is a schematic block diagram of a system according to an embodiment of the present invention.
[0018] Figure 3 This is a schematic diagram of the structure of a device provided in an embodiment of the present invention. Detailed Implementation
[0019] To enable those skilled in the art to better understand the technical solutions of this invention, the technical solutions of the embodiments of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this invention, and not all embodiments. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this invention.
[0020] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
[0021] The key terms used in this invention will be explained below.
[0022] Retrieval-augmented generation (RAG) is one of the most popular cutting-edge technologies for large-scale models.
[0023] Retrieval-enhanced generative models combine language modeling and information retrieval techniques. Specifically, when the model needs to generate text or answer questions, it first retrieves relevant information from a large collection of documents, and then uses this retrieved information to guide text generation, thereby improving the quality and accuracy of predictions.
[0024] The answer generation method based on RAG technology provided in this embodiment of the invention is executed by a computer device, and correspondingly, the answer generation system based on RAG technology runs in the computer device.
[0025] Figure 1 This is a schematic flowchart illustrating a method according to an embodiment of the present invention. Wherein, Figure 1 The implementing entity can be an answer generation system based on RAG technology. Depending on different needs, the order of steps in this flowchart can be changed, and some can be omitted.
[0026] like Figure 1 As shown, the method includes: S1. Receive the user's input question text; S2. Based on the question text, perform semantic retrieval in a pre-built knowledge base, calculate the semantic similarity between the question text and knowledge fragments in the knowledge base, and retrieve target knowledge fragments whose semantic similarity meets a preset threshold; S3. The question text and the target knowledge fragment are concatenated to form input prompt words; S4. Input the input prompt words into a pre-trained generative large language model, and the generative large language model generates and outputs the corresponding answer text.
[0027] This invention proposes an answer generation method based on RAG technology. RAG (Retrieval Augmented Generation) technology is a hybrid framework that combines information retrieval and generative artificial intelligence. It is mainly designed to address the technical shortcomings caused by large models relying on static training knowledge: limited timeliness, insufficient domain specialization, and the generation of factual errors.
[0028] Its core principle is to provide precise contextual support to large language models (LLMs) through real-time retrieval of external knowledge bases, thereby improving the accuracy and credibility of responses. Its workflow consists of three steps: During the knowledge base construction phase, domain-related text data is collected, cleaned and preprocessed, and then segmented and vectorized for storage. During the retrieval phase, the user's questions are semantically matched with the vectorized document library to extract the most relevant knowledge fragments; In the generation phase, the search results and the original question are input into a large model to generate a fact-based answer.
[0029] RAG retains the language understanding and generation capabilities of LLM, while overcoming the limitations of traditional models that rely on static training data and are prone to "illusions" through dynamic knowledge retrieval. It is widely used in scenarios such as intelligent question answering and knowledge base interaction.
[0030] In one embodiment of the present invention, based on step S2, the following will provide a possible embodiment and describe its specific implementation in a non-limiting manner.
[0031] Multimodal intent parsing is performed on user input by combining user roles and historical behavior data to obtain semantic vector representations. The generated semantic vector representations are then input into the FAISS framework, and the similarity between the semantic vector representations and knowledge base vectors is calculated using the Euclidean distance algorithm. Multiple text units with similarity higher than a preset threshold are selected, and the text units and metadata are returned in order of similarity.
[0032] In one example, the retrieval method includes: Retrieval text preprocessing: Correct and expand the user input text. Combine the user role and the user's historical behavior to understand the user's intention and generate a clearer and more accurate retrieval text. The user input supports multimodal queries (such as uploading pictures + text descriptions). During retrieval, match multimodal vectors such as text and images, and use the same embedding model as in the knowledge base construction phase to generate corresponding high-dimensional semantic vector representations. Similarity retrieval: Implement efficient vector retrieval based on the FAISS framework. Use the Euclidean distance algorithm to calculate the similarity between the query vector and the knowledge vector. Set an appropriate threshold, and according to the similarity, return the Top-K most relevant text units and their metadata sorted.
[0033] Adaptive retrieval: Different from the standard RAG retrieval enhancement system, the present invention evaluates the retrieved documents to ensure that only the most relevant and reliable information is used to generate responses, avoiding interference of the model by irrelevant data and improving the output accuracy. For some documents with unknown sources and chaotic data, they will be excluded.
[0034] Among them, the method for constructing the knowledge base includes: Domain definition: Determine the professional domain scope covered by the knowledge base, focusing on specific industry domains such as medical, legal, education, computer, etc. The knowledge base of this system is mainly used for enterprise internal retrieval enhancement, including but not limited to documents in the fields of enterprise rules and regulations, financial processes, personnel management, etc. Data collection: Use interfaces to connect to the enterprise internal knowledge management system to collect multimodal data sources, including text (HTML / PDF / WORD), scanned images (flowcharts, reports). For example, for HTML format documents, use BeautifulSoup to remove the HTML tags therein, so as to only retain the pure text content. Implement operations to remove special characters and punctuation marks in the text through regular expressions to simplify the text. For stop words,借助 the stop word lists provided by natural language processing libraries such as NLTK and spaCy, remove the stop words that frequently appear but have no substantial meaning for text semantic expression, such as "de", "shi", "zai", etc., from the text to improve the text quality and lay a foundation for subsequent text analysis and processing processes.
[0035] Data cleaning: For text files, remove noises such as garbled characters and abnormal data, perform standardized conversions on dates and measurement units, detect and fill in missing values and remove duplicate data, and improve the accuracy of subsequent processes through text standardization processing. For picture data, use an image library (such as Pillow) to check the integrity of the pictures, identify and remove damaged or unopenable picture files. Adjust the size and resolution of all pictures to a consistent standard to facilitate subsequent feature extraction and model processing. By calculating the hash value of the pictures (such as the perceptual hash algorithm), compare the similarity between pictures, and identify and delete duplicate pictures.
[0036] Semantic chunking: A large language model is used to break down long texts into meaningful, relatively independent small units and generate corresponding question-and-answer pairs for better organization and understanding of the text content. By setting specific prompt templates, the large language model is guided to generate question-and-answer pairs and segment the text as required. For example, inputting a prompt like "Please divide the following text into paragraphs according to different topics, and generate a question and answer for each paragraph: [specific text]" will allow the model to segment the text and generate question-and-answer pairs based on the text content. This approach allows for flexible control over the direction and content of generation and is applicable to various types of text. Contextually coherent text units (chunks) are generated to construct a question-and-answer pair knowledge structure corresponding to the text units. Entity relations are extracted using SPACY / DeepKE to establish a bidirectional index between text blocks / image blocks and graph nodes.
[0037] Vectorization: CLIP technology is used to jointly encode text and images to generate a unified semantic vector representation. CLIP is a multimodal learning method that trains on a large scale of image-text pairs through a contrastive learning mechanism, mapping images and text to the same semantic space, ensuring that images and texts with similar semantics are close in distance within that space. The text is preprocessed using CLIP's Transformer text encoder; images are processed using a ViT architecture image encoder. In this way, data from different modalities are encoded into a unified vector, facilitating subsequent similarity calculations and retrieval operations within the same space.
[0038] Index storage: Text question-and-answer pairs paragraphs, high-dimensional vector representations of question-and-answer pairs, and metadata (source, timestamp, author, element file storage path) are stored in the FAISS vector database. The original image files are stored based on MinIO objects, and the metadata of the file storage is associated with the vector index to facilitate subsequent user queries and retrieval.
[0039] In one embodiment of the present invention, based on step S3, the following will provide a possible embodiment and describe its specific implementation in a non-limiting manner.
[0040] Design structured prompt templates such as: "Background knowledge: {search content}, Question: {user query}, User role: {user role}, please generate a professional answer based on the above information", and dynamically populate the predefined fields of the template with the search results.
[0041] In one embodiment of the present invention, based on step S4, the following will provide a possible embodiment and describe its specific implementation in a non-limiting manner.
[0042] Extending model capabilities through Function Calling: Function Calling is a technique that allows large language models to enhance their capabilities by calling external functions or APIs. Custom tools can be developed using the Spring AI framework. For example, when a user needs to query the current time or perform specific numerical calculations, the model can call the appropriate tool to obtain the results, thereby generating a more accurate answer.
[0043] Based on the Spring AI framework, it integrates with various cloud-based or locally deployed language models (such as CachtGPT and DeepSeek). It combines input prompts, user input, and function calling metadata to integrate retrieved multimodal content (text, images, and tables) into a contextual framework, guiding the large model to generate richly illustrated answers. Reflective tags are introduced as a unique form of internal dialogue to deeply guide the large model's decision-making. These tags enable the large model to dynamically determine when to retrieve more information to provide a more comprehensive answer to questions, based on specific tasks and input information. Simultaneously, it objectively and deeply evaluates its generated responses to determine whether they accurately and completely meet user needs. Furthermore, it flexibly adjusts the output content according to specific standards, such as accuracy, relevance, and completeness, ensuring the final answer provided to the user has high quality and reliability. Reflective tags include retrieval tags indicating retrieval needs, such as "Yes" indicating retrieval is needed, "No" indicating no retrieval is needed, and "continue to use evidence" indicating that previously retrieved information can be used; relevance (ISREL) tags assessing the relevance of retrieved information, such as "Relevant" and "Irrelevant"; and support (ISSUP) tags judging the degree to which retrieved information supports the generated content, categorized as "Fully Supported," "Partially Supported," and "No Support / Contradictory." Implement consistency verification between response content and search results. Use a small discriminant model to check the consistency between generated content and search results. If a contradiction is detected, trigger a re-search and generation. At the same time, record the user's correction of the answer (such as manually marking errors). Optimize the knowledge base segmentation in reverse. For text blocks that frequently cause contradictions, mark them with a pending review label for temporary isolation and trigger manual review.
[0044] The beneficial effects of this method include: Significantly enhanced semantic understanding capabilities: Breaking through the limitations of traditional keyword matching, the system can understand user intent through a large language model. It can identify synonyms, eliminate ambiguity of polysemous words, support users in performing complex queries and multimodal semantic retrieval, and generate richly illustrated search results. Enhanced latent association mining capabilities: Larger models can capture implicit semantic relationships between texts, such as discovering the potential connection between "attendance anomalies" and "absenteeism handling process." When users query related information, they can provide more comprehensive and in-depth knowledge content, which helps ensure smooth business processes and collaborative work. Simultaneously, the introduction of cross-document connections from knowledge graphs results in a high recall rate for latent associations. The usability of search results has been significantly improved: Precise answer location is achieved, moving beyond simply returning a list of documents. By combining search results with the capabilities of large-scale models, accurate answers are directly provided to users, reducing the workload of manual secondary screening and improving information retrieval efficiency. Personalized search is supported, combining user roles (such as engineers, executives, etc.) and historical behavior (such as frequently searched areas) to identify user intent and provide personalized search results that meet the needs of different users, enhancing the value of search results in supporting decision-making.
[0045] Supports multimodal data retrieval: It can process multimodal data such as images and voice, and uses CILP technology to jointly encode text and images, transforming them into searchable high-dimensional vector representations. Addressing existing issues with large-scale models: Overcoming the limitation of knowledge timeliness in large-scale models by building specialized domain knowledge bases enables the acquisition of the latest knowledge information, ensuring the timeliness and accuracy of answers and allowing enterprise users to retrieve the latest professional domain knowledge. Enhancing domain specialization: For specific vertical domains of enterprises, specialized knowledge bases are built to provide in-depth domain knowledge, meeting the needs of enterprises in professional business areas and improving the professionalism and relevance of answers. Reducing factual errors in generated content: By combining retrieved factual evidence to generate answers, the "illusion" phenomenon of large-scale models is effectively avoided, improving the credibility and reliability of answers.
[0046] In some embodiments, the RAG-based answer generation system may include multiple functional modules composed of computer program segments. The computer programs for each program segment in the RAG-based answer generation system may be stored in the memory of a computer device and executed by at least one processor to perform (see details). Figure 1 (Description) Functionality for answer generation based on RAG technology.
[0047] In this embodiment, the answer generation system based on RAG technology can be divided into multiple functional modules according to the functions it performs, such as... Figure 2As shown. The module referred to in this invention is a series of computer program segments that can be executed by at least one processor and perform a fixed function, and is stored in memory. In this embodiment, the functions of each module will be described in detail in subsequent embodiments.
[0048] The question receiving module is used to receive the question text input by the user; The knowledge retrieval module is used to perform semantic retrieval in a pre-built knowledge base based on the question text, calculate the semantic similarity between the question text and knowledge fragments in the knowledge base, and retrieve target knowledge fragments whose semantic similarity meets a preset threshold. The splicing module is used to splice the question text and the target knowledge fragment to form input prompt words; The answer generation module is used to input the input prompt words into a pre-trained generative large language model, which then generates and outputs the corresponding answer text.
[0049] Figure 3 The RAG-based answer generation method provided in this application embodiment can be applied to devices. Those skilled in the art will understand that the device structure involved in the embodiments of this invention does not constitute a limitation on the device; a device may include more or fewer components than illustrated, or combine certain components, or have different component arrangements. In the embodiments of this invention, the device includes, but is not limited to, laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the embodiments of this application described and / or claimed herein.
[0050] The device 300 may include a processor 310, a memory 320, and a communication unit 330. These components communicate via one or more buses. Those skilled in the art will understand that the server structure shown in the figure does not constitute a limitation of the present invention. It may be a bus topology or a star topology, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0051] The memory 320 can be used to store execution instructions of the processor 310. The memory 320 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. When the execution instructions in the memory 320 are executed by the processor 310, the device 300 is able to perform some or all of the steps in the above method embodiments.
[0052] The processor 310 serves as the control center of the storage device, connecting various parts of the electronic device via various interfaces and lines. It executes software programs and / or modules stored in the memory 320, and calls data stored in the memory to perform various functions of the electronic device and / or process data. The processor can be composed of integrated circuits (ICs), such as a single packaged IC or multiple packaged ICs with the same or different functions connected together. For example, the processor 310 may consist only of a central processing unit (CPU). In this embodiment of the invention, the CPU may have a single processing core or include multiple processing cores.
[0053] The communication unit 330 is used to establish a communication channel, enabling the storage device to communicate with other devices. It can receive user data sent by other devices or send user data to other devices.
[0054] The present invention also provides a computer storage medium, wherein the computer storage medium may store a program, which, when executed, may include some or all of the steps provided in the embodiments of the present invention. The storage medium may be a magnetic disk, an optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0055] Those skilled in the art will clearly understand that the techniques in the embodiments of the present invention can be implemented using software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solutions in the embodiments of the present invention, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, or any other medium capable of storing program code. It includes several instructions to cause a computer device (which may be a personal computer, a server, or a second device, network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.
[0056] The same or similar parts between the various embodiments in this specification can be referred to mutually. In particular, the device embodiments are basically similar to the method embodiments, so the description is relatively simple, and the relevant parts can be referred to the description in the method embodiments.
[0057] In the embodiments provided by this invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative. For instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between systems or modules may be electrical, mechanical, or other forms.
[0058] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0059] In addition, the functional modules in the various embodiments of the present invention can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module.
[0060] Although the present invention has been described in detail with reference to the accompanying drawings and preferred embodiments, the present invention is not limited thereto. Various equivalent modifications or substitutions can be made to the embodiments of the present invention by those skilled in the art without departing from the spirit and essence of the invention, and such modifications or substitutions should all be within the scope of the present invention. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should also be covered within the protection scope of the present invention.
Claims
1. A method for answer generation based on RAG technology, characterized in that, The method comprises the following steps: receiving a question text input by a user; performing semantic retrieval in a pre-constructed knowledge base based on the question text, calculating the semantic similarity between the question text and the knowledge fragments in the knowledge base, and retrieving a target knowledge fragment whose semantic similarity meets a preset threshold; splicing the question text and the target knowledge fragment to form an input prompt word; inputting the input prompt word into a pre-trained generative large language model to generate a corresponding answer text and outputting the answer text.
2. The method of claim 1, wherein, Based on the question text, perform semantic retrieval in a pre-constructed knowledge base, calculate the semantic similarity between the question text and the knowledge fragments in the knowledge base, including: Perform multi-modal intent analysis on user input combined with user roles and historical behavior data to obtain semantic vector representation; Input the generated semantic vector representation into the FAISS framework to calculate the similarity between the semantic vector representation and the knowledge base vector through the Euclidean distance algorithm, filter a plurality of text units with a similarity higher than a preset threshold, and return the text units and metadata in order of similarity.
3. The method of claim 1, wherein, The method for constructing the knowledge base comprises the following steps: Determine the scope of the enterprise internal professional field covered by the knowledge base, including enterprise rules and regulations, financial processes, and personnel management documents; Through the interface, connect to the enterprise knowledge management system to collect HTML / PDF / WORD format text data and process diagram / image data; perform tag stripping, special character filtering, and word deletion based on a pre-defined stop word list on HTML text; Divide long text into independent semantic units based on a large language model; generate question and answer pairs corresponding to each semantic unit based on a preset prompt template; and establish a bidirectional index between the semantic units and the knowledge graph nodes using entity relationship extraction technology; Use the CLIP model to jointly encode the text and the image; Index the encoded text and image.
4. The method of claim 3, wherein, The method further comprises the following steps: Clean the data collected from the enterprise knowledge management system, and the cleaning method comprises the following steps: Perform the following operations on the text data: remove garbled characters, standardize dates / units of measurement, fill in missing values, and delete duplicate data; Perform the following operations on the image data: integrity verification, resolution standardization adjustment, and duplicate image identification and removal based on the perceptual hashing algorithm.
5. The method of claim 3, wherein, Index the encoded text and image, including: Store the semantic units, question and answer pairs, and their vectorized representations in the FAISS vector database; Store the original image in the object storage system; Associate the vector index with the image storage path through metadata, which includes source, timestamp, and author information.
6. The method of claim 1, wherein, Splice the question text and the target knowledge fragment to form an input prompt word, including: Obtain the user role, fill in the user role, user question, and target knowledge fragment into the pre-set prompt word template to obtain the input prompt word.
7. The method of claim 1, wherein, Input the input prompt word into a pre-trained generative large language model to generate a corresponding answer text and output the answer text, including: Access the generative large model deployed in the cloud or locally through the abstraction layer framework, and input the integrated prompt word and the functional metadata of the callable tool into the large model.
8. An answer generation system based on RAG technology, characterized in that, A question receiving module is configured to receive a question text input by a user; A knowledge retrieving module is configured to perform semantic retrieval in a pre-constructed knowledge base based on the question text, calculate semantic similarity between the question text and knowledge segments in the knowledge base, and retrieve a target knowledge segment with a semantic similarity satisfying a preset threshold; A splicing processing module is configured to splice the question text and the target knowledge segment to form an input prompt word; An answer generating module is configured to input the input prompt word into a pre-trained generative large language model, and generate and output a corresponding answer text from the generative large language model.
9. An answer generation apparatus based on RAG technology, characterized by, The method comprises the following steps: A memory is configured to store an answer generation program based on RAG technology; A processor is configured to implement the steps of the answer generation method based on RAG technology according to any one of claims 1-7 when executing the answer generation program based on RAG technology.
10. A computer readable storage medium storing a computer program, characterized in that, The readable storage medium stores an answer generation program based on RAG technology, and the steps of the answer generation method based on RAG technology according to any one of claims 1-7 are implemented when the answer generation program based on RAG technology is executed by a processor.
Citation Information
Cited By
Intelligent question and answer processing method and device in scientific computing software environment
CN121958510A
