Fusion retrieval method and device for graph data and vector data, equipment and medium
By vectorizing user query text and combining vector and graph database queries, the problem of inaccurate search of large language models in graph databases is solved, and more efficient query and answers are achieved.
Patent Information
- Application Number
- CN202510625462.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-15
- Publication Date
- 2025-08-05
AI Technical Summary
When searching large language models in graph databases, there are problems such as insufficient knowledge retrieval and lack of context, resulting in inaccurate answers.
Vectorization is performed by receiving user query text, querying target file blocks using vector database, and conducting context query in the graph database, and combining large language models to generate accurate query results.
It improves the accuracy and effectiveness of query, reduces dependence on computing power, and improves the answer efficiency and accuracy of large language models.
Smart Images

Figure CN120429477A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of large language models, and in particular to a method, apparatus, device and medium for fusion retrieval of graph data and vector data. Background Art
[0002] The large language model possesses certain logical thinking and reasoning capabilities, enabling it to understand the meaning of user text and generate natural language text. This natural language text generation relies on the data provided by its graph and vector databases. When a user issues a query to the large language model, the model provides a textual response based on the data in these databases. In existing technologies, when large language models query data in graph and vector databases, they often generate corresponding graph query statements based on the query text and perform data queries within the graph database. However, these queries often suffer from incomplete knowledge retrieval and a lack of context, resulting in inaccurate responses and a poor user experience. Summary of the Invention
[0003] The present invention provides a method, apparatus, device and medium for fusion retrieval of graph data and vector data to solve the technical problem in the prior art that large language models cannot retrieve accurate and effective data in graph databases.
[0004] According to one aspect of the present invention, a method for fusion retrieval of graph data and vector data is provided, comprising:
[0005] receiving a user's query text for the large language model, vectorizing the query text to determine a query vector;
[0006] Performing a data query in a preset vector database according to the query vector to determine a target file block;
[0007] Performing a context query in a preset graph database according to the target file block to determine a target context;
[0008] The target context is input into the large language model to obtain a target query result output by the large language model.
[0009] According to another aspect of the present invention, a fusion retrieval device for graph data and vector data is provided, comprising:
[0010] A query response module, configured to receive a user's query text for the large language model, vectorize the query text, and determine a query vector;
[0011] A vector query module, configured to perform a data query in a preset vector database according to the query vector to determine a target file block;
[0012] A graph data module, configured to perform a context query in a preset graph database according to the target file block to determine a target context;
[0013] The data processing module is used to input the target context into the large language model to obtain the target query result output by the large language model.
[0014] According to another aspect of the present invention, an electronic device is provided, comprising:
[0015] at least one processor; and
[0016] a memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the fusion retrieval method of graph data and vector data described in any embodiment of the present invention.
[0018] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the fusion retrieval method of graph data and vector data described in any embodiment of the present invention when executed.
[0019] The technical solution of the embodiment of the present invention receives a user's query text for a large language model, vectorizes the query text, and determines a query vector. The vectorized query text can capture the semantic information of the query text and improve the effectiveness of the query; performs a data query in a preset vector database based on the query vector to determine the target file block, and matches the target file block corresponding to the query text through similarity matching between vectors, which can effectively improve the accuracy of the query; performs a context query in a preset graph database based on the target file block to determine the target context. The target context provides accurate data and can cover multi-dimensional data, improving the accuracy and effectiveness of the answer to the query text, and can also improve the reasoning ability of the large language model and the answer efficiency of the large language model; the target context is input into the large language model to obtain the target query result output by the large language model. This solves the technical problem in the prior art that large language models cannot retrieve accurate and valid data in graph databases, can ensure the effectiveness and accuracy of the retrieved content, reduce the time for large language models to retrieve data, improve the answer efficiency of large language models, and effectively reduce the dependence on computing power, thereby improving the answer performance of large language models.
[0020] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 A flowchart of a method for fusion retrieval of graph data and vector data is provided for an embodiment of the present invention;
[0023] Figure 2 A flowchart of another method for fusion retrieval of graph data and vector data provided by an embodiment of the present invention;
[0024] Figure 3 A schematic diagram of a process for storing original documents provided for the implementation of the present invention;
[0025] Figure 4 A schematic diagram of a process for retrieving data using a large language model provided for the implementation of the present invention;
[0026] Figure 5 A schematic diagram of the structure of a fusion retrieval device for graph data and vector data provided by an embodiment of the present invention;
[0027] Figure 6 A schematic structural diagram of an electronic device that can be used to implement an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0028] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0029] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0030] Figure 1 The present invention provides a flowchart of a method for fusion retrieval of graph data and vector data. This embodiment is applicable to situations where a user asks a question to a large language model and the large language model needs to retrieve data from a graph database. The method can be executed by a fusion retrieval device for graph data and vector data. The fusion retrieval device for graph data and vector data can be implemented in the form of hardware and / or software and can be configured in an electronic device. Figure 1 As shown, the method includes:
[0031] S110 : Receive a user's query text for a large language model, vectorize the query text, and determine a query vector.
[0032] The large language model can be a natural speech processing model pre-trained based on massive amounts of text data. It should be noted that the large language model can communicate with users through online text, understand text sent to it, and generate corresponding text responses.
[0033] Optionally, the training process of the large language model can be: collecting massive text data, performing pre-processing operations on the massive text data such as deduplication, denoising, and clearing irrelevant and erroneous data to obtain training data, pre-training and fine-tuning the constructed natural language processing model through the training data, and setting up reinforcement learning for feedback collection, reward modeling, and strategy optimization to obtain a trained large language model.
[0034] The query text can be the text that the user enters into the large language model for query purposes. It should be noted that the large language model can automatically understand and recognize the text entered by the user, and use the text used by the user to query data as the query text. For example, a user enters "Please play the role of a legal practitioner and explain the history of patent law to me" in the dialogue page provided by the large language model, and "Explain the history of patent law" is used as the user's query text.
[0035] The query vector may be a query text represented in the form of a vector. It should be noted that, in the embodiment of the present invention, after the query text is recognized by the large language model, the query text may be vectorized to obtain a query vector.
[0036] Optionally, embodiments of the present invention may employ any vectorization method to vectorize the query text, which is not limited by the present invention. Exemplary vectorization methods include a bag-of-words model, a large language model using an API (Application Programming Interface) for vectorization, and an embedding model.
[0037] Specifically, the user inputs a query text into the large language model, which receives the user's query text, vectorizes the query text, and determines a query vector.
[0038] S120 : Performing data query in a preset vector database according to the query vector to determine a target file block.
[0039] The vector database may be a pre-established database for storing vector data.
[0040] The target file block can be a file statement in the vector database that matches the query vector. It should be noted that the target file block is a file block obtained by segmenting a complete file, includes at least one complete text statement in the file block, and is stored in the vector database.
[0041] Specifically, the query vector is input into a preset vector database, data matching is performed in the vector database, and a target file block matching the query vector is determined.
[0042] Optionally, in an embodiment of the present invention, when inputting the query vector into a preset vector database for data matching, multiple file blocks may be matched, and the file block with the highest matching similarity may be selected as the target file block.
[0043] S130: Perform a context query in a preset graph database according to the target file block to determine a target context.
[0044] The graph database may be a pre-established database for storing graph data.
[0045] The target context can be the entities and relationships that match the target file block in the graph database. It should be noted that if there is at least one entity and relationship in the target file block, the target context is obtained by matching the entities and relationships in the graph database using the entities and edges to obtain entities and relationships that match the entities and relationships corresponding to the target file block.
[0046] Specifically, a context query is performed in a preset graph database based on the target file block to determine the target context.
[0047] S140: Input the target context into a large language model to obtain a target query result output by the large language model.
[0048] The target query result can be the answer generated by the large language model based on the target context. It should be noted that after the target context is obtained through the query, the target context is returned to the large language model, which then generates text based on the target context to obtain the target query result corresponding to the query text.
[0049] Specifically, the target context is input into the large language model to obtain the target query result output by the large language model.
[0050] The technical solution of the embodiment of the present invention receives a user's query text for a large language model, vectorizes the query text, and determines a query vector. The vectorized query text can capture the semantic information of the query text and improve the effectiveness of the query; performs a data query in a preset vector database based on the query vector to determine the target file block, and matches the target file block corresponding to the query text through similarity matching between vectors, which can effectively improve the accuracy of the query; performs a context query in a preset graph database based on the target file block to determine the target context. The target context provides accurate data and can cover multi-dimensional data, improving the accuracy and effectiveness of the answer to the query text, and can also improve the reasoning ability of the large language model and the answer efficiency of the large language model; the target context is input into the large language model to obtain the target query result output by the large language model. This solves the technical problem in the prior art that large language models cannot retrieve accurate and valid data in graph databases, can ensure the effectiveness and accuracy of the retrieved content, reduce the time for large language models to retrieve data, improve the answer efficiency of large language models, and effectively reduce the dependence on computing power, thereby improving the answer performance of large language models.
[0051] Preferably, in another embodiment of the present invention, performing a data query in a preset vector database according to the query vector to determine the target file block includes:
[0052] Perform vector matching in the vector database according to the query vector to determine a matching target data vector; and obtain the target file block according to the target data vector.
[0053] The target data vector can be a vector in the vector database that matches the target query document; the textual semantic information expressed by the target data vector matches the query text. It should be noted that the query vector is sent to the vector database, and similarity matching is performed between the query vector and the vector data in the vector database to obtain the similarity matching degree between the query vector and each vector data. The vector data with the highest similarity is selected as the target data vector.
[0054] Optionally, in a vector database, vector data and file blocks are stored correspondingly. After the target data vector is obtained through query, the target file block is obtained from the vector database based on the target data vector.
[0055] Specifically, vector matching is performed in a vector database according to the query vector to determine a matching target data vector; and a target file block is obtained according to the target data vector.
[0056] Preferably, in another embodiment of the present invention, performing a context query in a preset graph database according to the target file block to determine the target context includes:
[0057] Performing a data query in the data graph of the graph database according to the target file block to determine at least one data vertex and a vertex-edge relationship between the data vertex;
[0058] A context query is performed based on each of the data vertices and the vertex-edge relationship between each of the data vertices to determine the target context.
[0059] Among them, data vertices can be points corresponding to entities in the data graph of the graph database; vertex-edge relationships can be relationships between entities in the data graph of the graph database.
[0060] Optionally, identify at least one entity and relationship corresponding to the target file block, perform data query in the data graph of the graph database based on the entity and relationship corresponding to the target file block, and query the entity and relationship corresponding to the target file block in at least one data vertex and vertex-edge relationship between the data vertices in the data graph of the graph database.
[0061] Optionally, after obtaining at least one data vertex and vertex-edge relationship between data vertices corresponding to the target file block, a context query is performed in the graph database based on the vertex-edge relationship between the data vertex and the data vertex to determine the target context in the graph database that matches the vertex-edge relationship between the data vertex and the data vertex.
[0062] Specifically, a data query is performed in the data graph of the graph database based on the target file block to determine at least one data vertex and the vertex-edge relationship between the data vertices; a context query is performed based on the vertex-edge relationship between each data vertex and each data vertex to determine the target context.
[0063] Preferably, in an optional embodiment of the present invention, performing a context query based on each of the data vertices and the vertex-edge relationship between each of the data vertices to determine the target context includes:
[0064] For each of the data vertices, the vertex-edge relationship of the data vertex is expanded through the graph database to determine at least one neighbor vertex and the vertex-edge relationship of the neighbor vertex; context is sorted according to each of the data vertices, the vertex-edge relationship of each of the data vertices, each of the neighbor vertices and the vertex-edge relationship of each of the neighbor vertices to determine the target context.
[0065] Among them, neighbor vertices can be data vertices adjacent to the data vertex in the graph database. It should be noted that, corresponding to each data vertex, the data vertices corresponding to each vertex-edge relationship of the data vertex are queried in the graph database, and each data vertex corresponding to the vertex-edge relationship is used as a first-level neighbor vertex of the data vertex. After obtaining each first-level neighbor vertices of the data vertex, the vertex-edge relationship of each first-level neighbor vertex is obtained, and based on the vertex-edge relationship of each first-level neighbor vertex, the neighbor vertices of each first-level neighbor vertex are queried, and the neighbor vertices of each first-level neighbor vertex are used as each second-level neighbor vertices of the data vertex. The first-level neighbor vertices and second-level neighbor vertices of the data vertex are used as neighbor vertices of the data vertex, and the vertex-edge relationship of each neighbor vertex is obtained.
[0066] Optionally, when searching for neighbor vertices of a data vertex, a breadth-first search or a depth-first search may be selected, which is not limited in the present invention.
[0067] Optionally, in an embodiment of the present invention, the search for data vertices in graph data neighbor nodes is set to extend to two layers, and the first-layer neighbor vertices and the second-layer neighbor vertices of the data vertex are used as the context of the data vertex. Each of the data vertices, the vertex-edge relationship of each of the data vertices, and each of the neighbor vertices and the vertex-edge relationship of each of the neighbor vertices are subjected to certain reordering and merging operations to achieve context organization and determine the target context.
[0068] Optionally, after obtaining the neighbor vertices of a data vertex and before context organization, the correlation between each neighbor node and the data vertex can be identified, and neighbor nodes with low correlation to the data vertex can be filtered out, while retaining neighbor vertices with high correlation. The retained neighbor vertices can then be deduplicated. Based on the correlation between the neighbor nodes and the data vertex, reordering and merging operations can be performed to establish the target context. Optionally, the target context can be displayed in the form of a data graph subgraph, community, etc.
[0069] Specifically, for each data vertex, the vertex-edge relationship of the data vertex is expanded through the graph database to determine at least one neighbor vertex and the vertex-edge relationship of the neighbor vertex; context is sorted according to each data vertex, the vertex-edge relationship of each data vertex, and the vertex-edge relationship of each neighbor vertex to determine the target context.
[0070] Figure 2 This is a flowchart of another method for fusion retrieval of graph data and vector data provided by an embodiment of the present invention. The relationship between this embodiment and the above embodiment is the specific process of constructing a vector database and a graph database before the user sends a query text to the large language model. Figure 2 As shown, the method includes:
[0071] S210: Acquire an original document, perform document parsing and document slicing on the original document, and obtain at least one file block.
[0072] The original document may be a complete document with coherent semantic logic. It should be noted that the original document covers documents in multiple different fields and with different contents, and the contents of the original document are authentic.
[0073] Optionally, when parsing the original document, it is prioritized to identify whether the original document has a directory structure. If a directory structure exists, each chapter and each chapter paragraph is extracted based on the directory structure, and a mapping relationship between chapters and chapter paragraphs is established. If a directory structure does not exist, the semantics of the original document is understood, and segmentation processing is performed based on the semantics and document symbols to achieve parsing of the original document.
[0074] Optionally, if the original document contains images, the image information can be recognized through a large language model or by calling an optical character recognition interface to extract the text in the image and perform document parsing on the text.
[0075] Optionally, after parsing the original document, the original document may be segmented based on pre-set segmentation rules or semantic information to obtain file chunks. The pre-set segmentation rules may be based on character segmentation, file chunk size, or a fixed number of characters, and the present invention is not limited thereto.
[0076] Specifically, an original document is obtained, and document parsing and document slicing are performed on the original document to obtain at least one file block.
[0077] S220: Establish a vector database based on all the file blocks.
[0078] Specifically, a vector database storing the original document is established based on the text in the file block.
[0079] Optionally, in another optional embodiment of the present invention, establishing a vector database based on all the file blocks includes:
[0080] For each of the file blocks, text vectorization is performed on the file block to determine a data vector corresponding to the file block; and each of the data vectors and the file block corresponding to each of the data vectors are stored in the vector database.
[0081] Optionally, when performing text vectorization on a file block, entities and relationships between entities in each file block are identified, and the text in the file block is vectorized in the form of entities and relationships to obtain a data vector corresponding to the file block.
[0082] Optionally, when storing in the vector database, the file blocks are vectorized at the same time, the file blocks are associated with the data vectors, and an index is established in the vector database. The file blocks and data vectors are stored correspondingly in the vector database, so that after the data vectors are found, the file blocks can be found synchronously.
[0083] Specifically, for each file block, the text of the file block is vectorized to determine the data vector corresponding to the file block; each data vector and the file block corresponding to each data vector are stored in a vector database.
[0084] S230: Establish a graph database based on all the file blocks.
[0085] Specifically, a graph database storing original documents is established based on the text in the file blocks.
[0086] Optionally, in another optional embodiment of the present invention, establishing a graph database based on all the file blocks includes:
[0087] For each of the file blocks, entities and relationships are extracted from the file block using a preset large language model to determine the relationship between at least one entity and each entity; a knowledge graph is constructed based on each entity and the relationship between each entity, and each of the file blocks is stored in the graph database.
[0088] Optionally, after obtaining the file block, for each file block, clarify the field corresponding to the file block, define the graph schema of the data graph, determine the naming convention and semantic definition of the data graph, use the preset large language model to extract entities and relationships from the content of the file block according to the graph schema, identify the entities and relationships between entities in the file block, extract the metadata of the file block, establish corresponding nodes for the file block, and establish relationships between the file block and the entities corresponding to the file block.
[0089] Optionally, after extracting the entities and the relationships between entities in each file block, based on the graph schema, the entities and the relationships between entities in each file block are integrated into the graph, the relationships between entities are established, a data graph is formed, and each file block is stored in the graph database.
[0090] S240: Receive a user's query text for the large language model, vectorize the query text, and determine a query vector.
[0091] S250: Perform data query in a preset vector database according to the query vector to determine a target file block.
[0092] S260: Perform a context query in a preset graph database according to the target file block to determine a target context.
[0093] S270: Input the target context into a large language model to obtain a target query result output by the large language model.
[0094] The technical solution of the embodiment of the present invention receives a user's query text for a large language model, vectorizes the query text, and determines a query vector. The vectorized query text can capture the semantic information of the query text and improve the effectiveness of the query; performs a data query in a preset vector database based on the query vector to determine the target file block, and matches the target file block corresponding to the query text through similarity matching between vectors, which can effectively improve the accuracy of the query; performs a context query in a preset graph database based on the target file block to determine the target context. The target context provides accurate data and can cover multi-dimensional data, improving the accuracy and effectiveness of the answer to the query text, and can also improve the reasoning ability of the large language model and the answer efficiency of the large language model; the target context is input into the large language model to obtain the target query result output by the large language model. This solves the technical problem in the prior art that large language models cannot retrieve accurate and valid data in graph databases, can ensure the effectiveness and accuracy of the retrieved content, reduce the time for large language models to retrieve data, improve the answer efficiency of large language models, and effectively reduce the dependence on computing power, thereby improving the answer performance of large language models.
[0095] Optional, Figure 3 A schematic diagram of a process for storing original documents provided for the implementation of the present invention. Figure 3As shown in the figure; the original text is parsed and sliced to obtain file blocks; then the entities and the relationships between them in the file blocks are extracted, and the file blocks are vectorized. The relationships between the entities and the entities in the file blocks are vectorized, and the vectors of the file blocks and the vectors of the relationships between the entities and the entities are stored in a vector database; the relationships between the entities and the entities in the file blocks and the file blocks are stored in a graph database.
[0096] Optional, Figure 4 A schematic diagram of a large language model retrieval data process provided for the implementation of the present invention. Figure 4 As shown: After receiving the query text for the large language model, the query text is vectorized to obtain a query vector, and the query vector is used to query in the vector database to obtain the target file block. Based on the target file block, a query is performed in the graph database to query the data vertices and vertex-edge relationships corresponding to the target file block. In the graph database, the vertex-edge relationships of the data vertices are expanded to determine the vertex-edge relationships of neighbor vertices and neighbor vertices. Then, the context is sorted to obtain the target context, and the target context is input into the large language model to obtain the target query result.
[0097] The embodiments of the present invention can ensure the validity and accuracy of the retrieved content and can effectively reduce the dependence on computing power.
[0098] Figure 5 A schematic diagram of the structure of a fusion retrieval device for graph data and vector data provided by an embodiment of the present invention. Figure 5 As shown, the device includes: a query response module 510, a vector query module 520, a graph data module 530 and a data processing module 540; wherein,
[0099] A query response module 510 is configured to receive a user's query text for the large language model, vectorize the query text, and determine a query vector;
[0100] A vector query module 520 is configured to perform a data query in a preset vector database based on the query vector to determine a target file block;
[0101] A graph data module 530 is configured to perform a context query in a preset graph database based on the target file block to determine a target context;
[0102] The data processing module 540 is configured to input the target context into a large language model to obtain a target query result output by the large language model.
[0103] The technical solution of the embodiment of the present invention receives a user's query text for a large language model, vectorizes the query text, and determines a query vector. The vectorized query text can capture the semantic information of the query text and improve the effectiveness of the query; performs a data query in a preset vector database based on the query vector to determine the target file block, and matches the target file block corresponding to the query text through similarity matching between vectors, which can effectively improve the accuracy of the query; performs a context query in a preset graph database based on the target file block to determine the target context. The target context provides accurate data and can cover multi-dimensional data, improving the accuracy and effectiveness of the answer to the query text, and can also improve the reasoning ability of the large language model and the answer efficiency of the large language model; the target context is input into the large language model to obtain the target query result output by the large language model. This solves the technical problem in the prior art that large language models cannot retrieve accurate and valid data in graph databases, can ensure the effectiveness and accuracy of the retrieved content, reduce the time for large language models to retrieve data, improve the answer efficiency of large language models, and effectively reduce the dependence on computing power, thereby improving the answer performance of large language models.
[0104] Optionally, the vector query module 520 is specifically configured to:
[0105] Performing vector matching in the vector database according to the query vector to determine a matching target data vector;
[0106] The target file block is obtained according to the target data vector.
[0107] Optionally, the graph data module 530 is specifically configured to:
[0108] Performing a data query in the data graph of the graph database according to the target file block to determine at least one data vertex and a vertex-edge relationship between the data vertex;
[0109] A context query is performed based on each of the data vertices and the vertex-edge relationship between each of the data vertices to determine the target context.
[0110] Optionally, the graph data module 530 is further configured to:
[0111] For each of the data vertices, performing vertex expansion on the vertex-edge relationship of the data vertex through the graph database to determine at least one neighbor vertex and the vertex-edge relationship of the neighbor vertex;
[0112] Context sorting is performed based on each of the data vertices, the vertex-edge relationship of each of the data vertices, each of the neighbor vertices, and the vertex-edge relationship of each of the neighbor vertices to determine the target context.
[0113] Optionally, the device further includes a document processing module, a vector storage module and a graph storage module: wherein,
[0114] The document processing module is configured to obtain an original document, perform document parsing and document slicing on the original document, and obtain at least one file block;
[0115] The vector storage module is used to establish a vector database based on all the file blocks;
[0116] The graph storage module is used to establish a graph database based on all the file blocks.
[0117] Optionally, the vector storage module is specifically used to:
[0118] For each of the file blocks, performing text vectorization on the file block to determine a data vector corresponding to the file block;
[0119] Each of the data vectors and the file blocks corresponding to each of the data vectors are stored in the vector database.
[0120] Optionally, the graph storage module is specifically used to:
[0121] For each of the file blocks, extract entities and relationships from the file block using a preset large language model to determine at least one entity and a relationship corresponding to each entity;
[0122] A knowledge graph is constructed based on each entity and the relationship corresponding to each entity, and each file block is stored in the graph database.
[0123] The fusion retrieval device for graph data and vector data provided in an embodiment of the present invention can execute the fusion retrieval method for graph data and vector data provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0124] Figure 6 A schematic diagram of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their modes are merely examples and are not intended to limit the implementation of the present invention described and / or claimed herein.
[0125] like Figure 6As shown, electronic device 10 includes at least one processor 11 and memory, such as read-only memory (ROM) 12 and random access memory (RAM) 13, communicatively connected to at least one processor 11. The memory stores computer programs executable by the at least one processor. Processor 11 can perform various appropriate actions and processes based on the computer programs stored in ROM 12 or loaded from storage unit 18 into RAM 13. RAM 13 can also store various programs and data required for the operation of electronic device 10. Processor 11, ROM 12, and RAM 13 are interconnected via bus 14. An input / output (I / O) interface 15 is also connected to bus 14.
[0126] Multiple components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0127] Processor 11 can be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any other suitable processor, controller, microcontroller, etc. Processor 11 executes the various methods and processes described above, such as the fusion retrieval method for graph data and vector data.
[0128] In some embodiments, the fusion retrieval method for graph data and vector data may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the fusion retrieval method for graph data and vector data described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the fusion retrieval method for graph data and vector data in any other appropriate manner (for example, by means of firmware).
[0129] Various embodiments of the systems and techniques described above can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0130] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the modes / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0131] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or apparatus. A computer-readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or apparatus, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media may include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0132] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device that has: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0133] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), a computing system that includes middleware components (e.g., an application server), a computing system that includes front-end components (e.g., a user computer with a graphical user interface or grid browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected via any form or medium of digital data communication (e.g., a communication grid). Examples of communication grids include: a local area network (LAN), a wide area network (WAN), a blockchain grid, and the Internet.
[0134] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication grid. This client-server relationship arises through computer programs running on the respective computers, establishing a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a hosting product within a cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS services.
[0135] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in the present invention can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved. This is not limited herein.
[0136] This embodiment provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the program implements the steps of the method for fusion retrieval of graph data and vector data provided in any embodiment of the present invention. The method includes:
[0137] receiving a user's query text for the large language model, vectorizing the query text to determine a query vector;
[0138] Performing a data query in a preset vector database according to the query vector to determine a target file block;
[0139] Performing a context query in a preset graph database according to the target file block to determine a target context;
[0140] The target context is input into the large language model to obtain the target query result output by the large language model.
[0141] The computer storage medium of the embodiments of the present invention may adopt any combination of one or more computer-readable media. The computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may be, for example, but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device, or device.
[0142] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0143] Program code embodied on a computer-readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0144] Computer program code for performing the operations of the present invention can be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer can be connected to the user's computer through any type of grid, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0145] Those skilled in the art will appreciate that the modules or steps of the present invention described above can be implemented using a general-purpose computing device. They can be centralized on a single computing device or distributed across a grid of multiple computing devices. Alternatively, they can be implemented using program code executable by a computer device, which can then be stored in a storage device and executed by the computing device. Alternatively, they can be fabricated into separate integrated circuit modules, or multiple modules or steps can be fabricated into a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0146] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in the present invention can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved. This is not limited herein.
[0147] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.
Claims
1. A fusion retrieval method for graph data and vector data, characterized in that: include: receiving a user's query text for the large language model, vectorizing the query text to determine a query vector; Performing a data query in a preset vector database according to the query vector to determine a target file block; Performing a context query in a preset graph database according to the target file block to determine a target context; The target context is input into the large language model to obtain the target query result output by the large language model.
2. The method according to claim 1, characterized in that The step of performing a data query in a preset vector database according to the query vector to determine a target file block includes: Performing vector matching in the vector database according to the query vector to determine a matching target data vector; The target file block is obtained according to the target data vector.
3. The method according to claim 2, characterized in that The performing a context query in a preset graph database according to the target file block to determine the target context includes: Performing a data query in the data graph of the graph database according to the target file block to determine at least one data vertex and a vertex-edge relationship between the data vertex; A context query is performed based on each of the data vertices and the vertex-edge relationship between each of the data vertices to determine the target context.
4. The method according to claim 3, characterized in that The performing a context query based on each of the data vertices and the vertex-edge relationship between each of the data vertices to determine the target context includes: For each of the data vertices, performing vertex expansion on the vertex-edge relationship of the data vertex through the graph database to determine at least one neighbor vertex and the vertex-edge relationship of the neighbor vertex; Context sorting is performed according to each of the data vertices, the vertex-edge relationship of each of the data vertices, each of the neighbor vertices, and the vertex-edge relationship of each of the neighbor vertices to determine the target context.
5. The method according to claim 1, wherein Before receiving the user's query text for the large language model, the method further includes: Obtaining an original document, parsing and slicing the original document to obtain at least one file block; Establishing a vector database according to all the file blocks; A graph database is established based on all the file blocks.
6. The method according to claim 5, characterized in that The step of establishing a vector database based on all the file blocks includes: For each of the file blocks, performing text vectorization on the file block to determine a data vector corresponding to the file block; Each of the data vectors and the file blocks corresponding to each of the data vectors are stored in the vector database.
7. The method according to claim 6, characterized in that The step of establishing a graph database based on all the file blocks includes: For each of the file blocks, extract entities and relationships from the file block using a preset large language model to determine at least one entity and a relationship corresponding to each entity; A knowledge graph is constructed based on each entity and the relationship corresponding to each entity, and each file block is stored in the graph database.
8. A fusion retrieval device for graph data and vector data, characterized in that: include: A query response module, configured to receive a user's query text for the large language model, vectorize the query text, and determine a query vector; A vector query module, configured to perform a data query in a preset vector database according to the query vector to determine a target file block; A graph data module, configured to perform a context query in a preset graph database according to the target file block to determine a target context; The data processing module is used to input the target context into the large language model to obtain the target query result output by the large language model.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the fusion retrieval method for graph data and vector data according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the fusion retrieval method for graph data and vector data according to any one of claims 1 to 7 when executed.