Domain-adaptive graph query language generation method and device based on large language model

Through the domain adaptive graph query language generation method based on large language model, the learning cost and efficiency problems caused by the differences in query language between different graph databases are solved, and more accurate and efficient graph query language generation is achieved, which enhances the adaptability of the system and scalability.

CN119149785BActive Publication Date: 2025-02-14AEROSPACE INFORMATION RES INST CAS
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411649490.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-19
Publication Date
2025-02-14
Estimated Expiration
2044-11-19

AI Technical Summary

Technical Problem

The query languages ​​of existing graph databases are different, which leads to users who need to learn multiple query languages ​​when switching between different graph databases, which increases learning costs and inefficiency in query.

Method used

The domain adaptation graph query language generation method based on the large language model is adopted. By obtaining natural language query information and using the pre-trained large language model for domain adaptation processing, the graph query language information of the target field is generated, so that the large language model and the target field are Graph database alignment.

Benefits of technology

It reduces the need to manually write complex query statements, improves the accuracy and efficiency of query, and enhances the cross-domain adaptability and scalability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149785B_ABST
    Figure CN119149785B_ABST
Patent Text Reader

Abstract

The present invention provides a method and device for generating a domain-adaptive graph query language based on a large language model, and relates to the field of natural language processing. The method for generating a domain-adaptive graph query language based on a large language model includes: obtaining natural language query information; using a pre-trained large language model to perform domain adaptation processing on the natural language query information, and generating graph query language information of the target domain, wherein the pre-training is used to align the large language model with the graph database of the target domain. The present invention understands the business logic described in natural language through a pre-trained large language model, and directly generates a graph database query statement, thereby avoiding the bottleneck of traditional query statement programming. At the same time, the graph query language generated by the large language model has cross-platform and cross-database portability, and is suitable for different business fields and rules.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of natural language processing, and in particular to a method and device for generating domain-adaptive graph query language based on a large language model. Background Art

[0002] As a non-relational database, graph database plays an important role in many application scenarios with its unique data model and query characteristics, and has been widely used in fields including social network analysis, recommendation system, fraud detection, bioinformatics, etc. However, the query and retrieval of graph databases now need to follow their own dedicated languages, such as Neo4j using Cypher language and ArangoDB using AQL language. These languages ​​have their own fixed grammatical structures and rules, which bring certain learning costs and obstacles to some business-oriented users who are not good at programming. And because each graph database uses a different query language, this means that if users need to switch between different graph databases, they have to master multiple query languages, which increases the learning cost and reduces the query efficiency. Summary of the invention

[0003] In view of this, an embodiment of the present invention provides a method for generating a domain-adaptive graph query language based on a large language model, a device thereof, and a storage medium.

[0004] A first aspect of an embodiment of the present invention provides a method for generating a domain-adapted graph query language based on a large language model, comprising: obtaining natural language query information; using a pre-trained large language model to perform domain adaptation processing on the natural language query information to generate graph query language information of a target domain, wherein the pre-training is used to align the large language model with a graph database of the target domain.

[0005] According to an embodiment of the present invention, a pre-trained large language model is used to perform domain adaptation processing on natural language query information to generate a graph query language for a target domain, including: generating multiple groups of NL-GQL template pairs that have been verified by queries; using the multiple groups of NL-GQL template pairs as training data, fine-tuning the large language model to be trained, and aligning the large language model with the graph database to obtain the pre-trained large language model.

[0006] According to an embodiment of the present invention, generating multiple groups of NL-GQL template pairs verified by graph database queries includes: defining a set of standardized first NL-GQL template pairs according to the graph database; using the large language model to be trained to perform self-guided expansion on the first NL-GQL template pairs to obtain second NL-GQL template pairs; querying and verifying the second NL-GQL template pairs to obtain multiple groups of NL-GQL template pairs.

[0007] According to an embodiment of the present invention, the first NL-GQL template pair includes at least one of an entity attribute query NL-GQL template pair, a numerical sorting query NL-GQL template pair, a relational reasoning query NL-GQL template pair, a yes-no question query NL-GQL template pair, a relational filtering query NL-GQL template pair, an attribute comparison query NL-GQL template pair, an edge attribute query NL-GQL template pair, and a string filtering query NL-GQL template pair.

[0008] According to an embodiment of the present invention, defining a set of standardized first NL-GQL template pairs includes: using a first placeholder to represent an entity in the first NL-GQL template pair, and using a second placeholder to represent an attribute of the entity.

[0009] According to an embodiment of the present invention, using multiple groups of NL-GQL template pairs as training data to fine-tune the large language model to be trained includes: using multiple groups of NL-GQL template pairs as training data, and using a quantized low-rank adaptive fine-tuning algorithm to perform supervised fine-tuning on the large language model to be trained.

[0010] According to an embodiment of the present invention, multiple groups of NL-GQL template pairs are used as training data, and a quantized low-rank adaptive fine-tuning algorithm is used to perform supervised fine-tuning on a large language model to be trained, including: quantizing the weights of the large language model to be trained into a specific precision format; adding low-rank adapter weights to the quantized large language model to learn high-order features of the original weights of the large language model; using multiple groups of NL-GQL template pairs as training data, and adjusting the low-rank adapter weights and the weight parameters of the quantized large language model through error feedback transmission.

[0011] According to an embodiment of the present invention, a pre-trained large language model is used to perform domain adaptation processing on natural language query information to generate graph query language information in a target domain, including: identifying a paradigm of a graph database, wherein the large language model is aligned with the paradigm, and the paradigm includes node types, relationship types, and attributes; and extracting named entities and patterns in the natural language query information to guide the large language model to use the paradigm to generate graph query language information in the target domain.

[0012] According to an embodiment of the present invention, the method for generating a domain-adaptive graph query language based on a large language model also includes: outputting the generated graph query language information to a user interface for user viewing and use; and iteratively updating the large language model based on user feedback information.

[0013] A second aspect of an embodiment of the present invention provides a domain-adaptive graph query language generation device based on a large language model, comprising: an input module for acquiring natural language query information; a processing module for performing domain adaptation processing on the natural language query information using a pre-trained large language model to generate graph query language information of a target domain, wherein the pre-training is used to align the large language model with a graph database of the target domain.

[0014] A third aspect of an embodiment of the present invention provides a computer-readable storage medium having a computer program or instruction stored thereon. When the computer program or instruction is executed by a processor, the steps of any one of the methods in the above embodiments are implemented.

[0015] According to the domain-adaptive graph query language generation method based on a large language model according to an embodiment of the present invention, domain adaptation processing is performed through a pre-trained large language model, which can more accurately understand the query requirements entered by the user in the form of natural language, and convert them into query languages ​​for graph databases in specific target domains. This conversion not only reduces the need for manually writing complex query statements, avoids the bottleneck of traditional query statement programming, but also significantly improves the accuracy and efficiency of queries. Through domain adaptation processing, the large language model can generate customized query languages ​​for graph databases in different fields, enhancing the cross-domain adaptability and scalability of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The above and other objects, features and advantages of the present invention will become more apparent through the following description of the embodiments of the present invention with reference to the accompanying drawings, in which:

[0017] Figure 1 A flowchart of a method for generating a domain-adaptive graph query language based on a large language model according to a first embodiment of the present invention is schematically shown;

[0018] Figure 2 A flowchart of a method for generating a domain-adaptive graph query language based on a large language model according to a second embodiment of the present invention is schematically shown;

[0019] Figure 3 A diagram schematically shows an application scenario of a method for generating a domain-adaptive graph query language based on a large language model according to an embodiment of the present invention;

[0020] Figure 4 A flowchart of a method for generating a domain-adaptive graph query language based on a large language model according to a third embodiment of the present invention is schematically shown;

[0021] Figure 5 The structural block diagram of a domain-adaptive graph query language generation device based on a large language model according to an embodiment of the present invention is schematically shown. DETAILED DESCRIPTION

[0022] Below, embodiments of the present invention will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present invention. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of embodiments of the present invention. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of concepts of the present invention.

[0023] The terms used herein are only for describing specific embodiments and are not intended to limit the present invention. The terms "comprise", "include", etc. used herein indicate the existence of features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.

[0024] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.

[0025] When using expressions such as "at least one of A, B, and C, etc.", they should generally be interpreted according to the meaning of the expression commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).

[0026] The applicant found in the research that the existing methods for converting natural language (NL) to graph query language (GQL) mainly include direct translation and data-driven generation. Among them, direct translation relies on manually formulated rules to directly translate natural language into GQL. The data-driven method mainly uses artificial intelligence models to learn the rules inherent in the data. By training the sequence-to-sequence (Seq2Seq) model on the NL2GQL (Natural Language to Graph Query Language) dataset, the system learns the conversion from NL to GQL. However, the existing methods have the following shortcomings: (1) Lack of domain-specific data: In the NL2GQL task in a specific domain, there is a lack of domain-specific NL-GQL data pairs, which makes it difficult to establish alignment between large language models (LLMs) and graph databases. (2) Complexity and professionalism: The complex and specialized nature of GQL makes the task of converting from natural language understanding to GQL very challenging. (3) Diversity of terminology and conventions: The diversity of terminology and conventions in domain-specific graph data increases the complexity of the translation process. In addition, domain-specific graph databases have unique patterns and query requirements, which are difficult for existing methods to adapt to. As a result, the accuracy of task implementation is low and it is difficult to generalize applications.

[0027] In view of this, the present invention provides a domain-adaptive graph query language generation method based on a large language model. By guiding the large language model with knowledge, the large language model can understand the semantics of the business logic described in natural language, and then directly generate the corresponding graph database query statement, effectively avoiding the programming bottleneck of the graph database query statement. Moreover, the language generated by the large language model can be cross-platform and cross-database, and has good portability. Figures 1 to 4 This paper introduces a domain-adaptive graph query language generation method based on a large language model.

[0028] Figure 1 The flowchart of the method for generating domain-adaptive graph query language based on a large language model according to an embodiment of the present invention is schematically shown.

[0029] like Figure 1 As shown, in this embodiment, the domain-adaptive graph query language generation method based on a large language model may include operation S110 and operation S120.

[0030] In operation S110, natural language query information is obtained;

[0031] For example, natural language query information can be obtained from users or other sources. These queries can be simple requests, such as "find all companies related to xx", or complex requests with multiple conditions and constraints, such as "find all companies related to xx in xx location". The natural language query information input by the user can be text directly entered through web forms, chat interfaces, etc. It can also be voice input, and then the voice is converted into text through speech recognition technology.

[0032] In operation S120, a pre-trained large language model (LLM) is used to perform domain adaptation processing on the natural language query information to generate graph query language information of a target domain, wherein the pre-training is used to align the large language model with the graph database of the target domain.

[0033] A large language model, also known as a large language model, is an artificial intelligence model designed to understand and generate human language. There are already a variety of large language models on the market, which can be selected as needed, and the present invention does not limit the specific type of large language model. However, considering the complexity and specialized nature of GQL, more advanced models or algorithms can be used to handle the complex task of converting from natural language understanding to GQL, including but not limited to improved sequence-to-sequence (Seq2Seq) models, or introducing more contextual understanding and semantic analysis techniques to improve the accuracy and efficiency of the conversion. For the selected basic large language model, it can be trained to align the large language model with the graph database of the target domain, that is, before the large language model is applied to generate the query language of the graph database of the target domain, a specific training process is used to enable the model to understand and adapt to the specific context, vocabulary, structure and query pattern of the target domain.

[0034] By performing domain adaptation processing with a pre-trained large language model, this method can more accurately understand the query requirements entered by users in natural language and convert them into query language for graph databases in specific target domains. This conversion not only reduces the need to manually write complex query statements, avoids the bottleneck of traditional query statement programming, but also significantly improves the accuracy and efficiency of queries. Through domain adaptation processing, the large language model can generate customized query languages ​​for graph databases in different fields, enhancing the cross-domain adaptability and scalability of the system.

[0035] Figure 2 The flowchart of the method for generating domain-adaptive graph query language based on a large language model according to the second embodiment of the present invention is schematically shown.

[0036] like Figure 2As shown, in some embodiments, before the above operation S120, the selected large language model may be pre-trained, which may specifically include operations S211 and S212.

[0037] In operation S211 , a plurality of query-verified groups of NL-GQL template pairs are generated.

[0038] The NL-GQL template pair consists of an NL template and a GQL template. It is understandable that the number of NL-GQL template pairs should be able to cover the common and key scenarios of the target graph database query. As an example, a series of concise and clear NL template statements and their corresponding GQL template statements that can cover different query scenarios can be generated first, and these GQL template statements are executed to verify whether they can retrieve the correct results from the graph database. If the verification is successful, the NL template statement and its corresponding GQL template statement are paired into an NL-GQL template pair as part of the training data.

[0039] In operation S212, multiple groups of NL-GQL template pairs are used as training data to fine-tune the large language model to be trained, so that the large language model is aligned with the graph database to obtain a pre-trained large language model.

[0040] During the training process, fine-tuning enables the large language model to learn how to map natural language queries to corresponding GQL statements and continuously optimize its performance. Usually, the fine-tuning process also needs to be accompanied by performance evaluation to understand the performance of the model in different scenarios and determine whether further training or adjustment is needed. Once the model reaches a satisfactory performance level, it can be deployed to actual application scenarios to process natural language queries from users and generate corresponding GQL statements for querying.

[0041] By generating multiple sets of NL-GQL template pairs and then fine-tuning the large language model, the large language model can be aligned with a specific graph database, enabling it to understand and generate natural language instructions related to the graph query language, thereby providing users with more convenient and efficient data query services.

[0042] Please continue reading Figure 2 In some embodiments, the operation S211 may specifically include: defining a set of standard first NL-GQL template pairs according to the graph database; using the large language model to be trained to perform self-guided expansion on the first NL-GQL template pairs to obtain second NL-GQL template pairs; querying and verifying the second NL-GQL template pairs to obtain multiple sets of NL-GQL template pairs.

[0043] Specifically, we can start from the graph database and collect a set of canonical first NL-GQL template pairs, covering typical queries such as node attributes, node relationships, numerical sorting, and attribute comparison, and then use the self-guided judgment method of the large language model to expand these initial pairs and generate more comprehensive second NL-GQL template pairs. The generated second NL-GQL template pairs are all verified by the query of the graph database to ensure that they have good performance in terms of query coverage and expression diversity, while maintaining consistency between NL templates and GQL templates.

[0044] In some embodiments, to ensure the diversity and comprehensiveness of NL-GQL generated on different graph databases, the NL-GQL template can be formulated as a narrative question with MASK mask items (i.e., entities and attributes), followed by a GQL framework, in which the first placeholder (such as [entity]) can be used to represent named entities in NL and GQL, and the second placeholder (such as [property]) can be used to represent the attributes of the entity. Placeholders can be used to mask the entity labels and attributes of some nodes in the statement, thereby increasing the robustness of the task. In some embodiments, for each NL type, data pairs can also be manually screened and included in the data pool to strengthen the human thinking guidance process.

[0045] In some embodiments, the first NL-GQL template pair includes at least one of an entity attribute query NL-GQL template pair, a numerical sorting query NL-GQL template pair, a relational reasoning query NL-GQL template pair, a yes-no query NL-GQL template pair, a relational filtering query NL-GQL template pair, an attribute comparison query NL-GQL template pair, an edge attribute query NL-GQL template pair, and a string filtering query NL-GQL template pair, so as to cover more query scenarios. As an example, these template pairs can be expressed as follows:

[0046] 1. Entity property query (Type#1 Entity property):

[0047] NL template: What is [entity]'s [property]?

[0048] GQL template: MATCH (s:node{name:'[entity]'}) RETURN s.node.[property]

[0049] 2. Numerical sorting query (Type#2 Numerical sorting):

[0050] NL template: The [property2] of node with the highest [property1]?

[0051] GQL template: MATCH (s:node) WITH s.node.[property2] AS n1, s.node.[property1] AS n2 ORDER BY n2 DESC LIMIT 1 RETURN n1

[0052] 3. Relationship inference query (Type#3 Relationship inference):

[0053] NL template: The [property] of node1 related to [entity] by [rel2]?

[0054] GQL template: MATCH (s1:node1)<-[:rel1]-(s2:node2)<-[:rel2]-(s3:node3{name:'[entity]'}) RETURN s1.node1.[property]

[0055] 4. Yes / No question (Type#4 Yes / No question):

[0056] NL template: Is the [property] of the [entity] greater than [mount]?

[0057] GQL template: MATCH (s:node{name:'[entity]'}) RETURN s.node.[property] >[mount]

[0058] 5. Relationship filtering query (Type#5 Relationship filtering):

[0059] NL template: The [property] of node2 that [rel] [entity1] and [entity2]?

[0060] GQL template: MATCH (s1:node1{name:'[entity1]'})<-[:rel]-(s2:node2)-[:rel]->(s3:node1{name:'[entity2]'}) RETURN s2:node2.[property]

[0061] 6. Attribute comparison query (Type#6 Attribute comparison):

[0062] NL template: How much does the [property] of [entity1] differ from that of [entity2]?

[0063] GQL template: MATCH (s1:node{name:'[entity1]'}) WITH s1.node.[property] ASt1 MATCH (s2:node{name:'[entity2]'}) WITH ABS(s2.node.[property] - t1) asabs_diff RETURN abs_diff

[0064] 7. Edge property query (Type#7 Edge property):

[0065] NL template: The [property] of node2 that [rel] [entity] with [r_property]less than [m]?

[0066] GQL template: MATCH (s1:node1{name:'[entity]'})-[r:rel]-(s2:node2) WHERE r.[r_property] < [m] RETURN s2.node2.[property]

[0067] 8. String filtering query (Type#8 String filtering):

[0068] NL template: The [property] of the node containing the [string]?

[0069] GQL template: MATCH (s:node) WHERE s.node.[property] CONTAINS [string]RETURN s.node.[property]

[0070] Please continue reading Figure 2 In the above operation S212, the quantized low-rank adaptation (QLoRA) fine-tuning algorithm can be used to fine-tune the large language model to be trained in a supervised manner to align with the paradigm of the graph database, that is, after generating multiple sets of NL-GQL template pairs, these instructions are used to fine-tune the existing basic large language model. The QLoRA technology is used to fine-tune the model, which is an improvement on the LoRA (Low-Rank Adaptation) technology. It improves the efficiency and accuracy of model fine-tuning by combining quantization technology and low-rank matrix adaptation, while minimizing fine-tuning parameters and optimizing memory usage, and maintaining performance. Specifically, for each NL-GQL template pair, the pattern items (such as node type, relationship type, attribute, etc.) in the graph database can be extracted as the context instruction of NL, and then the cross entropy loss function value of the GQL generated by the calculation model and the real GQL is fine-tuned in a supervised manner. Through the error feedback transmission method, the large language model is continuously iterated and updated, so that the fine-tuned large language model learns the pattern of the graph database in a specific domain and understands the conversion from NL to GQL. Here is a further explanation of this process:

[0071] First, the weights of the large language model to be trained are quantized into a specific precision format. Taking the LLaMA-3-Chinese large language model as an example, the weights of the model can be quantized into int4 format to reduce the memory usage and computing requirements of the model.

[0072] Next, low-rank adapter weights are added to the quantized large language model to learn the high-order features of the original weights of the large language model. These low-rank adapter weights will be used to capture the high-order features in the original weights and updated during the fine-tuning process to adapt to the query requirements of the graph database.

[0073] Then, multiple groups of NL-GQL template pairs are used as training data, and the weight parameters of the low-rank adapter and the quantized large language model are adjusted through error feedback transmission. For example, multiple groups of NL-GQL pairs generated in step S211 are used as training data, and the low-rank adapter weights and the quantized model weights are adjusted through optimization algorithms such as back propagation and gradient descent.

[0074] Through the above steps, fine-tuning of the LLaMA-3-Chinese large language model can be achieved. The large language model is trained through fine-tuning technology so that it can accurately understand the business logic semantics described in natural language and generate corresponding query language.

[0075] Furthermore, the above steps may also include model performance optimization, model evaluation, and reasoning. For example, during the fine-tuning process, the performance of the large language model is monitored to ensure that it adapts to the specific structure and query requirements of the graph database while maintaining accuracy. Next, the fine-tuned large language model is evaluated on the validation set to ensure that it can accurately convert natural language queries into correct GQL statements. The fine-tuned large language model can then be deployed to actual applications, enabling it to receive natural language queries and generate corresponding GQL statements for execution by the graph database.

[0076] See also Figure 1 and Figure 2 , the above step S120 may specifically include: identifying the paradigm of the graph database, wherein the large language model is aligned with the paradigm, and the paradigm includes node types, relationship types, and attributes; extracting named entities and patterns in natural language query information to guide the large language model to use the paradigm to generate graph query language information in the target domain.

[0077] The graph database is stored according to the logic of association. As an example, its representation can be recorded as follows:

[0078]

[0079] in, and V represent the collection of nodes and edges respectively. Nodes represent entities, and edges represent the relationship between entities. A graph database is a graph structure with attributes, where both nodes and edges have labels and multiple attributes, which together form a schema, i.e. a comprehensive description of the types and attributes of the graph database nodes and edges.

[0080] Then, in combination with the paradigm of the graph database, prompt sentences and examples of the target domain are constructed. By constructing a domain-adaptive prompt paradigm, that is, by guiding the large language model with domain knowledge, the large language model can better understand the business logic semantics described by natural language, and can generate graph database queries more accurately. Specifically, in the reasoning process, in order to align the large language model with the paradigm of the graph database, by extracting patterns related to the query natural speech as a guiding example, the large language model can be more accurately guided to use the recognized graph database paradigm to generate a precise domain-adapted graph query language. Specifically, the algorithm extracts the main graph database paradigm item content related to natural language, rather than the entire paradigm as context. To this end, a domain adaptive linker can be used to extract named entities and link them to labels in the graph database. Named entities usually refer to entities with specific meanings in text, such as names of people, places, and institutions. Domain adaptation means that this linker can be optimized for specific domains or contexts to improve the accuracy and efficiency of named entity recognition. Then, the large language model prompt organizes the extracted tags into context and generates the main body of the graph query language. Finally, a connection table is further inferred based on the extracted tags and they are appended to the body to form a prompt. After obtaining the relevant patterns, the task description and input natural language are combined to compose a comprehensive prompt.

[0081] See also Figure 3 , Figure 3 The application scenario diagram of the domain-adaptive graph query language generation method based on a large language model according to an embodiment of the present invention is schematically shown, showing the process of the trained large language model converting the acquired natural speech query information into graph query language information in the target domain. In this application scenario, the following prompt statements and examples are constructed in combination with the Schema of Graph DB:

[0082] 「Schema of Graph DB」:

[0083] Nodes: {{'properties': ['id', 'name'], 'labels': 'Journal')) ({'properties1': ['id', 'name'], 'labels': 'Author')) {{'properties': ['id', 'title', 'abstract', 'authors', 'date', 'journal'), 'labels': 'Article'}}.

[0084] Relationships: {{'source': 'Journal', 'relationship': 'PUBLISHED', 'target': ['Article'l}) {{'source': 'Author', 'relationship': 'WROTE', 'target': ['Article'l}}Nodes {{}'properties': [('code', 'string'), ...] ...

[0085] 「Task Description」:You are a graph database expert. Please write the corresponding graph query language based on the relevant schema and naturallanguage.

[0086] The user enters the natural language query information based on the task description above:

[0087] 「NL」: Get 5 journal titles?

[0088] After the trained large language model understands the user's natural speech, it generates the corresponding graph query language information:

[0089] "GQL": MATCH (j:.Journal) RETURN j.name LIMIT 5.

[0090] Figure 4 The flowchart of the method for generating domain-adaptive graph query language based on a large language model according to the third embodiment of the present invention is schematically shown.

[0091] like Figure 4 As shown, in this embodiment, after the above operation S120, the domain adaptation graph query language generation method based on the large language model may further include operation S410 and operation S420.

[0092] In operation S410, the generated graph query language information is output to a user interface for viewing and use by a user.

[0093] In operation S420, the large language model is iteratively updated according to the user's feedback information.

[0094] Specifically, the feedback information may include evaluations of the accuracy, speed, and ease of use of the query. As an example, a feedback mechanism may be added to the user interface to allow users to evaluate the query results or make suggestions for improvement. Based on the feedback results, the system re-labels or corrects part of the query data, and then uses the updated training data to retrain or fine-tune the large language model to improve the performance of the large language model. The number and cycle of iterations can be reasonably set as needed until the large language model reaches a satisfactory performance level.

[0095] Through the above embodiment, after the generation and execution of the graph query language is completed, the results are output to the user interface for users to view and use, which not only allows users to directly obtain the data they need, but also enhances the interactivity and user experience of the system. At the same time, iteratively updating the large language model based on user feedback information can continuously improve the performance and accuracy of the model, making it better adapted to actual application scenarios.

[0096] In summary, through the above multiple embodiments, the domain-adaptive graph query language generation method based on a large language model of the present invention has at least the following beneficial effects:

[0097] 1. Break the barriers between logic and data access. The big language model understands the business logic described in natural language and directly generates graph database query statements, avoiding the bottleneck of traditional query statement programming. The language generated by the big language model is cross-platform and cross-database portable and is suitable for different business fields and rules.

[0098] 2. Improve query efficiency and accuracy. Through fine-tuning technologies such as QLoRA, the large language model is trained to accurately understand the business logic semantics described in natural language and generate corresponding query language. In combination with the paradigm of graph database, prompt statements and examples are constructed to further improve the accuracy of queries.

[0099] 3. Enhance system robustness. Use templates with mask items to increase the robustness of the task and ensure the stability and accuracy of the system when processing different types of queries. The designed NL-GQL task template covers multiple query types such as node attributes, node relationships, numerical sorting, attribute comparison, etc., which enhances the adaptability of the system.

[0100] 4. Wider practical scenarios. During the model deployment and actual use process, by continuously collecting feedback, the model is further iterated and optimized to continuously improve system performance and user experience, making it better adapted to actual application scenarios.

[0101] Based on the above-mentioned domain adaptation graph query language generation method based on a large language model, the present invention also provides a domain adaptation graph query language generation device based on a large language model, which has the same technical features and effective effects as the above-mentioned domain adaptation graph query language generation method based on a large language model. Figure 5 The device is described in detail.

[0102] Figure 5 The structural block diagram of a domain-adaptive graph query language generation device based on a large language model according to an embodiment of the present invention is schematically shown.

[0103] like Figure 5 As shown, the domain adaptive graph query language generation device 500 of this embodiment includes: an input module 510 and a processing module 520.

[0104] The input module 510 is used to obtain natural language query information. In one embodiment, the input module 510 can be used to perform the operation S110 described above, which will not be described in detail here.

[0105] The processing module 520 is used to use the pre-trained large language model to perform domain adaptation processing on the natural language query information to generate graph query language information in the target domain, wherein the pre-training is used to align the large language model with the graph database in the target domain. In one embodiment, the processing module 520 can be used to perform the operation S120 described above, which will not be repeated here.

[0106] In some embodiments, the domain-adaptive graph query language generation device 500 may further include a training module for generating multiple sets of NL-GQL template pairs verified by queries; using the multiple sets of NL-GQL template pairs as training data, fine-tuning the large language model to be trained, and aligning the large language model with the graph database to obtain a pre-trained large language model. In one embodiment, the training module can be used to perform operations S211-S212 described above, which will not be repeated here.

[0107] In some embodiments, the domain-adaptive graph query language generation device 500 may further include an output module and an update module. The output module is used to output the generated graph query language information to the user interface for the user to view and use. The update module is used to iteratively update the large language model according to the user's feedback information. In one embodiment, the output module can be used to perform the operation S310 described above, and the update module can be used to perform the operation S320 described above, which will not be repeated here.

[0108] According to an embodiment of the present invention, any multiple modules among the input module 510, the processing module 520, the training module, the output module and the update module can be combined into one module for implementation, or any one of the modules can be split into multiple modules. Alternatively, at least part of the functions of one or more of these modules can be combined with at least part of the functions of other modules and implemented in one module. According to an embodiment of the present invention, at least one of the input module 510, the processing module 520, the training module, the output module and the update module can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware and firmware or in any appropriate combination of any of them. Alternatively, at least one of the input module 510, the processing module 520, the training module, the output module and the update module can be at least partially implemented as a computer program module, and when the computer program module is run, the corresponding function can be executed.

[0109] The present invention also provides a computer-readable storage medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present invention is implemented.

[0110] According to an embodiment of the present invention, the computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, may include but is not limited to: 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), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, apparatus or device.

[0111] It will be appreciated by those skilled in the art that the features described in the various embodiments of the present invention may be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in the present invention. In particular, without departing from the spirit and teachings of the present invention, the features described in the various embodiments of the present invention may be combined and / or combined in various ways. All of these combinations and / or combinations fall within the scope of the present invention.

[0112] The embodiments of the present invention are described above. However, these embodiments are only for the purpose of illustration, and are not intended to limit the scope of the present invention. Although each embodiment is described above, it does not mean that the measures in each embodiment cannot be used in combination advantageously. Without departing from the scope of the present invention, those skilled in the art may make various substitutions and modifications, which should all fall within the scope of the present invention.

Claims

1. A method for generating domain-adaptive graph query language based on a large language model, characterized in that: include: Obtain natural language query information; Using a pre-trained large language model, domain adaptation processing is performed on the natural language query information to generate graph query language information of a target domain, wherein the pre-training is used to align the large language model with a graph database of the target domain; Before the pre-trained large language model is used to perform domain adaptation processing on the natural language query information to generate a graph query language for a target domain, the method includes: Generate multiple groups of NL-GQL template pairs verified by queries; use the multiple groups of NL-GQL template pairs as training data, fine-tune the large language model to be trained, and obtain the pre-trained large language model after aligning the large language model with the graph database; The generating of multiple groups of NL-GQL template pairs verified by querying the graph database includes: defining a set of standardized first NL-GQL template pairs according to the graph database; using the large language model to be trained to perform self-guided expansion on the first NL-GQL template pairs to obtain second NL-GQL template pairs; querying and verifying the second NL-GQL template pairs to obtain the multiple groups of NL-GQL template pairs.

2. The method for generating a graph query language according to claim 1, characterized in that: The first NL-GQL template pair includes at least one of the following: entity attribute query NL-GQL template pair, numerical sorting query NL-GQL template pair, relational reasoning query NL-GQL template pair, yes or no question query NL-GQL template pair, relational filtering query NL-GQL template pair, attribute comparison query NL-GQL template pair, edge attribute query NL-GQL template pair, and string filtering query NL-GQL template pair.

3. The method for generating a graph query language according to any one of claims 1 to 2, characterized in that: The first NL-GQL template pair defining a set of specifications includes: A first placeholder is used to represent an entity in the first NL-GQL template pair, and a second placeholder is used to represent an attribute of the entity.

4. The method for generating a graph query language according to claim 1, characterized in that: The using the multiple groups of NL-GQL template pairs as training data to fine-tune the large language model to be trained comprises: The multiple groups of NL-GQL template pairs are used as training data, and a quantized low-rank adaptive fine-tuning algorithm is used to perform supervised fine-tuning on the large language model to be trained.

5. The method for generating a graph query language according to claim 4, characterized in that: The method of using the multiple groups of NL-GQL template pairs as training data and using a quantized low-rank adaptive fine-tuning algorithm to perform supervised fine-tuning on the large language model to be trained comprises: quantizing the weights of the large language model to be trained into a specific precision format; Adding low-rank adapter weights on the quantized large language model to learn high-order features of the original weights of the large language model; The multiple groups of NL-GQL template pairs are used as training data, and the weight parameters of the low-rank adapter and the quantized large language model are adjusted through error feedback transmission.

6. The method for generating a graph query language according to any one of claims 1 to 2 or 4 to 5, characterized in that: The using of the pre-trained large language model to perform domain adaptation processing on the natural language query information to generate graph query language information of the target domain includes: identifying a paradigm of the graph database, wherein the large language model is aligned with the paradigm, the paradigm comprising node types, relationship types, and attributes; Named entities and patterns in the natural language query information are extracted to guide the large language model to generate graph query language information of the target domain using the paradigm.

7. The method for generating a graph query language according to claim 1, characterized in that: Also includes: Outputting the generated graph query language information to a user interface for viewing and use by a user; The large language model is iteratively updated according to the feedback information of the user.

8. A domain-adaptive graph query language generation device based on a large language model, characterized in that: include: An input module, used to obtain natural language query information; A processing module, configured to perform domain adaptation processing on the natural language query information using a pre-trained large language model to generate graph query language information of a target domain, wherein the pre-training is used to align the large language model with a graph database of the target domain; A training module is used to generate multiple groups of NL-GQL template pairs verified by queries before using the pre-trained large language model to perform domain adaptation processing on the natural language query information to generate graph query language information of the target domain; using the multiple groups of NL-GQL template pairs as training data to fine-tune the large language model to be trained so that the large language model is aligned with the graph database to obtain the pre-trained large language model; wherein, generating multiple groups of NL-GQL template pairs verified by the graph database query includes: defining a set of standardized first NL-GQL template pairs according to the graph database; using the large language model to be trained to perform self-guided expansion on the first NL-GQL template pair to obtain a second NL-GQL template pair; query verification on the second NL-GQL template pair to obtain the multiple groups of NL-GQL template pairs.

Citation Information

Patent Citations

  • Large language model Text2SQL (Structured Query Language) chart generation method and device

    CN117851445A

  • Knowledge graph question and answer method, device and system, electronic equipment and storage medium

    CN118820435A