Text Search Method and System Based on Vector Retrieval and Large Model Optimization
Through the methods of vector retrieval and large-model optimization, combined with cross encoder and knowledge graph technology, the problems of semantic understanding and correlation sorting in text search are solved, achieving more accurate and efficient text retrieval.
Patent Information
- Application Number
- CN202510644939.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-20
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2045-05-20
AI Technical Summary
The existing text search technology has shortcomings in semantic understanding and correlation sorting, and it is difficult to accurately capture the deep semantic and contextual relationships of text, resulting in bias of search results from user needs and limited correlation sorting accuracy.
Using a method based on vector retrieval and large model optimization, semantic vectors are generated through pre-trained large language models, combined with the cross encoder model to calculate the correlation score of text pairs, and using the knowledge graph for entity recognition and relationship reasoning to optimize search results.
It improves the accuracy and relevance of text retrieval, improves user satisfaction, and reduces computing resource consumption, achieving search results that are more in line with user intentions.
Smart Images

Figure CN120179890B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to text search technology, and in particular to a text search method and system based on vector retrieval and large model optimization. Background Art
[0002] With the explosive growth of Internet information, text search technology, as a key link in information retrieval, has become increasingly important. Traditional text search mainly relies on keyword matching and realizes fast retrieval through technologies such as indexing and inverted indexing. In recent years, with the development of deep learning technology, vector-based semantic retrieval methods have gradually become a research hotspot. Such methods can understand the semantic content of text, not limited to literal matching. At the same time, the emergence of pre-trained large language models provides more powerful semantic understanding capabilities for text representation, enabling search systems to better understand user query intentions and document content. Knowledge graphs, as a representation of structured knowledge, can provide relationship information between entities, further enhancing the accuracy and comprehensiveness of search.
[0003] However, the existing text search technologies still have the following defects and deficiencies:
[0004] Insufficient text semantic understanding. Traditional keyword-based retrieval methods are difficult to understand the deep semantics of text, resulting in a deviation between retrieval results and the actual needs of users; even when using simple vector retrieval methods, it is difficult to accurately capture the context correlation and semantic details of text, especially for complex queries or long text content.
[0005] Limited relevance ranking accuracy. The existing ranking mechanisms mainly rely on a single similarity calculation method and cannot comprehensively consider the multi-dimensional associations between texts, resulting in the possibility that highly relevant content in the retrieval results may not be displayed preferentially, affecting user experience and retrieval efficiency. Summary of the Invention
[0006] Embodiments of the present invention provide a text search method and system based on vector retrieval and large model optimization, which can solve the problems in the prior art.
[0007] In a first aspect of the embodiments of the present invention, a text search method based on vector retrieval and large model optimization is provided, including:
[0008] Obtain the text to be retrieved, and input the text to be retrieved into a pre-trained large language model. Through the pre-trained large language model, generate a semantic vector of the text to be retrieved to obtain a first semantic vector of the text to be retrieved, where the large language model includes an encoder layer with a multi-layer transformer structure;
[0009] Performing similarity calculation in the vector retrieval database based on the first semantic vector to obtain a candidate text set with a similarity greater than a preset similarity threshold to the first semantic vector;
[0010] Combining the text to be retrieved with each candidate text in the candidate text set into text pairs, inputting the text pairs into a cross-encoder model, the cross-encoder model calculating a relevance score based on the context information of the text pairs, and sorting the candidate text set in descending order according to the relevance score to obtain an initial search result;
[0011] Inputting the initial search result into a text optimization model based on a knowledge graph, the text optimization model based on the knowledge graph including a knowledge entity extraction module and an entity relationship reasoning module, identifying key entities from the initial search result through the knowledge entity extraction module, analyzing the association relationships between the key entities based on a preset knowledge graph through the entity relationship reasoning module, and re-sorting and filtering the initial search result according to the association relationships to obtain a final search result.
[0012] Generating a first semantic vector of the text to be retrieved through the pre-trained large language model includes:
[0013] Inputting the text to be retrieved into the encoder layer of the pre-trained large language model, the encoder layer including multiple layers of transformer structures, and each layer of transformer structure including a self-attention sub-layer and a feed-forward neural network sub-layer;
[0014] In the encoder layer, encoding the position information of the tokens in the text to be retrieved into position vectors through position encoding, and combining the position vectors with the token-corresponding word embedding vectors to obtain an input vector sequence; the self-attention sub-layer calculating an attention weight matrix based on the input vector sequence, and performing weighted fusion on the input vector sequence according to the attention weight matrix to obtain a context representation vector; the feed-forward neural network sub-layer performing a non-linear transformation on the context representation vector to obtain a feature vector;
[0015] A pooling layer is arranged at the output end of the encoder layer, the pooling layer adopts an attention pooling mechanism, performs weighted averaging on the feature vectors through learned attention weights to obtain a global semantic representation of the text; inputs the global semantic representation into a dimension mapping layer, and maps the global semantic representation into a first semantic vector with a fixed dimension through the dimension mapping layer.
[0016] Combine the text to be retrieved with each candidate text in the candidate text set to form text pairs, input the text pairs into a cross-encoder model, the cross-encoder model calculates a relevance score based on the context information of the text pairs, and perform a descending order sorting on the candidate text set according to the relevance score, and the initial search result includes:
[0017] Concatenate and combine the text to be retrieved with each candidate text in the candidate text set according to a preset delimiter to generate a text pair sequence;
[0018] Input the text pair sequence into a cross-encoder model, encode the text to be retrieved and the candidate text respectively through the bidirectional transformer structure of the cross-encoder model to generate a first feature sequence of the text to be retrieved and a second feature sequence of the candidate text; calculate the interaction features between the first feature sequence and the second feature sequence based on the multi-head cross-attention mechanism;
[0019] Extract local semantic features in the interaction features through a one-dimensional convolutional neural network; calculate the long-range dependence relationship in the interaction features through a self-attention layer to obtain global semantic features; perform adaptive weighted summation on the local semantic features and the global semantic features to obtain a unified representation vector of the text pair;
[0020] Input the unified representation vector into the fully connected neural network of the cross-encoder model, perform a non-linear transformation on the unified representation vector through the fully connected neural network, and output the relevance score of the text pair;
[0021] Perform a descending order sorting on the candidate text set according to the relevance score, generate a sorted candidate text list, and output the sorted candidate text list as the initial search result.
[0022] The text optimization model based on the knowledge graph includes a knowledge entity extraction module and an entity relationship reasoning module. Identify key entities from the initial search result through the knowledge entity extraction module, and analyze the association relationship between the key entities based on a preset knowledge graph through the entity relationship reasoning module, including:
[0023] Perform sentence splitting processing and named entity recognition on each text content in the initial search result to obtain an entity annotation sequence;
[0024] Perform entity linking on the entity annotation sequence, and match the identified entities with the standard entities in the knowledge graph; calculate the occurrence frequency and position importance score of the entity in the text; calculate the relevance score between the entity and the text theme by combining word vectors; generate an entity importance score based on the weighted calculation of the entity frequency, position importance score, and relevance score; select the entities with entity importance scores greater than the preset scoring threshold as the key entity set;
[0025] Using the entities in the key entity set as the starting nodes, perform multi-hop relationship path search in the knowledge graph, filter the relationship paths with credibility higher than the preset credibility threshold, extract the entity relationship triples included in the relationship paths, and calculate the relationship strength based on the occurrence frequencies of the head entity, tail entity, and relationship type in the entity relationship triples;
[0026] Construct an entity relationship graph based on the relationship strength and the entity relationship triples, and perform node importance propagation in the entity relationship graph to obtain the final importance score of each entity.
[0027] Using the entities in the key entity set as the starting nodes, performing multi-hop relationship path search in the knowledge graph, and filtering the relationship paths with credibility higher than the preset credibility threshold includes:
[0028] Taking the starting node as the current search node, obtaining the adjacent node set and the corresponding relationship types of the current search node; calculating the credibility of each node in the adjacent node set, where the credibility is determined by the product of the node importance score, relationship type weight, and path attenuation factor. Among them, the node importance score is obtained by weighted summation of the in-degree, out-degree, and node attribute value of the node; the relationship type weight is determined by the ratio of the number of occurrences of the relationship corresponding to the node to the maximum relationship frequency; the path attenuation factor is determined based on the exponential relationship between the preset attenuation base and the current hop count;
[0029] Select the nodes with credibility exceeding the preset credibility threshold as candidate nodes; record the path information from the current search node to the candidate nodes;
[0030] Recursively perform path search on each candidate node until the preset maximum hop count is reached or the search queue is empty, specifically including:
[0031] Adding the candidate nodes to the node search queue; updating the node access status and marking the accessed nodes; calculating the cumulative credibility of the current path information, where the cumulative credibility is the sum of the credibilities of all nodes on the path; when the search depth reaches the preset maximum hop count, storing the current path information and the cumulative credibility into the path result set.
[0032] Re - order and filter the initial search results according to the association relationship to obtain the final search results, including:
[0033] Establish an entity association matrix according to the association relationship, where the rows and columns of the entity association matrix represent entities, and the matrix element value is the association strength value of the corresponding entity pair; calculate the first - order associated entity set of each entity, and the first - order associated entity set contains all entities directly connected to this entity; count the network centrality of each entity, and the network centrality is the size of the first - order associated entity set of this entity.
[0034] Re - order the initial search results according to the size of the network centrality; and delete the initial search results with network centrality less than the preset screening threshold to obtain the final search results.
[0035] In the second aspect of the embodiments of the present invention, a text search system based on vector retrieval and large - model optimization is provided, including:
[0036] The first unit is used to obtain the text to be retrieved, input the text to be retrieved into a pre - trained large - language model, and generate a first semantic vector of the text to be retrieved through the pre - trained large - language model, where the large - language model includes an encoder layer with a multi - layer transformer structure.
[0037] The second unit is used to perform similarity calculation in the vector retrieval database based on the first semantic vector to obtain a candidate text set with a similarity greater than the preset similarity threshold to the first semantic vector.
[0038] The third unit is used to combine the text to be retrieved with each candidate text in the candidate text set into a text pair, input the text pair into a cross - encoder model, the cross - encoder model calculates a relevance score based on the context information of the text pair, and sorts the candidate text set in descending order according to the relevance score to obtain the initial search results.
[0039] The fourth unit is used to input the initial search results into a text optimization model based on a knowledge graph. The text optimization model based on a knowledge graph includes a knowledge entity extraction module and an entity relationship reasoning module. Identify key entities from the initial search results through the knowledge entity extraction module, analyze the association relationship between the key entities based on a preset knowledge graph through the entity relationship reasoning module, and re - order and filter the initial search results according to the association relationship to obtain the final search results.
[0040] In the third aspect of the embodiments of the present invention,
[0041] Provided is an electronic device, including:
[0042] a processor;
[0043] a memory for storing instructions executable by the processor;
[0044] wherein, the processor is configured to call the instructions stored in the memory to execute the method described above.
[0045] In the fourth aspect of the embodiments of the present invention,
[0046] a computer-readable storage medium is provided, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the method described above is implemented.
[0047] The beneficial effects of this application are as follows:
[0048] In the present invention, semantic vectors are generated for the text to be retrieved by a large language model, achieving precise capture of the deep semantic features of the text, effectively solving the problem that traditional keyword matching methods cannot understand the semantic background of the text, and greatly improving the accuracy of retrieval.
[0049] The present invention introduces a cross-encoder model to finely rank candidate texts. This model can fully consider the context correlation information of text pairs and accurately evaluate the text relevance through deep learning algorithms, significantly improving the relevance of search results and user satisfaction.
[0050] The present invention combines knowledge graph technology to optimize search results. Through entity recognition and relationship reasoning, structured knowledge is incorporated into the search process, which can not only identify key entities in the text but also analyze the semantic associations between entities, making the final search results more in line with user intentions, while reducing computational resource consumption and improving the overall efficiency of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 is a schematic flow chart of the text search method based on vector retrieval and large model optimization according to the embodiments of the present invention;
[0052] Figure 2 is a schematic architecture diagram of the text optimization model based on knowledge graph according to the embodiments of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0053] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are only a part rather than all of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0054] The technical solutions of the present invention will be described in detail below with specific embodiments. These specific embodiments may be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.
[0055] Referring to Figure 1 and Figure 2 , the method of this application includes:
[0056] Obtain the text to be retrieved, and input the text to be retrieved into a pre-trained large language model. The pre-trained large language model generates a semantic vector for the text to be retrieved to obtain a first semantic vector of the text to be retrieved. Among them, the large language model includes an encoder layer with multiple transformer structures;
[0057] Based on the first semantic vector, calculate the similarity in the vector retrieval database to obtain a candidate text set whose similarity to the first semantic vector is greater than a preset similarity threshold;
[0058] Combine the text to be retrieved with each candidate text in the candidate text set to form text pairs, and input the text pairs into a cross-encoder model. The cross-encoder model calculates a relevance score based on the context information of the text pairs, and sorts the candidate text set in descending order according to the relevance score to obtain an initial search result;
[0059] Input the initial search result into a text optimization model based on a knowledge graph. The text optimization model based on the knowledge graph includes a knowledge entity extraction module and an entity relationship reasoning module. Identify key entities from the initial search result through the knowledge entity extraction module, analyze the association relationship between the key entities based on a preset knowledge graph through the entity relationship reasoning module, and re-rank and filter the initial search result according to the association relationship to obtain a final search result.
[0060] In an alternative embodiment, generating a first semantic vector of the text to be retrieved by the pre-trained large language model includes:
[0061] Input the text to be retrieved into the encoder layer of a pre-trained large language model. The encoder layer includes multiple layers of transformer structures, and each layer of transformer structure includes a self-attention sub-layer and a feed-forward neural network sub-layer;
[0062] In the encoder layer, the position information of the tokens in the text to be retrieved is encoded into position vectors through positional encoding, and the position vectors are combined with the token-embedding vectors corresponding to the tokens to obtain an input vector sequence; the self-attention sub-layer calculates an attention weight matrix based on the input vector sequence, and performs weighted fusion on the input vector sequence according to the attention weight matrix to obtain a context representation vector; the feed-forward neural network sub-layer performs a non-linear transformation on the context representation vector to obtain a feature vector;
[0063] A pooling layer is arranged at the output end of the encoder layer. The pooling layer adopts an attention pooling mechanism to perform weighted averaging on the feature vectors through learned attention weights to obtain the global semantic representation of the text; the global semantic representation is input into a dimension mapping layer, and the global semantic representation is mapped into a first semantic vector with a fixed dimension through the dimension mapping layer.
[0064] For example, the text to be retrieved can be "Artificial intelligence technology is changing our way of life".
[0065] Input the text to be retrieved into the encoder layer of a pre-trained large language model for processing. The encoder layer includes multiple layers of transformer structures, and in this embodiment, 12 layers of transformer structures can be adopted. Each layer of transformer structure includes a self-attention sub-layer and a feed-forward neural network sub-layer.
[0066] During the processing of the encoder layer, the position information of the tokens in the text to be retrieved is encoded into position vectors through positional encoding. Specifically, for the above example text, it is first tokenized into ["Artificial intelligence", "technology", "is", "changing", "our", "way", "of", "life"]. Assuming that the embedding dimension of each token is 768 dimensions, corresponding position encoding is generated for each token. For example, the token "Artificial intelligence" is located at the first position in the sequence, and its corresponding position vector can be calculated through sine and cosine functions, and this position vector is also 768 dimensions.
[0067] The position vectors are combined with the word embedding vectors corresponding to the tokens to obtain an input vector sequence. In this embodiment, the combination method is direct addition. For example, for the token "artificial intelligence", the number of heads is set to 12. Specifically, the input vector sequence is respectively linearly transformed to obtain three matrices: Query, Key, and Value. For the first token "artificial intelligence", the attention scores between it and all tokens are calculated. For example, the attention score with "technology" is 0.15, and the attention score with "change" is 0.08, etc. After softmax normalization, the attention weights are obtained. For example, the weight with "technology" is 0.2, and the weight with "change" is 0.1, etc.
[0068] The input vector sequence is weighted and fused according to the attention weight matrix to obtain a context representation vector. For example, the context representation vector of the token "artificial intelligence" is the result of weighted summation of the value vectors of all tokens according to the corresponding attention weights. The same operation is performed on all tokens to obtain a context representation vector sequence with a shape of [8, 768].
[0069] The feed-forward neural network sub-layer performs a non-linear transformation on the context representation vector to obtain a feature vector. This feed-forward neural network consists of two linear transformation layers with a ReLU activation function in the middle. The first linear transformation expands the dimension from 768 to 3072. After ReLU activation, the second linear transformation compresses the dimension from 3072 back to 768. For each context representation vector, the corresponding feature vector is obtained through this feed-forward network, and finally a feature vector sequence with a shape of [8, 768] is generated.
[0070] In the 12-layer transformer structure of the entire encoder, the output of each layer is used as the input of the next layer and is processed layer by layer. A pooling layer is set to process the feature vector sequence output by the last layer of the transformer structure. This pooling layer adopts an attention pooling mechanism to perform weighted averaging on the feature vectors through learned attention weights to obtain the global semantic representation of the text.
[0071] Specifically, a learnable query vector (with a dimension of 768) is introduced, and the correlation scores between this query vector and each feature vector are calculated. For example, the correlation score between the query vector and the feature vector of "artificial intelligence" is 0.25, and the correlation score with "technology" is 0.20, etc. These scores are normalized through softmax to obtain attention weights. For example, the weight of "artificial intelligence" is 0.28, and the weight of "technology" is 0.22, etc. All feature vectors are weighted and averaged according to these weights to obtain a 768-dimensional global semantic representation vector.
[0072] Input the global semantic representation into the dimension mapping layer, and map the global semantic representation into a first semantic vector with a fixed dimension through this dimension mapping layer. In this embodiment, the dimension mapping layer is a linear transformation layer that maps the 768-dimensional global semantic representation into a 256-dimensional semantic vector. For example, the first semantic vector obtained after mapping may be a 256-dimensional vector such as [-0.056, 0.127, 0.234, ..., 0.089].
[0073] Through the above processing, the original text to be retrieved "Artificial intelligence technology is changing our way of life" is successfully converted into a 256-dimensional semantic vector representation. This semantic vector captures the semantic information of the text and can be used for subsequent text retrieval, matching and other tasks. For example, calculate the cosine similarity between this vector and the document vectors in the corpus to find the document with the closest semantics.
[0074] In practical applications, various parameters can be adjusted according to specific task requirements, such as the number of transformer layers, the number of attention heads, the word embedding dimension, the dimension of the mapped vector, etc., to obtain the best performance.
[0075] In an alternative embodiment, combine the text to be retrieved with each candidate text in the candidate text set to form text pairs, input the text pairs into a cross-encoder model, the cross-encoder model calculates a relevance score based on the context information of the text pairs, and sorts the candidate text set in descending order according to the relevance score, and the initial search results include:
[0076] Concatenate and combine the text to be retrieved with each candidate text in the candidate text set according to a preset delimiter to generate a sequence of text pairs;
[0077] Input the sequence of text pairs into the cross-encoder model, and encode the text to be retrieved and the candidate text respectively through the bidirectional transformer structure of the cross-encoder model to generate a first feature sequence of the text to be retrieved and a second feature sequence of the candidate text; calculate the interaction features between the first feature sequence and the second feature sequence based on the multi-head cross-attention mechanism;
[0078] Extract local semantic features from the interaction features through a one-dimensional convolutional neural network; calculate the long-range dependencies in the interaction features through a self-attention layer to obtain global semantic features; perform adaptive weighted summation of the local semantic features and the global semantic features to obtain a unified representation vector of the text pair;
[0079] Input the unified representation vector into the fully-connected neural network of the cross-encoder model, and perform a non-linear transformation on the unified representation vector through the fully-connected neural network to output the correlation score of the text pair;
[0080] Sort the candidate text set in descending order according to the correlation score, generate a sorted candidate text list, and output the sorted candidate text list as the initial search result.
[0081] This embodiment provides a text retrieval method based on a cross-encoder model. The method first combines the text to be retrieved with each candidate text in the candidate text set to form text pairs, then uses the cross-encoder model to calculate the correlation score of the text pairs, and finally sorts the candidate texts according to the correlation score to obtain the initial search result. The specific implementation steps are as follows:
[0082] Concatenate and combine the text to be retrieved with each candidate text in the candidate text set according to a preset delimiter to generate a text pair sequence. For example, "[SEP]" can be used as the delimiter to concatenate the text to be retrieved "How's the weather today" with the candidate text "It's sunny today" as "How's the weather today[SEP]It's sunny today". Similar operations are performed on each candidate text in the candidate text set to generate multiple text pair sequences.
[0083] Input the text pair sequence into the cross-encoder model. The model adopts a bidirectional Transformer structure to encode the text to be retrieved and the candidate text respectively, generating a first feature sequence of the text to be retrieved and a second feature sequence of the candidate text. Specifically, the model first tokenizes the input text pair sequence, and then converts the tokenization result into word vectors. Then, the word vector sequence is processed through multiple layers of Transformer encoders to obtain the context-related representation of the text. In this process, the model can capture the long-distance dependencies and context information in the text.
[0084] Calculate the interaction features between the first feature sequence and the second feature sequence based on the multi-head cross-attention mechanism. The multi-head cross-attention mechanism allows the model to learn the alignment relationship between texts from multiple different representation subspaces. Specifically, 8 attention heads can be used, with the dimension of each head being 64. In this way, the model can comprehensively capture the correlation between the text to be retrieved and the candidate text.
[0085] Extract the local semantic features in the interaction features through a one-dimensional convolutional neural network. Convolution kernels of different sizes (such as 3, 4, 5) can be used to capture local features in different ranges. For example, use 128 3x1 convolutional kernels, 128 4x1 convolutional kernels, and 128 5x1 convolutional kernels to perform convolution operations on the interaction features respectively, and then splice the results to obtain the local semantic features.
[0086] At the same time, calculate the long-range dependencies in the interaction features through the self-attention layer to obtain the global semantic features. The self-attention layer can capture the relationships between any positions in the sequence and effectively model long-range dependencies. 8 attention heads with a dimension of 64 for each head can be used to fully capture the global semantic information.
[0087] Perform adaptive weighted summation on the local semantic features and the global semantic features to obtain the unified representation vector of the text pair. Adaptive weighting can be achieved through a learnable parameter α, enabling the model to automatically adjust the importance of local features and global features according to different inputs. The calculation formula for the unified representation vector can be expressed as: multiplying the local semantic features by α and adding the global semantic features multiplied by (1 - α). Here, α is a learnable parameter with a value range between 0 and 1.
[0088] Input the unified representation vector into the fully connected neural network of the cross-encoder model. This network performs a non-linear transformation on the unified representation vector and outputs the correlation score of the text pair. The fully connected neural network can contain multiple hidden layers, and each hidden layer uses the ReLU activation function. For example, two hidden layers can be used. The first layer has 512 neurons, the second layer has 256 neurons, and the last layer outputs a scalar value as the correlation score.
[0089] According to the calculated correlation scores, sort the candidate text set in descending order to generate a sorted list of candidate texts, and output this list as the initial search result. Sorting can be implemented using the quicksort algorithm with a time complexity of O(nlogn), where n is the number of candidate texts.
[0090] To better illustrate the implementation process of this method, a specific data case is given below:
[0091] Suppose the text to be retrieved is "How to prevent colds", and the candidate text set contains the following texts:
[0092] 1. "Drinking more hot water helps prevent colds";
[0093] 2. "Regular work and rest can enhance immunity";
[0094] 3. "The symptoms of a cold include fever and cough";
[0095] 4. "Maintaining good personal hygiene habits can prevent colds";
[0096] 5. "Exercise can enhance the body's resistance";
[0097] First, combine the text to be retrieved with each candidate text to form text pairs:
[0098] 1. "How to prevent colds [SEP] Drinking more hot water helps prevent colds";
[0099] 2. "How to prevent colds [SEP] Regular work and rest can enhance immunity";
[0100] 3. "How to prevent colds [SEP] Symptoms of a cold include fever and cough";
[0101] 4. "How to prevent colds [SEP] Maintaining good personal hygiene habits can prevent colds";
[0102] 5. "How to prevent colds [SEP] Exercise can improve the body's resistance";
[0103] Input these text pairs into the cross-encoder model. After the above processing steps, obtain the relevance scores of each text pair (hypothetical): 1. 0.85; 2. 0.72; 3. 0.45; 4. 0.93; 5. 0.78;
[0109] Sort the candidate texts in descending order according to the relevance scores to obtain the final initial search results:
[0110] 1. "Maintaining good personal hygiene habits can prevent colds" (Score: 0.93);
[0111] 2. "Drinking more hot water helps prevent colds" (Score: 0.85);
[0112] 3. "Exercise can improve the body's resistance" (Score: 0.78);
[0113] 4. "Regular work and rest can enhance immunity" (Score: 0.72);
[0114] ...
[0115] Through this method, we can effectively sort the candidate texts, placing the most relevant texts at the front to provide users with more accurate search results. This method makes full use of the advantages of the cross-encoder model, which can deeply understand the semantic information and context relationship of the texts, thus achieving high-quality text retrieval.
[0116] In an optional implementation manner, the text optimization model based on the knowledge graph includes a knowledge entity extraction module and an entity relationship reasoning module. The knowledge entity extraction module is used to identify key entities from the initial search results, and the entity relationship reasoning module analyzes the association relationships between the key entities based on a preset knowledge graph, including:
[0117] Perform sentence splitting processing and named entity recognition on each text content in the initial search results to obtain an entity annotation sequence;
[0118] Perform entity linking on the entity annotation sequence, match the identified entities with the standard entities in the knowledge graph; calculate the occurrence frequency and position importance score of the entities in the text; calculate the relevance score between the entities and the text theme in combination with word vectors; generate an entity importance score through weighted calculation of the entity frequency, position importance score, and relevance score; select the entities with entity importance scores greater than the preset scoring threshold as the key entity set;
[0119] Use the entities in the key entity set as the starting nodes to perform multi-hop relationship path search in the knowledge graph, filter the relationship paths with credibility higher than the preset credibility threshold, extract the entity relationship triples included in the relationship paths, and calculate the relationship strength based on the occurrence frequencies of the head entity, tail entity, and relationship type in the entity relationship triples;
[0120] Construct an entity relationship graph based on the relationship strength and the entity relationship triples, and perform node importance propagation in the entity relationship graph to obtain the final importance score of each entity.
[0121] The knowledge entity extraction module is used to identify key entities from the initial search results, and the entity relationship reasoning module analyzes the association relationships between the key entities based on a preset knowledge graph.
[0122] Perform sentence splitting processing on each text content in the initial search results. Taking "Today the weather is sunny and suitable for going out to play. There are many scenic spots in Beijing, such as the Forbidden City, the Great Wall, etc." as an example, it can be divided into two sentences: "Today the weather is sunny and suitable for going out to play." and "There are many scenic spots in Beijing, such as the Forbidden City, the Great Wall, etc."
[0123] Then, named entity recognition is performed on the text after clause splitting to obtain an entity annotation sequence. For example, entities such as "Beijing", "The Forbidden City", and "The Great Wall" can be recognized and their types annotated. For example, "Beijing" is annotated as a location, and "The Forbidden City" and "The Great Wall" are annotated as scenic spots.
[0124] Next, entity linking is performed on the entity annotation sequence to match the recognized entities with the standard entities in the knowledge graph. For example, "The Forbidden City" may be matched to the entity "The Palace Museum" in the knowledge graph.
[0125] Calculate the occurrence frequency and position importance score of the entity in the text. For example, "Beijing" appears once at the beginning of the sentence and has a relatively high score; "The Forbidden City" and "The Great Wall" each appear once at the end of the sentence and have relatively low scores.
[0126] Combine word vectors to calculate the relevance score between the entity and the text theme. For example, if the text theme is "Beijing tourism", then the relevance scores of "Beijing", "The Forbidden City", and "The Great Wall" are all relatively high.
[0127] Generate an entity importance score based on the weighted calculation of entity frequency, position importance score, and relevance score. Weights can be set to 0.3, 0.3, and 0.4 respectively. Suppose the three scores of "Beijing" are 1, 0.9, and 0.95 respectively, then its importance score is 1 * 0.3 + 0.9 * 0.3 + 0.95 * 0.4 = 0.95.
[0128] Select entities with entity importance scores greater than the preset scoring threshold as the key entity set. For example, set the threshold to 0.8, then "Beijing", "The Forbidden City", and "The Great Wall" may all be selected as key entities.
[0129] Using the entities in the key entity set as the starting nodes, perform multi-hop relationship path search in the knowledge graph. Filter the relationship paths with credibility higher than the preset credibility threshold. For example, set the threshold to 0.9, then only retain the relationship paths with credibility greater than 0.9.
[0130] Extract the entity relationship triples contained in the relationship paths. Calculate the relationship strength based on the occurrence frequencies of the head entity, tail entity, and relationship type in the entity relationship triples.
[0131] Construct an entity relationship graph based on the relationship strength and entity relationship triples; perform node importance propagation in the entity relationship graph to obtain the final importance score of each entity. The PageRank algorithm can be used for importance propagation and iteratively calculated until convergence.
[0132] Through the above steps, key entities can be extracted from the initial search results, and the association relationships between entities can be analyzed, providing a basis for subsequent text optimization. This method can effectively utilize the structured information in the knowledge graph to improve the accuracy of entity recognition and relationship reasoning.
[0133] In practical applications, various thresholds and parameters can be adjusted according to specific scenarios. For example, for shorter texts, the threshold for the entity importance score can be lowered to retain more entities; for texts in professional fields, the confidence threshold for relationship paths can be increased to ensure the accuracy of reasoning results.
[0134] In addition, different weights and calculation methods can be adopted for different types of entities and relationships. For example, for news texts, higher weights can be assigned to entities of time and location types; for technology texts, higher weights can be assigned to entities of technical terms and company name types.
[0135] In the process of constructing the entity relationship graph, the time dimension can be considered to handle the situation where entity relationships change over time. For example, for the relationship of "company - CEO - person's name", the effective time period of the relationship can be marked to more accurately reflect the dynamic relationship between entities.
[0136] When propagating the importance of nodes, the directionality and semantics of relationships can be considered. For example, for the relationship of "A is affiliated with B", when propagating importance, more importance can be passed from node B to node A, while less importance is passed from node A to node B.
[0137] Finally, to improve the interpretability of the system, the decision-making basis can be recorded in each step. For example, when performing entity linking, the specific matching features can be recorded; when filtering relationship paths, the calculation process of confidence can be recorded. This information can help understand and optimize the behavior of the system.
[0138] Through the above detailed implementation manners, those skilled in the art can implement a text optimization model based on the knowledge graph according to the disclosed content, including two key modules: knowledge entity extraction and entity relationship reasoning. This model can effectively extract key information from texts and perform relationship reasoning using the knowledge graph, providing strong support for subsequent text optimization tasks.
[0139] In an alternative implementation manner, using the entities in the key entity set as the starting nodes, performing multi-hop relationship path search in the knowledge graph, and filtering relationship paths with a confidence higher than a preset confidence threshold includes:
[0140] Take the starting node as the current search node, and obtain the set of adjacent nodes of the current search node and the corresponding relationship types; calculate the credibility of each node in the set of adjacent nodes, where the credibility is determined by the product of the node importance score, the relationship type weight, and the path attenuation factor. The node importance score is obtained by weighted summation of the in-degree, out-degree, and node attribute value of the node. The relationship type weight is determined by the ratio of the number of occurrences of the relationship corresponding to the node to the maximum relationship frequency. The path attenuation factor is determined based on the exponential relationship between the preset attenuation base and the current hop count.
[0141] Select the nodes whose credibility exceeds the preset credibility threshold as candidate nodes; record the path information from the current search node to the candidate nodes.
[0142] Recursively perform path search for each candidate node until the preset maximum hop count is reached or the search queue is empty, which specifically includes:
[0143] Add the candidate node to the node search queue; update the node access status and mark the accessed nodes; calculate the cumulative credibility of the current path information, where the cumulative credibility is the sum of the credibilities of all nodes on the path. When the search depth reaches the preset maximum hop count, store the current path information and the cumulative credibility into the path result set.
[0144] Perform multi-hop relationship path search in the knowledge graph with the entities in the key entity set as the starting nodes. Specifically, take the starting node as the current search node and obtain the set of adjacent nodes of the current search node and the corresponding relationship types. For example, assume the starting node is "a certain mobile phone company", and the adjacent nodes may include "Tim Cook" (relationship type: CEO), "iPhone" (relationship type: product), "California" (relationship type: headquarters location), etc.
[0145] Next, calculate the credibility of each node in the set of adjacent nodes. The credibility is determined by the product of the node importance score, the relationship type weight, and the path attenuation factor.
[0146] The node importance score is obtained by weighted summation of the in-degree, out-degree, and node attribute value of the node. The in-degree represents the number of edges pointing to the node, and the out-degree represents the number of edges starting from the node. The node attribute value can be the PageRank value of the node, the centrality of the node in the graph, etc. For example, for the node "Tim Cook", assume its in-degree is 50, out-degree is 30, and PageRank value is 0.8. Then, the weights can be set to 0.3, 0.3, and 0.4 respectively, and the calculated node importance score is: 0.3×50 + 0.3×30 + 0.4×0.8 = 24.32.
[0147] The weight of the relationship type is determined by the ratio of the number of occurrences of the relationship corresponding to the node to the maximum relationship frequency. For example, if the "CEO" relationship appears 500 times in the knowledge graph, and the maximum relationship frequency (such as the "is located in" relationship) appears 2000 times, then the weight of the "CEO" relationship is 500 / 2000 = 0.25.
[0148] The path attenuation factor is determined based on the exponential relationship between a preset attenuation base and the current hop count. Suppose the attenuation base is 0.8 and the current hop count is 1, then the path attenuation factor is the 1st power of 0.8, which is 0.8; when the hop count is 2, the attenuation factor is the 2nd power of 0.8, which is 0.64. This design is to reduce the credibility of long paths because generally, the longer the path, the less direct the relationship may be and the lower the credibility.
[0149] Taking into account the above three factors, assuming the node importance score of the node "Tim Cook" is 24.32, the weight of the relationship type "CEO" is 0.25, and the path attenuation factor corresponding to the current hop count of 1 is 0.8, then the credibility of this node is 24.32×0.25×0.8 = 4.864.
[0150] Select nodes with a credibility exceeding the preset credibility threshold as candidate nodes. Suppose the preset credibility threshold is 3.0, then the credibility of the "Tim Cook" node, 4.864, is greater than the threshold and is selected as a candidate node. Record the path information from the current search node "Apple Inc." to the candidate node "Tim Cook", including node ID, relationship type, credibility, etc.
[0151] Recursively perform path search for each candidate node until the preset maximum hop count is reached or the search queue is empty. The specific steps are as follows:
[0152] Add the candidate node to the node search queue. For example, add "Tim Cook" to the search queue.
[0153] Update the node access status, mark the visited nodes to avoid repeated visits and forming loops. A hash table can be used to record the visited nodes, with the node ID as the key and a boolean value indicating whether it has been visited as the value. For example, mark "Apple Inc." and "Tim Cook" as visited status.
[0154] Calculate the cumulative credibility of the current path information, that is, the sum of the credibilities of all nodes on the path. For example, the cumulative credibility of the path "Apple Inc. → Tim Cook" is the initial credibility of the starting node (assumed to be 5.0) plus the credibility of "Tim Cook", 4.864, which equals 9.864.
[0155] When the search depth reaches the preset maximum number of hops, the current path information and cumulative credibility are stored in the path result set. For example, if the preset maximum number of hops is 2, and currently, the search has jumped from "Apple Inc." to "Tim Cook" and then to "Stanford University" (relationship type: alma mater), then the path "Apple Inc. → Tim Cook → Stanford University" and its cumulative credibility are stored in the result set.
[0156] Continue using "Tim Cook" as the current search node, repeat the above steps, obtain its adjacent nodes such as "Stanford University", "Auburn University", etc., calculate the credibility of these nodes, and select the nodes whose credibility exceeds the threshold for continued search.
[0157] Suppose the node importance score of "Stanford University" is 30.5, the weight of the relationship type "alma mater" is 0.15, and the path attenuation factor corresponding to the current hop count of 2 is 0.64. Then the credibility of this node is 30.5 × 0.15 × 0.64 = 2.928. If the threshold is still 3.0, then "Stanford University" will not be selected as a candidate node, and the search stops at this node.
[0158] If the search queue is empty or all paths reach the maximum number of hops, the search ends. Finally, the path result set contains all paths that meet the conditions and their cumulative credibility. The paths can be sorted according to the cumulative credibility, and the path with the highest credibility can be selected as the final result.
[0159] Through the above method, multi-hop relationship paths between key entities can be efficiently discovered in the knowledge graph, and the most relevant and reliable paths can be filtered out through credibility calculation, providing support for knowledge discovery and reasoning.
[0160] In an alternative embodiment, reordering and filtering the initial search results according to the association relationship to obtain the final search results includes:
[0161] Establish an entity association matrix according to the association relationship, where the rows and columns of the entity association matrix represent entities, and the matrix element values are the association strength values of the corresponding entity pairs; calculate the first-order associated entity set of each entity, and the first-order associated entity set contains all entities directly connected to this entity; count the network centrality of each entity, and the network centrality is the size of the first-order associated entity set of this entity.
[0162] Reorder the initial search results according to the size of the network centrality; and delete the initial search results with a network centrality less than the preset screening threshold to obtain the final search results.
[0163] The specific implementation of reordering and filtering the initial search results according to the association relationship to obtain the final search results is as follows:
[0164] Build an entity association matrix. Both the rows and columns of this matrix represent entities, and each element value in the matrix represents the association strength between the entity pair corresponding to the row and column. For example, assume there are entities A, B, C, and D, and their association strengths can be represented by a 4x4 matrix. The value at the (A, B) position in the matrix represents the association strength between entities A and B.
[0165] The first-order associated entity set contains all entities directly connected to this entity. Specifically, traverse the row corresponding to this entity in the entity association matrix, and add the entities corresponding to the columns with association strength greater than 0 to the first-order associated entity set. For example, for entity A, if the values of columns B and C in row A of the matrix are greater than 0, and the value of column D is 0, then the first-order associated entity set of A is {B, C}.
[0166] The network centrality is defined as the size of the first-order associated entity set of this entity. Continuing with the above example, the network centrality of entity A is 2 because the size of its first-order associated entity set {B, C} is 2.
[0167] Based on the calculated network centrality, reorder the initial search results. The sorting rule is that the greater the network centrality, the higher the ranking. For example, assume the initial search results are [E1, E2, E3, E4], and their network centralities are [3, 5, 2, 4] respectively. Then the reordered result is [E2, E4, E1, E3].
[0168] Finally, set a preset screening threshold, and delete the search results with network centrality less than this threshold. For example, if the threshold is set to 3, then E3 in the above sorting result will be deleted because its network centrality is 2, which is less than the threshold 3. The final search results obtained are [E2, E4, E1].
[0169] The following uses a specific data case to illustrate the whole process:
[0170] Assume the initial search results contain 5 entities: E1, E2, E3, E4, E5. Their association relationships are represented by the following 5x5 entity association matrix:
[0171] E1 E2 E3 E4 E5;
[0172] E1 0 1 1 0 1;
[0173] E2 1 0 1 1 0;
[0174] E3 1 1 0 0 1;
[0175] E4 0 1 0 0 1;
[0176] E5 1 0 1 1 0;
[0177] First, calculate the set of first-order associated entities for each entity:
[0178] E1: {E2, E3, E5};
[0179] E2: {E1, E3, E4};
[0180] E3: {E1, E2, E5};
[0181] E4: {E2, E5};
[0182] E5: {E1, E3, E4};
[0183] Then, calculate the network centrality of each entity:
[0184] E1: 3; E2: 3; E3: 3; E4: 2; E5: 3;
[0185] Reorder the initial search results according to the network centrality. Since the network centralities of E1, E2, E3, and E5 are the same, their relative order remains unchanged. E4 is ranked last because its network centrality is the smallest. The reordered result is:
[0186] [E1, E2, E3, E5, E4];
[0187] Finally, assuming that the set screening threshold is 3, the entity E4 with a network centrality less than 3 will be deleted.
[0188] The final search result obtained is:
[0189] [E1, E2, E3, E5].
[0190] The advantage of this method is that it not only considers the direct association relationship between entities but also reflects the importance of entities in the entire network through network centrality. Entities with high network centrality are often associated with more other entities and thus may contain richer and more relevant information. By reordering and filtering in this way, more important and relevant search results can be preferentially presented to users, while relatively isolated and weakly associated results are filtered out, thereby improving the quality and relevance of search results.
[0191] In practical applications, the entity association matrix may be a very large sparse matrix. Therefore, when implementing, it is necessary to consider using appropriate data structures to store and process this matrix, such as using an adjacency list or a compressed sparse row (CSR) format. At the same time, for large-scale data, a distributed computing framework can be considered to improve processing efficiency.
[0192] In addition, the calculation method of the association strength can also be customized according to specific application scenarios. For example, in text search, the association strength between entities can be calculated based on term frequency-inverse document frequency (TF-IDF); in social network analysis, the association strength can be calculated based on user interaction frequency.
[0193] Generally speaking, this method of re-ranking and filtering search results based on association relationships improves the search quality by leveraging the association information between entities, and has strong flexibility and scalability, and can be adjusted and optimized according to different application scenarios.
[0194] The text search system based on vector retrieval and large model optimization according to the embodiments of the present invention includes:
[0195] A first unit, configured to obtain a text to be retrieved, input the text to be retrieved into a pre-trained large language model, and generate a first semantic vector of the text to be retrieved through the pre-trained large language model, where the large language model includes an encoder layer with a multi-layer transformer structure;
[0196] A second unit, configured to perform similarity calculation in the vector retrieval database based on the first semantic vector, and obtain a candidate text set whose similarity with the first semantic vector is greater than a preset similarity threshold;
[0197] A third unit, configured to combine the text to be retrieved with each candidate text in the candidate text set into a text pair, input the text pair into a cross-encoder model, the cross-encoder model calculates a relevance score based on the context information of the text pair, and sorts the candidate text set in descending order according to the relevance score to obtain an initial search result;
[0198] A fourth unit, configured to input the initial search result into a text optimization model based on a knowledge graph. The text optimization model based on the knowledge graph includes a knowledge entity extraction module and an entity relationship reasoning module. The key entities are identified from the initial search result through the knowledge entity extraction module, and the association relationship between the key entities is analyzed based on a preset knowledge graph through the entity relationship reasoning module. The initial search result is re-ranked and filtered according to the association relationship to obtain a final search result.
[0199] In a third aspect of the embodiments of the present invention,
[0200] there is provided an electronic device, comprising:
[0201] a processor;
[0202] a memory for storing instructions executable by the processor;
[0203] wherein the processor is configured to call the instructions stored in the memory to execute the method described above.
[0204] In a fourth aspect of the embodiments of the present invention,
[0205] there is provided a computer-readable storage medium, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the method described above is implemented.
[0206] The present invention may be a method, an apparatus, a system, and / or a computer program product. The computer program product may include a computer-readable storage medium, on which computer-readable program instructions for executing various aspects of the present invention are uploaded.
[0207] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A text search method based on vector retrieval and large model optimization, characterized in that Including: Obtain the text to be retrieved, input the text to be retrieved into a pre-trained large language model, and generate a semantic vector for the text to be retrieved through the pre-trained large language model to obtain a first semantic vector of the text to be retrieved, where the large language model includes encoder layers with multiple Transformer structures; Perform similarity calculation in the vector retrieval database based on the first semantic vector, and obtain a candidate text set whose similarity to the first semantic vector is greater than a preset similarity threshold; Combine the text to be retrieved with each candidate text in the candidate text set into text pairs, input the text pairs into a cross-encoder model, the cross-encoder model calculates a relevance score based on the context information of the text pairs, and sorts the candidate text set in descending order according to the relevance score to obtain an initial search result; Input the initial search result into a text optimization model based on a knowledge graph. The text optimization model based on the knowledge graph includes a knowledge entity extraction module and an entity relationship reasoning module. Identify key entities from the initial search result through the knowledge entity extraction module, analyze the association relationship between the key entities based on a preset knowledge graph through the entity relationship reasoning module, and re-rank and filter the initial search result according to the association relationship to obtain a final search result; Establish an entity association matrix according to the association relationship, where the rows and columns of the entity association matrix represent entities, and the matrix element value is the association strength value of the corresponding entity pair; calculate the first-order associated entity set of each entity, and the first-order associated entity set contains all entities directly connected to this entity; count the network centrality of each entity, and the network centrality is the size of the first-order associated entity set of this entity; Re-rank the initial search result according to the size of the network centrality; and delete the initial search results whose network centrality is less than a preset screening threshold to obtain a final search result.
2. The method according to claim 1, characterized in that, Generating a first semantic vector of the text to be retrieved through the pre-trained large language model includes: Input the text to be retrieved into the encoder layer of the pre-trained large language model. The encoder layer includes multiple Transformer structures, and each Transformer structure includes a self-attention sublayer and a feed-forward neural network sublayer; In the encoder layer, encode the position information of the tokens in the text to be retrieved into position vectors through position encoding, and combine the position vectors with the token-corresponding word embedding vectors to obtain an input vector sequence; the self-attention sublayer calculates an attention weight matrix based on the input vector sequence, and performs weighted fusion on the input vector sequence according to the attention weight matrix to obtain a context representation vector; the feed-forward neural network sublayer performs a non-linear transformation on the context representation vector to obtain a feature vector; A pooling layer is set at the output end of the encoder layer. The pooling layer adopts an attention pooling mechanism to perform weighted averaging on the feature vectors through learned attention weights to obtain the global semantic representation of the text. The global semantic representation is input into a dimension mapping layer, and the global semantic representation is mapped into a first semantic vector with a fixed dimension through the dimension mapping layer.
3. The method according to claim 1, wherein The text to be retrieved is combined with each candidate text in the candidate text set to form text pairs. The text pairs are input into a cross-encoder model. The cross-encoder model calculates a relevance score based on the context information of the text pairs, and performs a descending order sorting on the candidate text set according to the relevance score. The initial search results include: The text to be retrieved is concatenated and combined with each candidate text in the candidate text set according to a preset delimiter to generate a sequence of text pairs. The sequence of text pairs is input into a cross-encoder model. The cross-encoder model encodes the text to be retrieved and the candidate text respectively through a bidirectional Transformer structure to generate a first feature sequence of the text to be retrieved and a second feature sequence of the candidate text. The interaction features between the first feature sequence and the second feature sequence are calculated based on a multi-head cross-attention mechanism. Local semantic features in the interaction features are extracted through a one-dimensional convolutional neural network. The long-range dependence relationship in the interaction features is calculated through a self-attention layer to obtain global semantic features. The local semantic features and the global semantic features are adaptively weighted and summed to obtain a unified representation vector of the text pair. The unified representation vector is input into a fully-connected neural network of the cross-encoder model. The fully-connected neural network performs a non-linear transformation on the unified representation vector and outputs the relevance score of the text pair. The candidate text set is sorted in descending order according to the relevance score to generate a sorted list of candidate texts, and the sorted list of candidate texts is output as the initial search result.
4. The method according to claim 1, wherein The text optimization model based on the knowledge graph includes a knowledge entity extraction module and an entity relationship reasoning module. Key entities are identified from the initial search results through the knowledge entity extraction module, and the association relationships between the key entities are analyzed based on a preset knowledge graph through the entity relationship reasoning module, including: Each text content in the initial search results is subjected to sentence splitting processing and named entity recognition to obtain an entity annotation sequence. Entity linking is performed on the entity annotation sequence to match the identified entities with the standard entities in the knowledge graph. The occurrence frequency and position importance score of the entity in the text are calculated. The relevance score between the entity and the text theme is calculated in combination with the word vector. The entity importance score is generated through weighted calculation of the entity frequency, position importance score, and relevance score. Entities with entity importance scores greater than a preset scoring threshold are selected as the key entity set. Taking the entities in the key entity set as starting nodes, perform multi-hop relationship path search in the knowledge graph, filter out the relationship paths with credibility higher than the preset credibility threshold, extract the entity relationship triples included in the relationship paths, and calculate the relationship strength based on the occurrence frequencies of the head entity, tail entity, and relationship type in the entity relationship triples; Construct an entity relationship graph based on the relationship strength and the entity relationship triples, and perform node importance propagation in the entity relationship graph to obtain the final importance score of each entity.
5. The method according to claim 4, wherein Taking the entities in the key entity set as starting nodes, performing multi-hop relationship path search in the knowledge graph, and filtering out the relationship paths with credibility higher than the preset credibility threshold includes: Taking the starting node as the current search node, obtaining the adjacent node set and the corresponding relationship types of the current search node; calculating the credibility of each node in the adjacent node set, where the credibility is determined by the product of the node importance score, the relationship type weight, and the path attenuation factor. Among them, the node importance score is obtained by weighted summation of the in-degree, out-degree, and node attribute values of the node; the relationship type weight is determined by the ratio of the number of occurrences of the relationship corresponding to the node to the maximum relationship frequency; the path attenuation factor is determined based on the exponential relationship between the preset attenuation base and the current hop number; Selecting the nodes with credibility exceeding the preset credibility threshold as candidate nodes; recording the path information from the current search node to the candidate nodes; Recursively performing path search on each of the candidate nodes until the preset maximum hop number is reached or the search queue is empty, specifically including: Adding the candidate nodes to the node search queue; updating the node access status and marking the visited nodes; calculating the cumulative credibility of the current path information, where the cumulative credibility is the sum of the credibilities of all nodes on the path; when the search depth reaches the preset maximum hop number, storing the current path information and the cumulative credibility into the path result set.
6. A text search system based on vector retrieval and large model optimization for implementing the method according to any one of claims 1-5, characterized in that, Including: The first unit is used to obtain the text to be retrieved, input the text to be retrieved into a pre-trained large language model, and generate a first semantic vector of the text to be retrieved through the pre-trained large language model. Among them, the large language model includes an encoder layer with a multi-layer transformer structure; The second unit is used to perform similarity calculation in the vector retrieval database based on the first semantic vector to obtain a candidate text set with similarity greater than the preset similarity threshold to the first semantic vector; The third unit is used to combine the text to be retrieved with each candidate text in the candidate text set into a text pair, input the text pair into a cross-encoder model, the cross-encoder model calculates a relevance score based on the context information of the text pair, and sorts the candidate text set in descending order according to the relevance score to obtain an initial search result; A fourth unit is configured to input the initial search results into a text optimization model based on a knowledge graph. The text optimization model based on the knowledge graph includes a knowledge entity extraction module and an entity relationship reasoning module. The knowledge entity extraction module is configured to identify key entities from the initial search results, and the entity relationship reasoning module is configured to analyze the association relationships between the key entities based on a preset knowledge graph, and reorder and filter the initial search results according to the association relationships to obtain final search results.
7. An electronic device, characterized in that, Comprising: A processor; A memory for storing instructions executable by the processor; Wherein, the processor is configured to call the instructions stored in the memory to execute the method according to any one of claims 1 to 5.
8. A computer-readable storage medium having computer program instructions stored thereon, characterized in that, The computer program instructions, when executed by the processor, implement the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Data search method and device based on knowledge graph and electronic equipment
CN117076599A
Knowledge graph searching method and system based on local semantics and global communitization
CN119577098A