RAG knowledge base construction method, equipment and medium
By employing a multi-level priority judgment and a segmentation and storage method driven by a large language model, the semantic fragmentation problem of RAG technology when processing special types of data is solved. This enables unified parsing and associated storage of multimodal data, improves retrieval accuracy and data management efficiency, and expands the application scenarios of the knowledge base.
Patent Information
- Application Number
- CN202511532060.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-24
- Publication Date
- 2026-02-10
AI Technical Summary
Existing RAG technology suffers from semantic fragmentation and loss of key information when processing special types of data such as resumes, legal documents, and tables. It also lacks multimodal support, retrieval accuracy, the ability to parse non-text data, and a deep understanding of the semantics of the data.
The input data is evaluated for format, structure, and semantic features using a multi-level priority judgment logic. Data slices are generated using a segmentation strategy, and keywords are generated and stored using a large language model. Combined with a multimodal data management mechanism, the parsing and associated storage of multimodal data are realized.
It enhances the integrity and logical coherence of knowledge units, expands the coverage of the knowledge base, improves retrieval accuracy and response precision, ensures data security and privacy, and enables efficient management and retrieval of heterogeneous resources.
Smart Images

Figure CN121503606A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence, and in particular to a method, device and medium for constructing a RAG knowledge base. Background Technology
[0002] Retrieval Enhanced Generation (RAG) technology, as the core framework for knowledge retrieval and intelligent generation, has been widely applied in enterprise-level knowledge management, professional domain question answering, and other scenarios.
[0003] However, the existing RAG technology segmentation strategy is singular and fixed, and it does not design adaptation logic for special types of data such as resumes, legal documents, and tables. It only uses a general slicing method, which easily severs the contextual relationship of data, resulting in semantic breaks in knowledge base slices or loss of key information, affecting the subsequent retrieval and generation effect.
[0004] Secondly, existing RAG technologies lack multimodal support capabilities. Limited to text data management, they cannot parse non-text data such as audio (e.g., MP3, WAV formats) and video (e.g., MP4, AVI formats), resulting in limited knowledge base coverage and difficulty in combining multimodal resources to output rich responses. Furthermore, there is insufficient retrieval accuracy. Existing RAGs rely on traditional methods such as vector retrieval, failing to incorporate large models for keyword generation and lacking a deep understanding of data semantics. This makes them prone to retrieval bias when faced with ambiguous queries or within specialized fields. Summary of the Invention
[0005] This application provides a method, device, and medium for constructing a RAG knowledge base. The method includes: logically judging the format features, structural features, and semantic features of input data through multi-level priority judgment logic to determine the data type of the input data; the data type is one of question-and-answer pairs, resumes, tables, papers, books, legal provisions, PPTs, general data, or multimodal data; according to the data type, calling a preset segmentation strategy to segment the input data to generate data slices; the data slices have slice identifiers and metadata; calling a large language model to asynchronously generate keywords for each data slice according to a preset prompt word configuration to obtain a keyword set; the keyword set includes links to the identifiers of each data slice; storing each data slice and its corresponding resource links and keyword set according to a mixed storage mode of structured metadata and unstructured raw data to generate a RAG knowledge base; receiving user query requests, and based on the same preset prompt word configuration, calling a large language model to generate a query keyword set; matching the query keyword set with the keyword set in the RAG knowledge base to obtain search results.
[0006] In one example, based on the data type, a preset segmentation strategy is invoked to segment the input data and generate data slices. Specifically, when the data type is non-multimodal, a preset segmentation logic library is matched according to the data type, and the corresponding segmentation strategy in the segmentation logic library is invoked to segment the input data and generate data slices; when the data type is multimodal, a preset private multimodal large model is invoked, and the input data is asynchronously parsed according to a preset prompt word template to generate text descriptions; the text descriptions are then bound to the input data through a unique resource ID to form data description slices.
[0007] In one example, when the data type is non-multimodal data, a preset segmentation logic library is matched according to the data type, and the corresponding segmentation strategy in the segmentation logic library is called to segment the input data to generate data slices. Specifically, this includes: when the data type is a question-answer pair, for structured question-answer pairs, each question and answer is segmented as an independent data slice; for unstructured question-answer pairs, semantically related question-answer content is encapsulated into an independent single data slice by identifying the question start identifier and the answer start identifier; when the data type is a resume, the resume content is segmented into modules, and each resume content module is an independent data slice. When the data type is legal text, it is segmented according to the clause number and hierarchical relationship; when the data type is a table, it is segmented according to the table row and column association logic; when the data type is a thesis, it is segmented according to the academic chapter division, and formulas, charts and graphs are bound to the corresponding text content; when the data type is a PPT, it is segmented with each slide as an independent segment unit; when the data type is a book, it is segmented according to the first-level chapter identifier; when the data type is general data, it is split according to the user-preset token threshold and a sliding window overlap strategy.
[0008] In one example, a large language model is invoked to asynchronously generate keywords for each data slice based on a preset prompt word configuration, resulting in a keyword set. Specifically, this involves: loading the corresponding preset prompt word configuration according to the data type of the data slice; the prompt word configuration includes multiple predefined templates from the system or custom instructions provided by the user through a configuration interface; creating a corresponding keyword generation task for each data slice and adding the keyword generation task to the asynchronous task queue; inputting each data slice and its corresponding prompt word configuration into the large language model to generate a keyword list for each data slice; performing semantic deduplication on the keyword list and verifying the relevance between the deduplicated keywords and the data slice; when the relevance is greater than a preset relevance threshold, the keyword list is determined as a subset of the keywords for the data slice; and summing the keyword subsets corresponding to each data slice to obtain the keyword set.
[0009] In one example, based on a hybrid storage model of structured metadata and unstructured raw data, each data slice, its corresponding resource links, and keyword sets are stored to generate a RAG knowledge base. Specifically, this includes: extracting the resource links corresponding to each data slice and the structured metadata of the keyword sets; the metadata includes a unique slice identifier, data type, generation time, associated resource link identifiers, keyword set association identifiers, and source data identifiers; performing format standardization and integrity verification on the unstructured raw data; the unstructured raw data includes the original data slice text, multimodal resource files, and a copy of the original data; and storing the unique slice identifier and the original data slice text storage path, multimodal resource files, and other related information. Resource file storage paths and keyword set storage addresses are bound together to establish an association index between structured metadata and unstructured raw data. The extracted structured metadata is stored in a relational database, while the unstructured raw data, after integrity verification, is stored in a distributed file system. By randomly selecting unique slice identifiers, the storage paths recorded in the metadata are checked to ensure they accurately point to the corresponding unstructured data, thus verifying the association between the stored structured metadata and the unstructured raw data. After successful verification, the metadata index in the relational database and the resources in the distributed file system are integrated to obtain the RAG knowledge base, and the generation time and version identifier of the RAG knowledge base are recorded.
[0010] In one example, a multi-level priority judgment logic is used to logically judge the format characteristics, structural characteristics, and semantic characteristics of the input data to determine the data type. Specifically, this includes: identifying the format identification information of the input data and performing a first-level type judgment based on the file extension and file structure identifier; if the first-level judgment fails to determine the data type, performing a second-level type judgment based on the document hierarchy structure and specific paragraph marks; if the second-level judgment fails to determine the data type, parsing the semantic characteristics of the input data and performing a third-level type judgment based on the vocabulary and semantic patterns of specific domains in the input data; if the third-level judgment fails to determine the data type, the input data is classified as a general data type; when the input data is non-text content, it is classified as a multimodal data type.
[0011] In one example, the query keyword set is matched with the keyword set in the RAG knowledge base to obtain the search results. Specifically, this includes: calculating the number of exact matches and the number of fuzzy matches between the query keyword set and the keyword set, and calculating the total matching score according to a preset weight; and retrieving the data slice with the highest relevance and the data links associated with the data slice based on the total matching score.
[0012] In one example, the number of exact matches and fuzzy matches between the query keyword set and the keyword set are calculated, and the total matching score is calculated according to a preset weight. Specifically, this includes: calculating the number of complete overlaps between query keywords and determining the number of complete overlaps as the number of exact matches; calculating the cosine similarity between query keywords and determining the number of keywords with a cosine similarity greater than a preset similarity as the number of fuzzy matches; and weighting the number of exact matches and the number of fuzzy matches according to the preset weight to obtain the total matching score.
[0013] On the other hand, embodiments of this application provide a RAG knowledge base construction device, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform any of the above-mentioned RAG knowledge base construction methods.
[0014] On the other hand, embodiments of this application provide a non-volatile computer storage medium for constructing a RAG knowledge base, which stores computer-executable instructions that can execute any of the above-mentioned methods for constructing a RAG knowledge base.
[0015] The above-described technical solutions adopted in the embodiments of this application can achieve the following beneficial effects: This application effectively solves the semantic fragmentation problem caused by traditional fixed segmentation by introducing a multi-level priority judgment and type adaptation intelligent segmentation method, significantly improving the integrity and logical relevance of knowledge units. By constructing a multimodal data fusion management mechanism, it achieves unified parsing and associated storage of non-text data such as voice and video, breaking through the text limitations of traditional RAG systems and greatly expanding the coverage and application scenarios of the knowledge base. Through a large-model-driven dual-end keyword generation and matching mechanism, combined with user-configurable prompt word strategies, it significantly improves retrieval accuracy, effectively reduces noise interference, and enhances the accuracy and relevance of the system response. Through a privately deployed multimodal parsing link and hybrid storage architecture, it achieves efficient management and retrieval of heterogeneous resources while ensuring data security and privacy, achieving an organic balance between security and processing efficiency. Attached Figure Description
[0016] To more clearly illustrate the technical solution of this application, some embodiments of this application will be described in detail below with reference to the accompanying drawings, in which: Figure 1 A flowchart illustrating a method for constructing a RAG knowledge base, as provided in an embodiment of this application; Figure 2 This is a schematic diagram of the structure of a RAG knowledge base construction device provided in an embodiment of this application. Detailed Implementation
[0017] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0018] Some embodiments of this application will now be described in detail with reference to the accompanying drawings.
[0019] Figure 1 This is a flowchart illustrating a method for constructing a RAG knowledge base, as provided in an embodiment of this application. This method can be applied to different business domains. Certain input parameters or intermediate results in this process can be manually adjusted to help improve accuracy.
[0020] The analysis method involved in the embodiments of this application can be implemented by a terminal device or a server, and this application does not impose any special limitations on it. For ease of understanding and description, the following embodiments are all described in detail using a server as an example.
[0021] Based on this Figure 1 The process may include the following steps: S101: The data type of the input data is determined by performing logical judgment on the format features, structural features, and semantic features of the input data through multi-level priority judgment logic; the data type is one of question-and-answer pairs, resumes, tables, papers, books, legal provisions, PPTs, general data, or multimodal data.
[0022] In some embodiments of this application, the input data is first subjected to multi-dimensional feature extraction and hierarchical judgment. In the format feature extraction stage, the file extension (such as .csv, .pptx, .tex) and file header metadata are parsed to identify whether there are table column structures, slide page identifiers, or LaTeX formula marks.
[0023] For data with clear format identifiers, such as CSV files with a question-answer dual-column structure, they are directly classified as question-answer pair data; PPT files with slide pagination marks are classified as PPT data.
[0024] If format features cannot uniquely determine the type, the system proceeds to the structural feature analysis stage. The system uses a document structure parser to perform hierarchical analysis of the content, identifying structural features such as heading levels (e.g., Section 1.1 of Chapter X), clause numbers (e.g., Article X), and table borders. For example, if a continuous clause number structure is detected and no other type features are found, it is classified as legal text data.
[0025] When format and structural features are insufficient for classification, semantic feature analysis is initiated. The system calls a lightweight semantic model to annotate text fragments and extract domain-specific vocabulary (such as work experience and project experience in a resume, and abstracts and references in a paper). By calculating the matching degree between the extracted vocabulary and a preset semantic template, type recognition is achieved. For example, when the matching degree of keywords such as educational background and skills exceeds a set threshold, it is determined to be resume data.
[0026] Furthermore, it should be noted that a conflict arbitration mechanism is adopted. When the results of multi-feature judgments are inconsistent, the final type is determined according to the priority of format > structure > semantics. All unclassifiable data is uniformly marked as a general data type, and non-text data (such as audio and video) is marked as multimodal data.
[0027] By introducing a multi-level priority judgment and type adaptation intelligent segmentation method, the semantic fragmentation problem caused by traditional fixed segmentation is effectively solved, and the integrity and logical relevance of knowledge units are significantly improved.
[0028] S102: Based on the data type, a preset segmentation strategy is invoked to segment the input data and generate data slices; the data slices are labeled with slice identifiers and metadata.
[0029] In some embodiments of this application, the corresponding processing logic is called from the segmentation strategy library according to the identified data type. For question-answer pair data, if it is in a structured format, the question and answer text is extracted line by line, encapsulated into independent slices, and a question-answer pair-line number identifier is attached; if it is unstructured text, the semantic segmentation model is used to identify start and end markers such as "question:" and "answer:" to ensure the semantic integrity of each question-answer pair.
[0030] When processing resume data, a combination of named entity recognition and semantic clustering is used to locate the boundaries of modules such as education background and work experience. For content containing multiple experiences, sub-segments are performed in chronological order, and the relationships between modules are recorded in the metadata.
[0031] For tabular data, the table recognition model is called to parse the row and column structure and merged cells, and then convert it into standard JSON format. The table is dynamically divided into slices based on the number of rows. When the number of rows exceeds a set limit, an overlapping slicing strategy is used to preserve the row and column relationships between adjacent slices.
[0032] For legal text data, Article X is used as the basic segmentation unit. A hierarchical structure of main article-sub-sub-item is established for articles that include multiple clauses and items. The citation relationship between clauses is identified through semantic parsing, and a dependency graph is constructed in the metadata.
[0033] For the paper data, the main sections are divided according to the academic chapter structure, including abstract, introduction, methodology, experimental results, discussion, conclusion, and references. Mathematical formulas are accurately extracted using a LaTeX parser and encapsulated into formula-context sub-slices along with formula numbers and context descriptions. Related statements for figures and tables are identified, and a mapping relationship is established between figure and table titles, numbers, and text descriptions, forming independent figure and table slices. Long chapters are split according to section boundaries, maintaining overlap between adjacent sub-slices.
[0034] For book data, chapter boundaries are identified based on title level features, with first-level identifiers such as Chapter X serving as the main segmentation nodes. Large blocks of content are supported; chapters not exceeding a certain token count threshold are treated as slices, while those exceeding the threshold are split into sections, ensuring that the splits meet the principles of sentence integrity and logical coherence.
[0035] For PPT data, each slide is used as the smallest segment unit, generating an independent slice for each page and adding a PPT name-page number identifier. The titles, body text, charts, formulas, and other elements within each page are structurally integrated, with the title serving as the slice title, and body paragraphs linked to charts and formulas. For scanned PPTs, the OCR engine is first used to extract the text content, followed by element integration and segmentation.
[0036] For general data, a sliding window mechanism is used for segmentation, supporting user-preset token quantity thresholds. The window step size is set to 50% of the threshold to ensure that adjacent slices retain 50% content overlap, and the overlapping area must contain a complete sentence. For extremely long paragraphs in the text, the threshold is automatically and temporarily increased to prevent the core semantics of the paragraph from being fragmented.
[0037] When the data type is multimodal data, the preset private multimodal large model is invoked, and the input data is asynchronously parsed according to the preset prompt word template to generate text descriptions; then the text descriptions are bound to the input data through a unique resource ID to form data description slices.
[0038] All generated data slices contain metadata such as unique identifiers, data types, segmentation strategy versions, and original location information, providing a complete context for subsequent processing.
[0039] By constructing a multimodal data fusion management mechanism, unified parsing and associated storage of non-text data such as voice and video have been achieved, breaking through the text limitations of traditional RAG systems and greatly expanding the coverage and application scenarios of the knowledge base.
[0040] S103: Invoke the large language model and generate keywords asynchronously for each data slice according to the preset prompt word configuration to obtain a keyword set; the keyword set includes the link of each data slice identifier.
[0041] In some embodiments of this application, an independent keyword generation task is created for each data slice, and an asynchronous scheduling mechanism is used to improve processing efficiency. The task scheduler assigns priorities based on the slice type, with core chapters or high-value data being processed first.
[0042] The system has a built-in library of prompt word templates for various scenarios. For example, general templates guide the model to extract keywords and proper nouns, while legal professional templates require the extraction of rights and obligations subjects, types of liability, etc. Users can customize extraction parameters through a visual interface, including the number of keywords, semantic bias, and professional field preferences.
[0043] The large language model receives data slice content and configured prompt words, and outputs a list of raw keywords. The system performs post-processing on the output: first, it deduplicates based on semantic vectors, merging words that are similar in expression but different in literal meaning; then, it calculates the semantic relevance of each keyword to the slice content, filtering out noisy words below a threshold.
[0044] Furthermore, the subset of keywords that pass quality verification is bound to the unique identifier of the corresponding slice and stored in the keyword set. The system supports an incremental update mechanism, so that when the knowledge base content changes, keywords are only regenerated for the affected slices, avoiding full duplication processing.
[0045] By leveraging a large-model-driven dual-end keyword generation and matching mechanism, combined with user-configurable suggestion strategies, the system significantly improves retrieval accuracy, effectively reduces noise interference, and enhances the accuracy and relevance of system responses.
[0046] S104: Based on the mixed storage mode of structured metadata and unstructured raw data, each data slice and its corresponding resource links and keyword set are stored to generate the RAG knowledge base.
[0047] In some embodiments of this application, knowledge base resources are managed through a hybrid storage architecture. First, the resource links corresponding to each data slice, as well as the structured metadata of the keyword set, are extracted. The metadata includes a unique slice identifier, data type, generation time, associated resource link identifier, keyword set association identifier, and source data identifier.
[0048] Furthermore, the unstructured raw data undergoes format standardization conversion and integrity verification; the unstructured raw data includes the original data slices, multimodal resource files, and copies of the original data.
[0049] Furthermore, the unique identifier of each slice is bound to the original storage path of the data slice, the storage path of the multimodal resource file, and the storage address of the keyword set to establish an association index between structured metadata and unstructured raw data. The extracted structured metadata is stored in a relational database, while the unstructured raw data, after integrity verification, is stored in a distributed file system.
[0050] Furthermore, by randomly selecting unique slice identifiers, the storage paths recorded in the metadata are checked to ensure they accurately point to the corresponding unstructured data, thus verifying the correlation between the stored structured metadata and the original unstructured data. After successful verification, the metadata indexes in the relational database and resources in the distributed file system are integrated to obtain the RAG knowledge base, and the generation time and version identifier of the RAG knowledge base are recorded.
[0051] By using a privately deployed multimodal parsing link and hybrid storage architecture, efficient management and retrieval of heterogeneous resources are achieved while ensuring data security and privacy, thus achieving an organic balance between security and processing efficiency.
[0052] S105: Receives user query requests and, based on the same preset prompt word configuration, calls the large language model to generate a set of query keywords.
[0053] In some embodiments of this application, when a user submits a query request, the system loads a prompt word configuration that is completely consistent with the knowledge base construction phase, ensuring that the keyword generation logic on the query side and the document side is consistent. For example, if the document slice uses a legal professional template to generate keywords, then the user query also uses the same template to extract query keywords.
[0054] The system preprocesses the query statements, including removing stop words, correcting spelling errors, and standardizing terminology. The purified query content is then combined with suggestion words and input into the large language model. After the model outputs a set of query keywords, the system performs the same post-processing procedures as for document keywords, including semantic deduplication and quality filtering, to form a standardized set of query keywords.
[0055] S106: Match the set of query keywords with the set of keywords in the RAG knowledge base to obtain the search results.
[0056] In some embodiments of this application, the system employs a multi-strategy fusion matching algorithm to calculate the similarity between query and document keywords. The exact matching module counts the number of completely identical keywords; the fuzzy matching module calculates cosine similarity based on pre-trained word vectors and counts similar keyword pairs that exceed a set threshold.
[0057] The matching score is calculated using a weighted summation method:
[0058] The system dynamically adjusts weight parameters based on business scenarios. For example, legal searches prioritize precise matching, while creative writing scenarios can increase the weight of fuzzy matching.
[0059] The search results are sorted in descending order of matching score, and then further sorted by semantic similarity score from the vector retrieval model. Finally, the top N most relevant results are returned. Each result includes a data slice, a list of matching keywords, matching score details, and links to related multimodal resources, providing rich contextual information for the generation module.
[0060] It should be noted that, although the embodiments in this application are based on... Figure 1 Steps S101 to S106 will be described sequentially, but this does not mean that steps S101 and S106 must be performed in a strict order. The reason this embodiment follows this order is... Figure 1 The order in which steps S101 to S106 are described is provided to facilitate understanding of the technical solutions of the embodiments of this application by those skilled in the art. In other words, in the embodiments of this application, the order of steps S101 to S106 can be appropriately adjusted according to actual needs.
[0061] pass Figure 1 This application, by introducing a multi-level priority judgment and type-adaptive intelligent segmentation method, effectively solves the semantic fragmentation problem caused by traditional fixed segmentation, significantly improving the integrity and logical relevance of knowledge units. By constructing a multimodal data fusion management mechanism, it achieves unified parsing and associated storage of non-text data such as voice and video, breaking through the text limitations of traditional RAG systems and greatly expanding the coverage and application scenarios of the knowledge base. Through a large-model-driven dual-end keyword generation and matching mechanism, combined with user-configurable prompt word strategies, it significantly improves retrieval accuracy, effectively reduces noise interference, and enhances the accuracy and relevance of system response. Through a privately deployed multimodal parsing link and hybrid storage architecture, it achieves efficient management and retrieval of heterogeneous resources while ensuring data security and privacy, achieving an organic balance between security and processing efficiency.
[0062] Figure 2 A schematic diagram of a RAG knowledge base construction device provided in this application embodiment includes: At least one processor; and, A memory that is communicatively connected to at least one processor; wherein, A method for constructing a RAG knowledge base, wherein the memory stores instructions that can be executed by at least one processor, and the instructions are executed by at least one processor to enable at least one processor to perform any of the above.
[0063] Some embodiments of this application provide a non-volatile computer storage medium for constructing a RAG knowledge base, which stores computer-executable instructions that can execute any of the above-described RAG knowledge base construction methods.
[0064] The various embodiments in this application are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device and medium embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the description of the method embodiments.
[0065] The devices and media provided in this application are one-to-one with the methods. Therefore, the devices and media also have similar beneficial technical effects as their corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the devices and media will not be repeated here.
[0066] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0067] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0068] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1The function specified in one or more boxes.
[0069] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0070] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0071] Memory may include non-persistent storage in computer-readable media, random access memory (RAM), and non-volatile memory such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0072] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0073] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0074] The above are merely embodiments of this application and are not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the technical principles of this application should fall within the protection scope of this application.
Claims
1. A method for constructing a RAG knowledge base, characterized in that, The method includes: The data type of the input data is determined by logically judging the format features, structural features, and semantic features of the input data through a multi-level priority judgment logic; the data type is one of the following: question-answer pairs, resumes, tables, papers, books, legal provisions, PPTs, general data, or multimodal data; Based on the data type, a preset segmentation strategy is invoked to segment the input data and generate data slices; each data slice carries a slice identifier and metadata. The large language model is invoked, and keywords are generated asynchronously for each data slice according to the preset prompt word configuration to obtain a keyword set; the keyword set includes the link that identifies each data slice; Based on the mixed storage mode of structured metadata and unstructured raw data, each data slice and its corresponding resource links and keyword set are stored to generate the RAG knowledge base; Receive user query requests, and based on the same preset prompt word configuration, call the large language model to generate a set of query keywords; The search results are obtained by matching the set of query keywords with the set of keywords in the RAG knowledge base.
2. The method according to claim 1, characterized in that, The step of segmenting the input data according to the data type by invoking a preset segmentation strategy to generate data slices specifically includes: When the data type is non-multimodal data, a preset segmentation logic library is matched according to the data type, and the corresponding segmentation strategy in the segmentation logic library is called to segment the input data and generate data slices. When the data type is multimodal data, the preset private multimodal large model is invoked, and the input data is asynchronously parsed according to the preset prompt word template to generate text description; The text description is bound to the input data using a unique resource ID to form a data description slice.
3. The method according to claim 2, characterized in that, When the data type is non-multimodal data, a preset segmentation logic library is matched according to the data type, and the corresponding segmentation strategy in the segmentation logic library is called to segment the input data to generate data slices, specifically including: When the data type is a question-answer pair, for structured question-answer pairs, each pair of questions and answers is processed as an independent data slice. For unstructured question-and-answer pairs, by identifying the question start identifier and the response start identifier, the semantically related question and answer content is encapsulated into an independent single data slice; When the data type is a resume, the resume content is divided into modules and segmented, with each resume content module being an independent data slice. When the data type is legal provisions, the legal provisions are segmented according to the clause number and hierarchical relationship; When the data type is a table, segmentation is performed according to the table row and column association logic; When the data type is a paper, it is segmented according to the academic chapters, and formulas, charts and graphs are bound to the corresponding text content. When the data type is PPT, the PPT is segmented into segments, with each slide as an independent segment unit. When the data type is "book", the book is segmented according to the first-level chapter identifier; When the data type is general data, the general data is split according to the user-preset token threshold and a sliding window overlap strategy.
4. The method according to claim 1, characterized in that, The process of calling the large language model involves asynchronously generating keywords for each data slice based on a preset prompt word configuration, resulting in a keyword set. Specifically, this includes: Based on the data type of the data slice, load the corresponding preset prompt word configuration; the prompt word configuration includes multiple templates predefined by the system or custom instructions provided by the user through the configuration interface; Create a corresponding keyword generation task for each data slice and add the keyword generation task to the asynchronous task queue; Input each data slice and its corresponding prompt word configuration into the large language model to generate a keyword list for each data slice; The keyword list is semantically deduplicated, and the relevance between the deduplicated keywords and the data slices is verified. When the relevance is greater than a preset relevance threshold, the keyword list is determined as a subset of keywords for the data slice; The keyword subsets corresponding to each data slice are summarized to obtain the keyword set.
5. The method according to claim 1, characterized in that, The method of storing each data slice and its corresponding resource links and keyword sets according to the hybrid storage mode of structured metadata and unstructured raw data to generate a RAG knowledge base specifically includes: Extract the resource links corresponding to each data slice, as well as the structured metadata of the keyword set; the metadata includes the slice's unique identifier, data type, generation time, associated resource link identifier, keyword set association identifier, and source data identifier; The unstructured raw data undergoes format standardization and integrity verification; the unstructured raw data includes original data slices, multimodal resource files, and copies of the original data. The unique identifier of the slice is bound to the storage path of the original data slice, the storage path of the multimodal resource file, and the storage address of the keyword set to establish an association index between structured metadata and unstructured raw data. The extracted structured metadata is stored in a relational database, while the unstructured raw data after integrity verification is stored in a distributed file system. By randomly selecting the unique identifier of the slice, we check whether the storage path recorded in the metadata accurately points to the corresponding unstructured data, so as to verify the correlation between the stored structured metadata and the unstructured original data. After successful verification, the metadata index in the relational database and the resources in the distributed file system are integrated to obtain the RAG knowledge base, and the generation time and version identifier of the RAG knowledge base are recorded.
6. The method according to claim 1, characterized in that, The step of using multi-level priority judgment logic to logically judge the format features, structural features, and semantic features of the input data to determine the data type of the input data specifically includes: The format identifier information of the input data is identified, and the first-level type is determined based on the file extension and file structure identifier; If the first-level judgment fails to determine the data type, a second-level type judgment is performed based on the document hierarchy and specific paragraph marks. If the second-level judgment fails to determine the data type, the semantic features of the input data are analyzed, and a third-level type judgment is made based on the vocabulary and semantic patterns of the specific domain in the input data. If the third-level judgment fails to determine the data type, the input data will be classified as a general data type; When the input data is non-text content, the input data will be classified as a multimodal data type.
7. The method according to claim 1, characterized in that, The step of matching the query keyword set with the keyword set in the RAG knowledge base to obtain the search results specifically includes: Calculate the number of exact matches and fuzzy matches between the query keyword set and the keyword set, and calculate the total matching score based on preset weights; Based on the total matching score, the data slice with the highest relevance and the data links associated with the data slice are retrieved.
8. The method according to claim 7, characterized in that, The calculation of the number of exact matches and fuzzy matches between the query keyword set and the keyword set, and the calculation of the total matching score according to the preset weights, specifically includes: Calculate the number of complete overlaps between query keywords and keywords, and determine the number of complete overlaps as the number of exact matches; Calculate the cosine similarity between query keywords and keywords, and determine the number of keywords with a cosine similarity greater than a preset similarity as the number of fuzzy matches; Based on preset weights, the number of exact matches and the number of fuzzy matches are weighted and calculated to obtain the total matching score.
9. A RAG knowledge base construction device, characterized in that, include: At least one processor; as well as, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform a RAG knowledge base construction method according to any one of claims 1-8.
10. A RAG knowledge base construction storage medium, storing computer-executable instructions, characterized in that, The computer-executable instructions are capable of executing the RAG knowledge base construction method according to any one of claims 1-8.
Citation Information
Patent Citations
Multi-source and multi-mode fused knowledge reasoning method, system and device and medium
CN119005340A
Method and system for constructing intelligent customer service interaction based on big language model RAG framework
CN119129739A
RAG knowledge base construction method based on layout analysis and query generation
CN119441507A
Cited By
Power line loss analysis data set construction method, device and equipment based on large model
CN121808400A
Method, device and equipment for constructing power line loss analysis dataset based on large model
CN121808400B