Semantic vector generation method and device, equipment and storage medium
By constructing positive and negative samples in the knowledge graph and training a vector model, the problem of synonyms and semantic associations in the knowledge graph was solved, achieving efficient text matching and cross-scene adaptability, and improving the accuracy and computational efficiency of AI search services.
Patent Information
- Application Number
- CN202511450951.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-11
- Publication Date
- 2026-02-10
AI Technical Summary
In knowledge graph-based AI search, existing technologies struggle to effectively handle synonyms and semantic associations, and deep learning methods lack cross-scenario transfer capabilities, resulting in low computational efficiency and insufficient answer accuracy.
By obtaining the CQL statement pairs corresponding to the fine-tuning query statements, recall text related to node labels and attribute data is retrieved from the knowledge graph, positive and negative samples are constructed, fine-tuning samples are generated using fine-tuning instructions and end markers, the vector model is trained, and parameters are adjusted to generate the target vector model, adapting to different knowledge graph scenarios.
It improves the accuracy of text matching in knowledge graph search scenarios, maintains accurate semantic information and has good scenario adaptability, and reduces annotation costs.
Smart Images

Figure CN121503623A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of vector matching, in particular to a semantic vector generation method and device, equipment and a storage medium. BACKGROUND
[0002] In the AI search business based on the knowledge graph, a large model needs to rely on an external knowledge graph to answer user questions to solve the "illusion" problem of a general large model. However, the information volume of the knowledge graph is huge, and if all the information of the knowledge graph is input into the model, the context will be too long, the calculation efficiency will be low, and there will be semantic redundancy. Therefore, it is necessary to accurately recall the node and relationship information related to the user question from the knowledge graph, to construct local information focusing on the query demand, and to further improve the accuracy of the answer and the response efficiency.
[0003] The matching method in the related art mainly includes two types: one is sparse matching based on the BM25 algorithm, which depends on word frequency statistics and cannot effectively handle synonym and semantic association problems, such as the difficulty in identifying the semantic relevance between "card swiping" and "attendance"; the other is semantic matching based on deep learning (such as the BERT model), which can capture semantic information, but usually relies on a large amount of labeled data and is severely biased towards a fixed field (such as medical care and law) for which the training is performed, and lacks cross-scene migration capability. SUMMARY
[0004] The main purpose of the embodiments of the present application is to propose a semantic vector generation method, device, equipment and storage medium to improve the accuracy of text matching in the search scenario based on the knowledge graph.
[0005] To achieve the above purpose, the first aspect of the embodiments of the present application proposes a semantic vector generation method, comprising: obtaining a fine-tuning query sentence, obtaining a CQL sentence pair corresponding to the fine-tuning query sentence from a preset knowledge graph; obtaining all node labels related to the CQL sentence pair in the knowledge graph, and obtaining a recall text according to the node labels and corresponding attribute data, taking the recall text as a positive sample, and selecting a recall text unrelated to the positive sample from the knowledge graph as a negative sample; obtaining an end identifier and a fine-tuning instruction for indicating the distinction between the positive sample and the negative sample, sequentially splicing the fine-tuning instruction, the fine-tuning query sentence, the positive sample, the negative sample and the end identifier to generate a fine-tuning sample; training a vector model using the fine-tuning sample to obtain a fine-tuning loss value, adjusting parameters of the vector model based on the fine-tuning loss value until the training is completed, obtaining a trained target vector model, and the target fine-tuning model is used for vectorization of a target query sentence to obtain a target text vector.
[0006] In some embodiments, obtaining the CQL statement pair corresponding to the fine-tuning query statement from a preset knowledge graph includes: The intent of the fine-tuned query statement is parsed to determine the query elements, which include at least the query entity, query relationship, query attribute, filtering conditions, and aggregation requirements. Graph pattern matching is performed based on the query entity and the query relationship to obtain a graph pattern clause. A filter clause is generated based on the filtering conditions. An aggregation clause is generated based on the aggregation requirements and the filter clause. An initial statement pair is obtained based on at least the graph pattern clause, the filter clause, and the aggregation clause. If the knowledge graph determines that the initial statement pair contains hallucination information, the initial statement pair is cleaned to obtain the CQL statement pair.
[0007] In some embodiments, training the vector model using the fine-tuned samples to obtain the fine-tuned loss value includes: For each training batch of fine-tuned samples, calculate the positive similarity index of the positive sample set corresponding to the fine-tuned query statement in each fine-tuned sample; The normalization factor is calculated based on the positive similarity index, and the fine-tuning loss value is calculated based on the positive similarity index and the normalization factor.
[0008] In some embodiments, calculating the positive similarity index of the positive sample set corresponding to the fine-tuning query statement in each fine-tuning sample includes: The positive samples in the fine-tuning sample are statistically analyzed according to the fine-tuning query statement to obtain at least one set of positive samples; For each positive sample in the set of positive samples, calculate the positive similarity value between the corresponding fine-tuning query statement and the positive sample. Based on the ratio between the positive similarity value and the preset temperature coefficient, obtain the positive median value. Accumulate the positive median value to obtain the positive similarity index corresponding to the set of positive samples.
[0009] In some embodiments, calculating the normalization factor based on the positive similarity index includes: The negative samples in the fine-tuning sample are statistically analyzed according to the fine-tuning query statement to obtain at least one set of negative samples. For each negative sample in the negative sample set, calculate the negative similarity value between the corresponding fine-tuning query statement and the negative sample, calculate the negative sample weight based on the negative similarity value, obtain the negative sample mask related to the negative sample in the fine-tuning query statement, calculate the ratio of the product of the negative similarity value and the negative sample weight to a preset temperature coefficient, obtain the negative median value based on the ratio and the negative sample mask, and accumulate the negative median value to obtain the negative similarity index corresponding to the negative sample set; The normalization factor is obtained based on the negative similarity index and the positive similarity index.
[0010] In some embodiments, obtaining the negative sample mask related to the negative sample in the fine-tuning query statement includes: For the negative sample, a comparison statement is selected one by one from the different fine-tuning query statements, and the statement similarity between the fine-tuning query statement and the comparison statement is calculated. If the statement similarity is not less than a preset score, and the positive sample set of the fine-tuning query statement is a proper subset of the positive sample set of the comparison statement, the negative sample mask is zero; otherwise, it is one.
[0011] In some embodiments, the calculation process of the preset score includes the following steps: The preset number of fine-tuning query statements of a certain type are uniformly sampled from the training set composed of the fine-tuning samples to obtain multiple fine-tuning samples corresponding to each fine-tuning query statement. For each of the fine-tuning query statements, the sample similarity between each pair of fine-tuning samples is calculated, and the mean of the sample similarity is calculated to obtain the statement sample mean. The average of all the statement sample means is calculated to obtain the preset score.
[0012] To achieve the above objectives, a second aspect of this application provides a semantic vector generation apparatus, comprising: Data acquisition module: used to acquire fine-tuning query statements and obtain the corresponding CQL statement pairs from a preset knowledge graph; The knowledge graph recall module is used to obtain all node labels related to the CQL statement pair in the knowledge graph, and obtain recall text based on the node labels and corresponding attribute data. The recall text is used as a positive sample, and recall texts unrelated to the positive sample are selected from the knowledge graph as negative samples. Sample construction module: used to obtain end identifier and fine-tuning instructions for distinguishing positive and negative samples, and sequentially concatenate the fine-tuning instructions, the fine-tuning query statement, the positive sample, the negative sample and the end identifier to generate fine-tuned samples; Training module: Used to train the vector model using the fine-tuning samples, obtain fine-tuning loss values, adjust the parameters of the vector model based on the fine-tuning loss values until training ends, and obtain a trained target vector model. The target fine-tuning model is used to vectorize the target query statement to obtain the target text vector.
[0013] To achieve the above objectives, a third aspect of this application provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the method described in the first aspect.
[0014] To achieve the above objectives, a fourth aspect of the present application provides a storage medium that stores a computer program, which, when executed by a processor, implements the method described in the first aspect.
[0015] The semantic vector generation method, apparatus, device, and storage medium proposed in this application embodiment obtain a fine-tuning query statement, retrieves the corresponding CQL statement pair from a preset knowledge graph, obtains all node labels related to the CQL statement pair in the knowledge graph, and obtains the recall text based on the node labels and corresponding attribute data. The recalled text is used as a positive sample, and recall text unrelated to the positive sample is selected from the knowledge graph as a negative sample. An end marker and a fine-tuning instruction used to distinguish between positive and negative samples are obtained. The fine-tuning instruction, fine-tuning query statement, positive sample, negative sample, and end marker are sequentially concatenated to generate a fine-tuning sample. The fine-tuning sample is used to train a vector model to obtain a fine-tuning loss value. Based on the fine-tuning loss value, the parameters of the vector model are adjusted until training is complete, resulting in a trained target vector model. The target fine-tuning model is used to vectorize the target query statement to obtain a target embedding vector. This application embodiment utilizes the semantic associations between entities built into the knowledge graph, using text recall with deep semantic associations with the training query statement as the basis for matching, and constructs corresponding positive and negative samples. By combining fine-tuning instructions and end markers to construct structured fine-tuning samples, annotation costs are reduced, and the sample generation logic is adaptable to different knowledge graph scenarios, avoiding the model's dependence on domain-specific labeled data. Furthermore, a vector model is used to train the fine-tuning query statement and positive / negative samples, enabling the vector model to learn semantic association patterns within the knowledge graph and quickly adapt to different knowledge graph search scenarios. This ensures that the text matching results based on the knowledge graph maintain accurate semantic information while possessing good scenario adaptability, significantly improving the accuracy of text matching in search scenarios. Attached Figure Description
[0016] Figure 1 This is a flowchart of the semantic vector generation method provided in the embodiments of this application.
[0017] Figure 2 This is a flowchart provided in an embodiment of the present application for obtaining CQL statement pairs corresponding to fine-tuning query statements from a preset knowledge graph.
[0018] Figure 3 This is a schematic diagram of the vector model provided in the embodiments of this application.
[0019] Figure 4 This is a flowchart of training a vector model using fine-tuned samples to obtain fine-tuned loss values, provided in an embodiment of this application.
[0020] Figure 5 This is a flowchart provided in an embodiment of the present application for calculating the positive similarity index of the positive sample set corresponding to the fine-tuned query statement in each fine-tuned sample.
[0021] Figure 6 This is a flowchart of calculating the normalization factor based on the positive similarity index provided in the embodiments of this application.
[0022] Figure 7 This is a schematic diagram of the calculation process of the preset score provided in the embodiments of this application.
[0023] Figure 8 This is an overall flowchart of the semantic matching method provided in the embodiments of this application.
[0024] Figure 9 This is a block diagram of a semantic vector generation device provided in another embodiment of this application.
[0025] Figure 10 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0026] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0027] It should be noted that although functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart.
[0028] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0029] First, let's analyze some of the terms used in this application: Artificial Intelligence (AI) is a new branch of computer science that studies, develops, and applies theories, methods, technologies, and systems to simulate, extend, and expand human intelligence. It aims to understand the essence of intelligence and produce intelligent machines that can react in a way similar to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing, and expert systems. AI can simulate the information processes of human consciousness and thought. Furthermore, AI utilizes digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceiving the environment, acquiring knowledge, and using that knowledge to achieve optimal results.
[0030] In knowledge graph-based AI search, large models rely on external knowledge graphs to answer user questions, addressing the "illusion" problem of general-purpose large models. However, knowledge graphs contain vast amounts of information; inputting all of it into the model results in excessively long contexts, low computational efficiency, and semantic redundancy. Therefore, it's necessary to accurately retrieve nodes and relationships relevant to the user's question from the knowledge graph, constructing localized information focused on the query requirements to improve answer accuracy and response efficiency. Matching user questions with knowledge graphs presents two main challenges: user questions are not fixed, containing numerous synonyms and sentence structures; and knowledge graphs are not fixed, changing frequently with business needs.
[0031] Matching methods in related technologies are mainly divided into two categories: one is sparse matching based on the BM25 algorithm. This method calculates the similarity score of text pairs using term frequency (TF) and inverse document frequency (IDF), and selects the text with the highest similarity as the matching result. However, this method relies on term frequency statistics and cannot effectively handle synonyms and semantic associations. For example, it is difficult to identify the semantic relevance between "swipe card" and "attendance". The other category is semantic matching based on deep learning (such as the BERT model). It uses pre-trained models such as Word2Vec, GloVe, and BERT to convert text into vector representations, thereby capturing the semantics and contextual relationships of the text, and then calculates the similarity score of vector pairs to obtain the optimal matching text. Although this type of method can effectively capture semantic information, it usually relies on a large amount of labeled data and is heavily biased towards the fixed domains it is trained on, such as medicine and law, lacking cross-scenario transferability. Furthermore, the nodes and relationships of knowledge graphs change frequently with business needs and involve a wide range of scenarios, requiring frequent fine-tuning of data. Therefore, the application of deep learning-based semantic matching models is difficult.
[0032] Based on this, embodiments of this application provide a semantic vector generation method, apparatus, device, and storage medium. By leveraging the semantic relationships between entities built into a knowledge graph, text with deep semantic connections to the training query statement is retrieved as the basis for matching, constructing corresponding positive and negative samples. Structured fine-tuning samples are constructed by combining fine-tuning instructions and end markers, reducing annotation costs. Furthermore, the sample generation logic is adaptable to different knowledge graph scenarios, avoiding model dependence on domain-specific annotation data. The fine-tuning query statement and positive / negative samples are then vectorized and trained using a vector model, enabling the vector model to learn the semantic relationship patterns in the knowledge graph and quickly adapt to different knowledge graph search scenarios. This ensures that the text matching results based on the knowledge graph maintain accurate semantic information while possessing good scenario adaptability, significantly improving the accuracy of text matching in search scenarios.
[0033] This application provides a semantic vector generation method, apparatus, device, and storage medium, which are specifically described through the following embodiments. First, the semantic vector generation method in this application is described.
[0034] This application's embodiments can acquire and process relevant data based on artificial intelligence (AI) technology. AI is the theory, methods, technology, and application system that uses digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results. In other words, AI is a comprehensive technology within computer science that attempts to understand the essence of intelligence and produce a new type of intelligent machine that can react in a way similar to human intelligence. AI also studies the design principles and implementation methods of various intelligent machines, enabling them to possess perception, reasoning, and decision-making capabilities.
[0035] Artificial intelligence (AI) is a comprehensive discipline encompassing a wide range of fields, including both hardware and software technologies. Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies primarily include computer vision, speech processing, natural language processing, and machine learning / deep learning.
[0036] The semantic vector generation method provided in this application relates to the field of vector matching technology. This method can be applied to a terminal, a server, or a computer program running on either the terminal or the server. For example, the computer program can be a native program or software module in an operating system; it can be a native application (APP), i.e., a program that needs to be installed in the operating system to run, such as a client that supports semantic vector generation, i.e., a program that only needs to be downloaded to a browser environment to run; or it can be a small program that can be embedded in any APP. In short, the above-mentioned computer program can be any form of application, module, or plugin. The terminal communicates with the server via a network. The semantic vector generation method can be executed by the terminal or the server, or by the terminal and the server working together.
[0037] In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, or smartwatch, etc. Additionally, the terminal can also be a smart in-vehicle device. This smart in-vehicle device uses the semantic vector generation method of this embodiment to provide related services and enhance the driving experience. The server can be an independent server, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms; it can also be a service node in a blockchain system, where the service nodes form a peer-to-peer (P2P) network. The P2P protocol is an application layer protocol running on top of the Transmission Control Protocol (TCP). The terminal and server can connect via Bluetooth, Universal Serial Bus (USB), or network communication methods; this embodiment does not impose any limitations.
[0038] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0039] The semantic vector generation method in the embodiments of this application is described below.
[0040] Figure 1 This is an optional flowchart of the semantic vector generation method provided in the embodiments of this application. Figure 1 The method may include, but is not limited to, steps 110 to 140. It is also understood that this embodiment... Figure 1 The order of steps 110 to 140 is not specifically limited. The order of steps can be adjusted or some steps can be reduced or added according to actual needs.
[0041] Step 110: Obtain the fine-tuning query statement. Obtain the CQL statement pair corresponding to the fine-tuning query statement from the preset knowledge graph.
[0042] In one embodiment, fine-tuned natural language query statements are constructed based on actual application scenarios, such as "Search the knowledge graph to find how many people have a taxable salary exceeding 600,000 in 24 years" or "Search the knowledge graph to find how many users who purchased a mobile phone also purchased a phone case and charger." In this case, the knowledge graph is also pre-obtained based on the actual application scenarios.
[0043] In one embodiment, reference is made to Figure 2 , Figure 2 This is a flowchart provided in this application embodiment for obtaining CQL statement pairs corresponding to fine-tuning query statements from a preset knowledge graph, specifically including the following steps: Step 210: Perform intent parsing on the fine-tuning query statement to determine the query elements.
[0044] In one embodiment, a pre-trained neural network model is used to perform intent parsing on the fine-tuned query statement to determine the query elements, wherein the query elements include at least query entities, query relationships, query attributes, filtering conditions, and aggregation requirements.
[0045] For example, for the fine-tuned query "Query the knowledge graph to find how many people have a taxable salary exceeding 600,000 in 24 years," intent analysis reveals the following: The query entities are salary details and personnel, corresponding to the node labels Pay_detail and Employee in the knowledge graph. The query relationship is salary details belonging to personnel, specifically the edge label connecting Pay_detail and Employee in the knowledge graph: PAY_DETAIL_BELONG_EMPLOYEE. The query attributes are taxable salary, time, and personnel ID, which are respectively the attribute data taxable_salary of the Pay_detail node, the attribute data year_month of the Pay_detail node, and the attribute data employee_no of the Employee node in the knowledge graph. The filtering criteria include time-based filtering and numerical filtering. Time-based filtering requires that `year_month` belongs to 2024 (i.e., `year_month>='2024-01' AND year_month<='2024-12'). Numerical filtering requires that the cumulative taxable salary in 2024 exceeds 600,000 (i.e., `SUM(taxable_salary)>600,000`). The aggregation requirement is to count the number of independent individuals meeting the criteria, which can be represented as `COUNT(DISTINCT employee_no)`. It's understandable that query nodes and attributes can be described in natural language, and corresponding node labels and attribute data can be found in the knowledge graph.
[0046] Step 220: Perform graph pattern matching based on the query entity and query relationship to obtain graph pattern clauses, generate filter clauses based on the filtering conditions, generate aggregation clauses based on the aggregation requirements and filter clauses, and obtain an initial statement pair based on at least the graph pattern clauses, filter clauses, and aggregation clauses.
[0047] In one embodiment, the initial statement pair is a Cypher statement, which serves as the corresponding carrier of "natural language query intent" and "graph query language (Cypher)". Therefore, clauses can be generated step by step according to the logic of graph pattern, filtering and aggregation, and finally assembled into a complete initial statement pair.
[0048] In one embodiment, graph pattern matching is performed based on the query entity and query relationship to obtain a graph pattern clause. As in the example above, the corresponding "node-edge-node" structure can be matched in the knowledge graph based on the query entity (Pay_detail, Employee) and query relationship (PAY_DETAIL_BELONG_EMPLOYEE) to ensure that the query scope does not deviate from the association relationship. The final graph pattern clause is represented as: MATCH(pd:Pay_detail)-[:PAY_DETAIL_BELONG_EMPLOYEE]->(e:Employee).
[0049] Next, filter clauses are generated based on the filtering criteria. As in the example above, the filtering criteria are converted into Cypher's WHERE clause. Since there are two filtering criteria, a layered approach is needed. The first layer targets a single record in the Pay_detail node, and the next layer aggregates multiple salary details for the same person. The resulting filter clause is expressed as: WHERE pd.year_month>='2024-01' AND pd.year_month<='2024-12' WITH e.employee_no AS employee_no, e.employee_name AS employee_name,SUM(pd.taxable_salary) AS total_taxable_salary WHERE total_taxable_salary>600000.
[0050] Similarly, aggregation clauses are generated based on aggregation requirements and filtering clauses. As in the example above, a RETURN clause is generated based on the aggregation requirements and the filtered intermediate results. A DISTINCT clause is added to prevent duplicate counting of the same person, and a LIMIT clause controls the amount of data returned to prevent query timeouts due to excessive data volume. The resulting aggregation clause is expressed as: RETURN DISTINCT COUNT (DISTINCTemployee_no) AS total_employees LIMIT100.
[0051] Then, based on at least the graph pattern clause, filter clause, and aggregation clause, the initial statement pair is obtained, represented as: MATCH(pd:Pay_detail)-[:PAY_DETAIL_BELONG_EMPLOYEE]->(e:Employee) WHERE pd.year_month>='2024-01' AND pd.year_month<='2024-12' WITH e.employee_no AS employee_no, e.employee_name AS employee_name,SUM(pd.taxable_salary) AS total_taxable_salary WHERE total_taxable_salary>600000 RETURN DISTINCT COUNT (DISTINCTemployee_no) AS total_employees LIMIT100.
[0052] Step 230: If the initial statement pair is determined to contain hallucination information based on the knowledge graph, perform data cleaning on the initial statement pair to obtain CQL statement pairs.
[0053] In one embodiment, illusory information refers to content in the initial statement that does not match the actual nodes, relationships, data, etc. of the knowledge graph. For example, non-existent node labels, attribute names, relationship labels, or logically contradictory filtering conditions can all be called illusory information. Therefore, it is necessary to combine the metadata of the knowledge graph, such as the node attribute dictionary, the relationship type list, etc., to detect and correct the initial statement pair, and finally obtain an executable CQL statement pair.
[0054] For example, the actual metadata of a knowledge graph is as follows: The Pay_detail node's year_month attribute is in the format 'YYYY-MM' (e.g., '2024-03'), and the taxable_salary attribute is a numeric type (unit: yuan). The Employee node's employee_no attribute is a unique identifier without duplicates, and the employee_name attribute is not stored for privacy protection.
[0055] After examining the initial statement pair, the following illusion was found: the Employee node does not have an employee_name attribute. Therefore, e.employee_name AS employee_name in the initial statement pair is a "reference to a non-existent attribute," which will cause a query error. Therefore, targeted data cleaning is needed, removing e.employee_name AS employee_name from the WITH clause, because the corresponding attribute does not exist, and the employee name is not required for counting the number of people.
[0056] By filtering out statements containing illusions based on the knowledge graph through the above process, the quality of the fine-tuning dataset for the vector model can be improved.
[0057] Step 120: Obtain all node labels related to CQL statement pairs in the knowledge graph, and obtain the recall text based on the node labels and corresponding attribute data. Use the recall text as positive samples, and select recall texts that are unrelated to the positive samples from the knowledge graph as negative samples.
[0058] In one embodiment, after obtaining executable CQL statement pairs, triple data for model training is constructed, with each triple data set fine-tuning the query statement, positive samples, and negative samples.
[0059] First, based on the determined node labels, the attribute data of the corresponding nodes is queried in the knowledge graph. For example, the node label "Pay_detail" might contain attribute data such as "year_month" and "taxable_salary," while the node label "Employee" might contain attribute data such as "employee_no" and "employee_name." Then, with the attribute data, the node labels and their attribute data can be combined into text to serve as the recall text. For example, the text "Employee [employee_name] with employee number [employee_no] had a taxable salary of [total_taxable_salary] in 2024" could be used as the recall text.
[0060] Next, the recall text generated from the node labels and attribute data related to the CQL statement is directly related to the user's query intent. It is information with clear semantics that is accurately recalled from the knowledge graph, and therefore it is used as a positive sample. At the same time, recall text unrelated to the positive samples is selected from the knowledge graph as negative samples to help the vector model identify information patterns that are not related to the user's query intent, thereby improving the model's ability to filter irrelevant information.
[0061] In one embodiment, negative samples can be obtained through random selection or distance-based methods. Random sampling involves randomly selecting nodes and attribute data from the knowledge graph to generate text unrelated to the positive sample's topic as negative samples. For example, if the positive sample is about employee salaries, nodes and attribute data related to company product information in the knowledge graph can be randomly selected to generate negative samples such as "the model of product [product_name] is [product_model]". Distance-based methods utilize the graph structure information in the knowledge graph to select nodes and attribute data that are far from the nodes in the positive sample to generate negative samples. For example, a shortest path algorithm can be used to calculate nodes whose shortest path to the positive sample nodes is greater than a certain threshold, and then negative samples can be generated based on these nodes.
[0062] In yet another embodiment, the node information of the #Neo4j graph database is as follows: ##Employee EDUCATIÓN: Highest degree CONTAINS ##Pay_detail - Employee Salary Payment Details absenteeism_deduction: Deduction for absenteeism, float … The relational information for the #Neo4j graph database is as follows: 1. PAY_DETAIL_BELONG_EMPLOYEE Description: {Employee salary payment details} The object is (employees) Relationship pointer: (Employee salary payment details) -> (Employee) or (Employee) <- (Employee salary payment details) 2. … The recall information for Neo4j graph database nodes, i.e., the positive samples, is as follows: ##Employee Employee fields: EDUCATION, Highest Education Level ##Pay_detail - Employee Salary Payment Details Fields in employee payroll details: absenteeism_deduction, deduction for unauthorized absences. … A large amount of triplet data is generated in the above way.
[0063] In one embodiment, after obtaining the triplet data, data cleaning is required. If a CQL statement pair contains statements without any nodes or relations, the number of positive samples will be 0. Since fine-tuning data requires that every triplet contain positive samples, any triplet with a positive sample count of 0 needs to be removed. The above steps are repeated until a high-quality fine-tuning dataset for the vector model is obtained, where a single triplet is represented as: "Search the knowledge graph to see how many people have a taxable salary exceeding 600,000 over 24 years": { "pos": ["Employee fields: employee_no, employee number", "Employee fields: employee_name, name", Fields in employee salary payment details: year_month, year and month to which the salary belongs. "Fields in employee salary payment details: taxable_salary, taxable wages", Description: The object {Employee Salary Payment Details} is {Employee}. The relationship is: (Employee Salary Payment Details) -> (Employee) or (Employee) <- (Employee Salary Payment Details). "neg": ["Employee fields: cost_center, Company", "Employee fields: admission_date, departure date", Fields in employee salary payment details: absenteeism_deduction, deduction for absenteeism. Fields in employee salary payment details: other_allowance, other allowances. Description: {Employee Salary Payment Details} belongs to the {Department}\nRelationship: (Employee Salary Payment Details)->(Department)<-(Employee Salary Payment Details)", "Description: The {Employee Compensation Rule} object is {Employee} and the octet points to: (Employee Compensation Rule) -> (Employee) or (Employee) <- (Employee Compensation Rule)"]}.
[0064] Step 130: Obtain the end marker and the fine-tuning instructions used to distinguish between positive and negative samples. Sequentially concatenate the fine-tuning instructions, fine-tuning query statements, positive samples, negative samples, and end marker to generate fine-tuned samples.
[0065] In one embodiment, the purpose of the end marker is to define a clear boundary for the fine-tuning sample, so as to avoid content confusion between different samples during model training. A unique symbol or text sequence that is not easily repeated with the sample content can be used, such as "[EOS]". Using such a clear marker, the vector model can quickly identify the termination position of each fine-tuning sample, thereby improving the data reading efficiency during training.
[0066] Furthermore, the fine-tuning instruction is used to instruct the vector model to distinguish between positive and negative samples during training. Therefore, the corresponding fine-tuning instruction could be "find the most similar text for this question" or "identify the correlation between the fine-tuning query and positive samples, while excluding the interference of negative samples." The fine-tuning instruction here can be set according to the actual situation, and this embodiment does not limit it.
[0067] In one embodiment, after determining the end marker and fine-tuning instruction, the fine-tuning instruction, fine-tuning query statement, positive sample, negative sample, and end marker are concatenated in sequence to generate a complete fine-tuning sample. Whether adding a new query scenario or expanding the sample size, the consistency of the sample format is maintained, reducing the complexity of data preprocessing. This embodiment enables the vector model to learn the association features between the fine-tuning query statement and positive samples more efficiently, strengthens the ability to exclude negative samples, and improves the semantic matching accuracy and irrelevant information filtering efficiency of the model in practical applications. Simultaneously, since the fine-tuning sample contains the fine-tuning query statement, positive samples (text related to knowledge graph nodes), and negative samples (text related to irrelevant nodes), the vector model can fully learn the data features of real query scenarios during training, more accurately recall relevant data in the knowledge graph, and reduce interference from irrelevant results.
[0068] Step 140: Train the vector model using fine-tuning samples to obtain fine-tuning loss values. Adjust the parameters of the vector model based on the fine-tuning loss values until training is complete, and obtain the trained target vector model. The target fine-tuning model is used to vectorize the target query statement to obtain the text embedding vector.
[0069] In one embodiment, reference is made to Figure 3 , Figure 3 This is a schematic diagram of the vector model provided in an embodiment of this application. The vector model is a pre-trained language model, specifically the Qwen3-Embedding model. Its input data consists of fine-tuning samples composed of fine-tuning instructions, fine-tuning query statements, positive samples, negative samples, and end markers. The vector model sequentially includes a causal language model, a pooling layer, and a normalization layer; specifically, the causal language model can be the Qwen3 model.
[0070] During fine-tuning, the causal language model receives structured fine-tuning samples as input. A Transformer encoder encodes the text sequence token-by-token, generating a context-dependent vector for each token. This generates word vectors for the hidden layers. When predicting the next word, the causal language model relies on the encoding information of the preceding words. Therefore, when predicting the last word, its hidden state has already encoded information from all preceding words. Then, a pooling layer aggregates the token vectors. The pooling strategy can be either mean pooling or clstoken pooling. Therefore, the pooling strategy selects the hidden layer output corresponding to the [EOS] end marker as the text embedding vector. The pooling layer compresses the high-dimensional token vector matrix into a fixed-dimensional overall vector, preserving the global semantic features of the fine-tuning samples while reducing subsequent computational complexity. However, the overall vector output after the pooling layer may have large numerical range differences and uneven distribution, which can affect the accuracy of the vector model's vector similarity calculation. Finally, after normalization, the output is a 1024-dimensional text embedding vector within the same range. The normalization layer adopts the L2 normalization strategy, which divides the pooled vector by its L2 norm to make the magnitude of the final output vector equal to the norm of the L2 norm. This eliminates the interference of vector magnitude differences on similarity calculation and improves the accuracy and stability of the vector model in semantic matching tasks.
[0071] The specific training process is described below. In related technologies, the loss functions used in the fine-tuning process of large vector models include cosine similarity loss, contrastive loss, and online contrastive loss. These loss functions are all supervised learning losses, therefore requiring annotation to distinguish between the question and positive / negative sample pairs, making them unsuitable for large-scale data training. Furthermore, the loss calculation uses distance calculation, which is relatively simple and unsuitable for complex data scenarios. Therefore, this application's embodiment, to be suitable for large-scale data training, adopts a self-supervised learning training process. This process does not rely on the annotation information of the fine-tuned samples, and can more effectively capture the relationship between the fine-tuned query and positive / negative samples, making it suitable for complex data learning processes.
[0072] In one embodiment, reference is made to Figure 4 , Figure 4 This is a flowchart provided in this application embodiment for training a vector model using fine-tuned samples to obtain fine-tuned loss values, specifically including the following steps: Step 410: For a training batch of fine-tuned samples, calculate the positive similarity index of the positive sample set corresponding to the fine-tuned query statement in each fine-tuned sample.
[0073] In one embodiment, reference is made to Figure 5 , Figure 5 This is a flowchart illustrating the calculation of the positive similarity index of the positive sample set corresponding to the fine-tuned query statement in each fine-tuned sample, provided in an embodiment of this application. The flowchart specifically includes the following steps: Step 510: Perform statistics on the positive samples in the fine-tuning sample according to the fine-tuning query statement to obtain at least one set of positive samples.
[0074] In one embodiment, it is assumed that the number of fine-tuning query questions in a training batch of fine-tuning samples is a preset number of types N, wherein each fine-tuning query question has at least one positive sample and at least one negative sample, the positive samples constitute a positive sample set, and the negative samples constitute a negative sample set.
[0075] Step 520: For each positive sample in the positive sample set, calculate the positive similarity value between the corresponding fine-tuning query statement and the positive sample. Based on the ratio between the positive similarity value and the preset temperature coefficient, obtain the positive median value. Accumulate the positive median value to obtain the positive similarity index corresponding to the positive sample set.
[0076] In one embodiment, since the fine-tuning dataset is derived from CQL statements, it is easy for the similarity scores between the fine-tuning query and the positive samples to be extremely low, while the similarity scores between the positive samples differ significantly, leading to gradient oscillations during the fine-tuning process. Therefore, to avoid drastic changes during the training process, the similarity calculation is performed on all positive samples of a single question when calculating the loss value for fine-tuning.
[0077] Specifically, for each positive sample in the positive sample set, the positive similarity value between the corresponding fine-tuning query and each positive sample is calculated. For example, for the i-th fine-tuning query... The s-th positive sample in the corresponding positive sample set is The corresponding positive similarity value is expressed as .
[0078] Next, based on the positive similarity value and the preset temperature coefficient The ratio between them is expressed as the exact midpoint:
[0079] The preset temperature coefficient is used to control the smoothness of the similarity score.
[0080] Next, summing the positive median values yields the positive similarity index corresponding to the set of positive samples, denoted as:
[0081] in, Let represent the positive similarity index corresponding to the i-th positive sample set.
[0082] Step 420: Calculate the normalization factor based on the positive similarity index, and calculate the fine-tuning loss value based on the positive similarity index and the normalization factor.
[0083] In one embodiment, reference is made to Figure 6 ,Figure 6 This is a flowchart of calculating the normalization factor based on the positive similarity index provided in the embodiments of this application, which specifically includes the following steps: Step 610: Statistically analyze the negative samples in the fine-tuning sample according to the fine-tuning query statement to obtain at least one set of negative samples.
[0084] Step 620: For each negative sample in the negative sample set, calculate the negative similarity value between the corresponding fine-tuning query statement and the negative sample, calculate the negative sample weight based on the negative similarity value, obtain the negative sample mask related to the fine-tuning query statement and the negative sample, calculate the ratio of the product of the negative similarity value and the negative sample weight to the preset temperature coefficient, obtain the negative median value based on the ratio and the negative sample mask, and accumulate the negative median values to obtain the negative similarity index corresponding to the negative sample set.
[0085] In one embodiment, the i-th fine-tuning query statement The s-th negative sample in its corresponding negative sample set is The corresponding negative similarity value is represented as Then, the negative sample weights are calculated based on the negative similarity values. Represented as:
[0086] In the fine-tuning dataset, the recalled text obtained through nodes and attributes is used as positive samples, while the recalled text of the remaining attributes of the nodes is used as negative samples. It is possible that some fine-tuning queries and negative samples may have very high similarity scores, even higher than other types of positive samples in the same query, which are difficult for vector models to distinguish. Therefore, in the calculation of the fine-tuning loss value in this application embodiment, a negative sample weight value is added to strengthen the focus on difficult negative samples and improve the model's ability to distinguish them.
[0087] Next, we obtain the mask of negative samples related to the fine-tuning query statement. Specifically, for each negative sample, we select a comparison statement from different fine-tuning queries. This comparison statement is one that is related to the current fine-tuning query statement. Different fine-tuning query statements, for example, fine-tuning query statements Then, the similarity between the fine-tuning query and the comparison query is calculated. If the similarity between the statements is not less than the preset score and the set of positive samples of the fine-tuned query statement is a proper subset of the set of positive samples of the comparison statement, the negative sample mask is zero; otherwise, it is one.
[0088] In one embodiment, reference is made to Figure 7 , Figure 7 This is a schematic diagram of the calculation process of the preset score provided in the embodiments of this application, including the following steps: Step 710: Uniformly sample a preset number of fine-tuning query statements from the training set consisting of fine-tuning samples to obtain multiple fine-tuning samples corresponding to each fine-tuning query statement.
[0089] In one embodiment, each fine-tuning query statement is uniformly sampled from the training set consisting of fine-tuning samples to ensure a balanced number of fine-tuning samples for each question type, avoiding model training bias due to an excessive number of samples of one type. This results in a preset number of sample sets of different types, each corresponding to a fine-tuning query statement, and each sample set containing T fine-tuning samples, where T is at least one.
[0090] Step 720: For each fine-tuning query statement, calculate the sample similarity between pairs of fine-tuning samples, and calculate the mean of the sample similarity to obtain the statement sample mean. Calculate the average of all statement sample means to obtain the preset score.
[0091] In one embodiment, for the first A set of samples, with two fine-tuned samples and The corresponding sample similarity is The corresponding sample mean of the statements is expressed as: Therefore, the preset score is expressed as:
[0092] in, Let represent the number of combinations, which is the number of combinations of choosing 2 from T problems.
[0093] With the preset scores, the next step is to determine whether the positive sample set of the fine-tuning query is a proper subset of the positive sample set of the alignment query. In other words, the positive sample set of the fine-tuning query needs to be smaller than the positive sample set of the alignment query. This determination process is expressed as follows:
[0094] in, This represents the set of positive samples for fine-tuning the query statement. The diff function represents the set of positive samples in the comparison statement and is used to determine... Is it? The proper subset of .
[0095] Therefore, the i-th fine-tuning query statement The s-th negative sample in its corresponding negative sample set The negative sample mask is represented as:
[0096] in, This represents a negative sample mask, used to remove the influence of false negative samples.
[0097] Then, the ratio of the product of the negative similarity value and the negative sample weight to the preset temperature coefficient is calculated and expressed as:
[0098] Then, based on the ratio and the negative sample mask, the negative median value is obtained, expressed as:
[0099] The negative similarity index corresponding to the negative sample set is obtained by summing the negative median values, and is expressed as:
[0100] Where K represents the number of negative samples in the negative sample set.
[0101] Step 630: Obtain the normalization factor based on the negative similarity index and the positive similarity index.
[0102] In one embodiment, the normalization factor for the i-th fine-tuning query statement is expressed as:
[0103] With the normalization factor, the fine-tuning loss value L calculated based on the positive similarity index and the normalization factor is expressed as:
[0104] In one embodiment, since the purpose of fine-tuning the vector model is to calculate the similarity scores between the fine-tuned query statement, i.e., the user question and the positive and negative samples, to ensure that the positive sample scores are high and the negative sample scores are low, effectively distinguishing the difficult negative samples corresponding to the question and reducing false recall, it can be seen that the above-mentioned fine-tuning loss value is more in line with the business scenario based on knowledge graph, and can effectively improve the vector model's distinction of difficult negative samples, increase the positive sample score, and reduce the negative sample score.
[0105] The fine-tuning loss value is calculated through the above process. This loss value is then used to adjust the parameters of the vector model until training is complete, resulting in the trained vector model, i.e., the target vector model. At this point, during inference, the model parameters of the vector model are fixed. Its specific task is no longer learning, but generating a high-quality, semantic target text vector for any possible input target query. This allows for full utilization of the semantic and contextual information of the text when calculating vector pair similarity.
[0106] In one embodiment, a trained vector model is used to generate an embedding vector for a specific user question. The input format can be: "Find the most similar text for this question + [the user's specific question]", for example: "Find the most similar text for this question by searching the knowledge graph for the number of people whose taxable salary for 24 years exceeds 600,000". Then, a 1024-dimensional normalized vector, i.e., the target text vector, is output, which encodes the deep semantics of the user question.
[0107] Alternatively, a pre-trained vector model can be used to generate corresponding embedding vectors for the knowledge graph text and store them in a database. Then, all candidate texts in the knowledge graph can be pre-converted into vectors and stored in a vector database to build an index, such as Milvus, Chroma, or Pinecone. Understandably, this operation can be performed offline in batches.
[0108] In one embodiment, reference is made to Figure 8 , Figure 8 This is an overall flowchart of the semantic matching method provided in this application embodiment. First, a fine-tuning query statement and a preset knowledge graph are obtained. An initial statement pair corresponding to the fine-tuning query statement is obtained from the preset knowledge graph. After data cleaning, CQL statement pairs are obtained. Next, an end marker and a fine-tuning instruction used to distinguish between positive and negative samples are obtained. The fine-tuning instruction, fine-tuning query statement, positive sample, negative sample, and end marker are sequentially concatenated to generate fine-tuning samples. Simultaneously, fine-tuning samples that do not contain positive samples are cleaned to obtain a fine-tuning dataset. Next, the vector model is trained using the fine-tuning samples in the fine-tuning dataset to obtain a fine-tuning loss value. Based on the fine-tuning loss value, the parameters of the vector model are adjusted until training is complete, resulting in a trained target vector model.
[0109] In one embodiment, since general-purpose vector models are difficult to meet accuracy requirements, the semantic vector generation method of this application trains the vector model to improve the recall rate of nodes and relationships in the knowledge graph. At this time, the general-purpose vector model, after being trained with fine-tuned samples, has rich pre-trained knowledge, strong versatility, and strong cross-domain transfer capabilities. It can effectively solve scenarios with diverse user questions and flexible and ever-changing knowledge graphs, and possesses a more refined semantic understanding capability for fine-tuning scenarios. To improve fine-tuning efficiency, a fine-tuning dataset is automatically constructed using CQL statement pairs. After fine-tuning, the target vector model has strong semantic understanding and generalization capabilities, shortens the contextual information length of downstream tasks, improves the recall and precision of knowledge graph nodes and relationships, solves the problem of high scenario limitations of deep learning-based semantic matching methods, meets the business needs of frequently changing knowledge graphs and broad scenarios in search scenarios, thereby improving the accuracy of downstream tasks.
[0110] The technical solution provided in this application involves obtaining a fine-tuning query statement, retrieving the corresponding CQL statement pair from a preset knowledge graph, obtaining all node labels related to the CQL statement pair in the knowledge graph, and obtaining the recall text based on the node labels and corresponding attribute data. The recalled text is used as a positive sample, and recall text unrelated to the positive sample is selected from the knowledge graph as a negative sample. An end marker and a fine-tuning instruction used to distinguish between positive and negative samples are obtained. The fine-tuning instruction, fine-tuning query statement, positive sample, negative sample, and end marker are sequentially concatenated to generate a fine-tuning sample. The fine-tuning sample is used to train a vector model to obtain a fine-tuning loss value. Based on the fine-tuning loss value, the parameters of the vector model are adjusted until training is complete, resulting in a trained target vector model. The target fine-tuning model is used to vectorize the target query statement to obtain a text embedding vector. This application embodiment utilizes the semantic relationships between entities built into the knowledge graph, using text recall with deep semantic relationships to the training query statement as the basis for matching, and constructing corresponding positive and negative samples. By combining fine-tuning instructions and end markers to construct structured fine-tuning samples, annotation costs are reduced, and the sample generation logic is adaptable to different knowledge graph scenarios, avoiding the model's dependence on domain-specific labeled data. Furthermore, a vector model is used to train the fine-tuning query statement and positive / negative samples, enabling the vector model to learn semantic association patterns within the knowledge graph and quickly adapt to different knowledge graph search scenarios. This ensures that the text matching results based on the knowledge graph maintain accurate semantic information while possessing good scenario adaptability, significantly improving the accuracy of text matching in search scenarios.
[0111] This application also provides a semantic vector generation apparatus that can implement the above-described semantic vector generation method, referring to... Figure 9 The device includes: Data acquisition module 910: Used to acquire fine-tuning query statements and obtain the corresponding CQL statement pairs from the preset knowledge graph.
[0112] Graph Recall Module 920: Used to obtain all node labels related to CQL statement pairs in the knowledge graph, and obtain recall text based on node labels and corresponding attribute data. The recalled text is used as a positive sample, and recall texts unrelated to the positive samples are selected from the knowledge graph as negative samples.
[0113] Sample construction module 930: used to obtain the end identifier and the fine-tuning instructions for distinguishing between positive and negative samples, and to sequentially concatenate the fine-tuning instructions, fine-tuning query statements, positive samples, negative samples and end identifier to generate fine-tuned samples.
[0114] Training module 940: Used to train the vector model using fine-tuning samples, obtain fine-tuning loss values, adjust the parameters of the vector model based on the fine-tuning loss values until the training is completed, and obtain the trained target vector model. The target fine-tuning model is used to vectorize the target query statement to obtain the target text vector.
[0115] The specific implementation of the semantic vector generation device in this embodiment is basically the same as the specific implementation of the semantic vector generation method described above, and will not be repeated here.
[0116] This application also provides an electronic device, including: At least one memory; At least one processor; At least one program; The program is stored in a memory, and the processor executes the at least one program to implement the semantic vector generation method described above. The electronic device can be any smart terminal, including mobile phones, tablets, personal digital assistants (PDAs), and in-vehicle computers.
[0117] Please see Figure 10 , Figure 10 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes: The processor 1001 can be implemented using a general-purpose central processing unit (CPU), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application. The memory 1002 can be implemented as a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1002 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1002 and is called and executed by the processor 1001 using the semantic vector generation method of the embodiments of this application. Input / output interface 1003 is used to implement information input and output; The communication interface 1004 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.). Bus 1005 transmits information between various components of the device (e.g., processor 1001, memory 1002, input / output interface 1003, and communication interface 1004); The processor 1001, memory 1002, input / output interface 1003 and communication interface 1004 are connected to each other within the device via bus 1005.
[0118] This application embodiment also provides a storage medium that stores a computer program, which, when executed by a processor, implements the above-described semantic vector generation method.
[0119] Memory, as a non-transitory storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0120] The semantic vector generation method, apparatus, device, and storage medium proposed in this application involve obtaining a fine-tuning query statement, retrieving the corresponding CQL statement pair from a preset knowledge graph, obtaining all node labels related to the CQL statement pair in the knowledge graph, obtaining recall text based on the node labels and corresponding attribute data, using the recall text as positive samples, selecting recall text unrelated to the positive samples as negative samples from the knowledge graph, obtaining an end marker and a fine-tuning instruction to distinguish between positive and negative samples, sequentially concatenating the fine-tuning instruction, fine-tuning query statement, positive samples, negative samples, and end marker to generate fine-tuning samples, training a vector model using the fine-tuning samples to obtain a fine-tuning loss value, adjusting the parameters of the vector model based on the fine-tuning loss value until training is complete, obtaining a trained target vector model, and using the target fine-tuning model to vectorize the target query statement to obtain a text embedding vector. This application embodiment utilizes the semantic relationships between entities built into the knowledge graph, using text recall with deep semantic relationships to the training query statement as the basis for matching, and constructing corresponding positive and negative samples. By combining fine-tuning instructions and end markers to construct structured fine-tuning samples, annotation costs are reduced, and the sample generation logic is adaptable to different knowledge graph scenarios, avoiding the model's dependence on domain-specific labeled data. Furthermore, a vector model is used to train the fine-tuning query statement and positive / negative samples, enabling the vector model to learn semantic association patterns within the knowledge graph and quickly adapt to different knowledge graph search scenarios. This ensures that the text matching results based on the knowledge graph maintain accurate semantic information while possessing good scenario adaptability, significantly improving the accuracy of text matching in search scenarios.
[0121] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0122] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0123] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0124] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0125] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0126] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0127] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0128] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0129] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0130] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0131] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.
Claims
1. A semantic vector generation method, characterized in that, include: Obtain the fine-tuning query statement and retrieve the corresponding CQL statement pair from the preset knowledge graph; Obtain all node labels related to the CQL statement pair in the knowledge graph, and obtain the recall text based on the node labels and corresponding attribute data. Use the recall text as a positive sample, and select recall texts that are unrelated to the positive sample from the knowledge graph as negative samples. Obtain the end identifier and the fine-tuning instruction used to distinguish between positive and negative samples, and sequentially concatenate the fine-tuning instruction, the fine-tuning query statement, the positive sample, the negative sample, and the end identifier to generate a fine-tuned sample; The vector model is trained using the fine-tuned samples to obtain a fine-tuning loss value. The parameters of the vector model are adjusted based on the fine-tuning loss value until the training is completed, resulting in a trained target vector model. The target fine-tuning model is used to vectorize the target query statement to obtain the target text vector.
2. The semantic vector generation method according to claim 1, characterized in that, The step of obtaining the CQL statement pair corresponding to the fine-tuning query statement from the preset knowledge graph includes: The intent of the fine-tuned query statement is parsed to determine the query elements, which include at least the query entity, query relationship, query attribute, filtering conditions, and aggregation requirements. Graph pattern matching is performed based on the query entity and the query relationship to obtain a graph pattern clause. A filter clause is generated based on the filtering conditions. An aggregation clause is generated based on the aggregation requirements and the filter clause. An initial statement pair is obtained based on at least the graph pattern clause, the filter clause, and the aggregation clause. If the knowledge graph determines that the initial statement pair contains hallucination information, the initial statement pair is cleaned to obtain the CQL statement pair.
3. The semantic vector generation method according to claim 1, characterized in that, The step of training the vector model using the fine-tuned samples to obtain the fine-tuning loss value includes: For each training batch of fine-tuned samples, calculate the positive similarity index of the positive sample set corresponding to the fine-tuned query statement in each fine-tuned sample; The normalization factor is calculated based on the positive similarity index, and the fine-tuning loss value is calculated based on the positive similarity index and the normalization factor.
4. The semantic vector generation method according to claim 3, characterized in that, The calculation of the positive similarity index of the positive sample set corresponding to the fine-tuned query statement in each fine-tuned sample includes: The positive samples in the fine-tuning sample are statistically analyzed according to the fine-tuning query statement to obtain at least one set of positive samples; For each positive sample in the set of positive samples, calculate the positive similarity value between the corresponding fine-tuning query statement and the positive sample. Based on the ratio between the positive similarity value and the preset temperature coefficient, obtain the positive median value. Accumulate the positive median value to obtain the positive similarity index corresponding to the set of positive samples.
5. The semantic vector generation method according to claim 4, characterized in that, The calculation of the normalization factor based on the positive similarity index includes: The negative samples in the fine-tuning sample are statistically analyzed according to the fine-tuning query statement to obtain at least one set of negative samples. For each negative sample in the negative sample set, calculate the negative similarity value between the corresponding fine-tuning query statement and the negative sample, calculate the negative sample weight based on the negative similarity value, obtain the negative sample mask related to the negative sample in the fine-tuning query statement, calculate the ratio of the product of the negative similarity value and the negative sample weight to a preset temperature coefficient, obtain the negative median value based on the ratio and the negative sample mask, and accumulate the negative median value to obtain the negative similarity index corresponding to the negative sample set; The normalization factor is obtained based on the negative similarity index and the positive similarity index.
6. The semantic vector generation method according to claim 5, characterized in that, The step of obtaining the negative sample mask related to the negative sample in the fine-tuning query statement includes: For the negative sample, a comparison statement is selected one by one from the different fine-tuning query statements, and the statement similarity between the fine-tuning query statement and the comparison statement is calculated. If the statement similarity is not less than a preset score, and the positive sample set of the fine-tuning query statement is a proper subset of the positive sample set of the comparison statement, the negative sample mask is zero; otherwise, it is one.
7. The semantic vector generation method according to claim 6, characterized in that, The calculation process for the preset score includes the following steps: The preset number of fine-tuning query statements of a certain type are uniformly sampled from the training set composed of the fine-tuning samples to obtain multiple fine-tuning samples corresponding to each fine-tuning query statement. For each of the fine-tuning query statements, the sample similarity between each pair of fine-tuning samples is calculated, and the mean of the sample similarity is calculated to obtain the statement sample mean. The average of all the statement sample means is calculated to obtain the preset score.
8. A semantic vector generation device, characterized in that, include: Data acquisition module: used to acquire fine-tuning query statements and obtain the corresponding CQL statement pairs from a preset knowledge graph; The knowledge graph recall module is used to obtain all node labels related to the CQL statement pair in the knowledge graph, and obtain recall text based on the node labels and corresponding attribute data. The recall text is used as a positive sample, and recall texts unrelated to the positive sample are selected from the knowledge graph as negative samples. Sample construction module: used to obtain end identifier and fine-tuning instructions for distinguishing positive and negative samples, and sequentially concatenate the fine-tuning instructions, the fine-tuning query statement, the positive sample, the negative sample and the end identifier to generate fine-tuned samples; Training module: Used to train the vector model using the fine-tuning samples, obtain fine-tuning loss values, adjust the parameters of the vector model based on the fine-tuning loss values until training ends, and obtain a trained target vector model. The target fine-tuning model is used to vectorize the target query statement to obtain the target text vector.
9. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the semantic vector generation method according to any one of claims 1 to 7.
10. A storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the semantic vector generation method according to any one of claims 1 to 7.