Vector database text recall method and device, equipment and medium
By conducting keyword extraction and comparative learning model training on the database text data set, the problem of alignment and uniformity of positive and negative samples in text recall is solved, the similarity score of text vector matching is improved, and the text recall effect of the vector database is improved. .
Patent Information
- Application Number
- CN202410639974.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2024-09-27
AI Technical Summary
In the process of user question vectorization and text vector similarity matching, existing text recall technology has problems such as keyword information being ignored, word order and grammatical structure not being considered, synonyms and polysemy processing capabilities being insufficient, and negative sample selection affecting the model training effect. , leading to defects in the alignment and uniformity of positive and negative samples in the text vector space, affecting the recall effect.
Through keyword extraction and fine screening of the database text data set, a mapping index file is constructed, and the SentenceTransformer model is used for fine-tuning. Through comparative learning model training, keyword vector features are added, the positive and negative sample data sets are optimized, and the text length-based The penalty function constructs a training loss function to improve the similarity score of text vector matching.
It improves the similarity score of text vector matching, improves the text recall effect of the vector database, solves the alignment and uniformity defects of positive and negative samples in the text vector space, and enhances the accuracy and efficiency of text recall.
Smart Images

Figure CN118708674A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a vector database text recall method, device, equipment and medium. Background Art
[0002] Text recall is a technology that vectorizes user questions and matches them with text datasets to recall semantically similar text data. Its core idea is to convert text data into vector representations in a high-dimensional space and perform efficient retrieval and recall based on these vectors. Therefore, text recall technology has a wide range of applications in information retrieval, question-answering systems, and other fields.
[0003] The common method for vectorizing user query sentences in the text recall process is the BERT-based text vectorization algorithm. The basic idea of this algorithm is to use the pre-trained language model BERT for supervised training, and obtain sentence vector representation through a single BERT in the model inference stage. The disadvantage of this algorithm is that it relies on the quality of training data. In addition, the BERT model uses single character-level features during pre-training, and divides continuous words into characters for separate masking. In terms of model structure, it ignores the keyword information in the prominent user query sentence.
[0004] Commonly used model algorithms for text vector similarity matching in the text recall process include the TF-IDF model algorithm based on the vector space model and the Siamese-Network-BERT model algorithm based on deep learning. The defect of the TF-IDF model algorithm based on the vector space model is that it ignores the word order and grammatical structure and only considers the frequency of words. Even if the word order of two texts is completely different, TF-IDF will still consider them similar and cannot reflect the real semantic information; furthermore, it cannot identify and process synonyms and polysemous words. The Siamese-Network-BERT model is a twin network. Its two sub-networks use the BERT model, and the two BERT models share parameters. When comparing the similarity between two texts, they are input into the BERT model respectively, and the output is the vector representing the sentence of the two, and then the similarity between the two is calculated. It has a strong dependence on the quality of negative sample data. During the model training process, it is necessary to compare positive samples (similar) and negative samples (dissimilar). If the negative sample is not selected properly, it may affect the training effect of the model. Although Siamese-Network-BERT reduces the number of model parameter gradient updates and speeds up training by sharing neural network weights, its shortcomings are also very obvious. Siamese-Network-BERT encodes the input text separately to obtain feature vectors, and seriously lacks information interaction features between texts, resulting in defects in alignment and uniformity in the text vector space. Summary of the invention
[0005] In view of this, the embodiments of the present application provide a vector database text recall method, device, equipment and medium, which extracts keywords from the text data set in the database, adds keyword vector features when vectorizing the text, and then uses a comparative learning method to solve the alignment and uniformity defects of positive and negative samples in the text vector space, thereby improving the text vector matching similarity score and enhancing the text recall effect of the vector database.
[0006] The embodiment of the present application provides the following technical solution: a vector database text recall method, comprising:
[0007] Acquire a text data set, and extract candidate keywords from the text data set;
[0008] Performing fine screening on the candidate keywords, taking the screening results as final keywords, and constructing a mapping index file between the final keywords and the text data set;
[0009] Fine-tune the SentenceTransformer model using the final keywords to obtain a fine-tuned SentenceTransformer model;
[0010] Obtaining a user query statement, performing text matching between the user query statement and the text data set, and determining a positive sample data text pair and a negative sample data text pair according to the matching result;
[0011] According to the mapping index file, keywords corresponding to the text are added to the text data prefixes in the positive sample data text pair and the negative sample data text pair respectively to obtain positive and negative sample data sets;
[0012] Using the positive and negative sample data sets to train model parameters of a contrastive learning model to obtain a trained contrastive learning model;
[0013] The user query statement is input into the fine-tuned SentenceTransformer model and the trained contrastive learning model in sequence, the output result of the contrastive learning model is matched with the text dataset, and the text with the highest similarity score in the matching result is taken as the text recall result.
[0014] According to an embodiment of the present application, obtaining a text data set and extracting candidate keywords from the text data set include:
[0015] Perform word segmentation on the text in the text data set, and then vectorize the word segmentation results to obtain candidate word vectors;
[0016] The similarity between the candidate word vector and the text data set is calculated, and the candidate word vectors whose similarity scores exceed a set threshold are subjected to part-of-speech filtering to be used as the candidate keywords.
[0017] According to an embodiment of the present application, the candidate keywords are finely screened and the screening results are used as final keywords, including:
[0018] The candidate keywords are carefully screened through a large language model, and the screening results are used as final keywords.
[0019] According to an embodiment of the present application, determining a positive sample data text pair and a negative sample data text pair according to the matching result includes:
[0020] The texts with correct matching results are taken as the positive sample data text pairs; and the multiple texts with similarity scores exceeding a set value in the texts with incorrect matching results are taken as the negative sample data text pairs.
[0021] According to an embodiment of the present application, it also includes: determining the positive sample data text pair after multiple oversampling operations.
[0022] According to an embodiment of the present application, the model parameters of the contrastive learning model are trained using the positive and negative sample data sets to obtain the trained contrastive learning model, including:
[0023] A penalty function based on text length is set, the similarity between texts is calculated according to the penalty function, a model training loss function of the contrastive learning model is constructed according to the similarity between the texts and the positive and negative sample data sets, and the model parameters of the contrastive learning model are trained through the model training loss function.
[0024] According to an embodiment of the present application, the formula of the penalty function based on text length is as follows:
[0025] LenPenalty=log(|len(A)-len(B)|+1.01)
[0026] Among them, LenPenalty represents the penalty function, A and B represent text A and text B respectively;
[0027] The formula for the similarity between the texts is as follows:
[0028]
[0029] Among them, Sim(A, B) represents the similarity between text A and text B, and LenPenalty(A, B) represents the penalty function between text A and text B.
[0030] The present application also provides a vector database text recall device, comprising:
[0031] A keyword extraction module, used to obtain a text data set and extract candidate keywords from the text data set;
[0032] The keyword extraction module is further used to perform fine screening on the candidate keywords, use the screening results as final keywords, and construct a mapping index file between the final keywords and the text data set;
[0033] A model fine-tuning module, used to fine-tune the SentenceTransformer model using the final keywords to obtain a fine-tuned SentenceTransformer model;
[0034] A training data set construction module is used to obtain a user query statement, perform text matching between the user query statement and the text data set, and determine a positive sample data text pair and a negative sample data text pair according to the matching result;
[0035] The training data set construction module is further used to add keywords corresponding to the text to the text data prefixes in the positive sample data text pair and the negative sample data text pair respectively according to the mapping index file to obtain positive and negative sample data sets;
[0036] A model training module, used to train the model parameters of the contrastive learning model using the positive and negative sample data sets to obtain a trained contrastive learning model;
[0037] The result output module is used to input the user query statement into the fine-tuned SentenceTransformer model and the trained contrastive learning model in sequence, perform text matching between the model output result and the text data set, and take the text with the highest similarity score in the matching result as the text recall result.
[0038] The present application also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned vector database text recall method when executing the computer program.
[0039] The present application also provides a computer-readable storage medium, which stores a computer program for executing the above-mentioned vector database text recall method.
[0040] Compared with the prior art, the beneficial effects that can be achieved by at least one of the above-mentioned technical solutions adopted in the embodiments of this specification include at least the following: The embodiments of the present invention include text keyword extraction and training of a comparative learning model. Preprocessing of keyword extraction is performed through the text data set of the database, and a keyword recognition model of user query statements based on deep learning is used to add keyword vector features when text vectorizing user query statements, which helps to improve the vector interaction feature matching between texts. Then, through the comparative learning model, the distance between positive sample data with high similarity in the text vector space is made smaller, and the distance between negative sample data with low similarity in the text vector space is made as large as possible, and at the same time, the similarity distribution between samples of the same type is made more uniform. The alignment and uniformity defects of positive and negative samples in the text vector space are solved, the text vector matching similarity score is improved, and the text recall effect of the vector database is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0042] Figure 1 It is a schematic diagram of a flow chart of a vector database text recall method according to an embodiment of the present invention;
[0043] Figure 2 It is a schematic diagram of the structure of a vector database text recall device according to an embodiment of the present invention;
[0044] Figure 3 It is a structural schematic diagram of the computer device of the present invention. DETAILED DESCRIPTION
[0045] The embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0046] The following describes the implementation methods of the present application through specific examples, and those skilled in the art can easily understand other advantages and effects of the present application from the contents disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The present application can also be implemented or applied through other different specific implementation methods, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that, in the absence of conflict, the following embodiments and the features in the embodiments can be combined with each other. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work belong to the scope of protection of the present application.
[0047] like Figure 1 As shown, an embodiment of the present invention provides a vector database text recall method, comprising:
[0048] S101. Obtain a text data set, and extract candidate keywords from the text data set;
[0049] S102. Perform fine screening on the candidate keywords, use the screening results as final keywords, and construct a mapping index file between the final keywords and the text data set;
[0050] S103. Fine-tune the SentenceTransformer model using the final keyword to obtain a fine-tuned SentenceTransformer model;
[0051] S104. Obtain a user query statement, perform text matching on the user query statement and the text data set, and determine a positive sample data text pair and a negative sample data text pair according to the matching result;
[0052] S105. According to the mapping index file, keywords corresponding to the text are added to the text data prefixes in the positive sample data text pair and the negative sample data text pair respectively to obtain positive and negative sample data sets;
[0053] S106. Using the positive and negative sample data sets to train the model parameters of the contrastive learning model to obtain a trained contrastive learning model;
[0054] S107. Input the user query statement into the fine-tuned SentenceTransformer model and the trained contrastive learning model in sequence, perform text matching on the output result of the contrastive learning model and the text dataset, and take the text with the highest similarity score in the matching result as the text recall result.
[0055] The embodiment of the present invention includes text keyword extraction and contrastive learning model training. The text data set of the database is used for preprocessing of keyword extraction, and the keyword recognition model of the user query statement based on deep learning is used to add keyword vector features when the user query statement is vectorized, which helps to improve the vector interaction feature matching between texts. Then, through the contrastive learning model, the alignment and uniformity defects of positive and negative samples in the text vector space are solved, so that the positive sample data with high similarity have a smaller distance in the text vector space, and the negative sample data with low similarity have a distance as large as possible in the text vector space. At the same time, the similarity distribution between similar samples is more uniform, thereby improving the text vector matching similarity score and improving the text recall effect of the vector database.
[0056] In the text recall process, when the user enters a query statement, the user's query statement needs to be converted into a vector representation. Then the similarity between the converted query vector and all text vectors in the vector database is calculated, and the text most similar to the query is returned as a result. In the embodiment of the present invention, the keyword extraction in the text data set is first performed, and the SentenceTransformer model is fine-tuned by the obtained keywords, so that when the user query statement is vectorized by the fine-tuned SentenceTransformer model, the keyword vector feature is added, the vector interaction feature matching between the texts is improved, and the text recall accuracy of the vector database is improved. On this basis, after adding keywords to the training data, the contrast learning model is trained. After the contrast learning model is used, the positive sample data with high similarity has a smaller distance in the text vector space, and the negative sample data with low similarity has a distance as large as possible in the text vector space. At the same time, the similarity distribution between similar samples is more uniform, thereby solving the alignment and uniformity defects of positive and negative samples in the text vector space, and ensuring the text recall quality of the vector database.
[0057] Specifically, in step S101, the text in the text data set is segmented, and then the segmentation results are vectorized to obtain candidate word vectors; the similarity between the candidate word vectors and the text data set is calculated, and the candidate word vectors whose similarity scores exceed a set threshold are filtered by part of speech as the candidate keywords.
[0058] The specific implementation includes the following steps:
[0059] Step 1.1: First, perform word segmentation on the text. Use the Jieba Chinese word segmentation tool to add professional entity nouns and terms required by the text dataset to the Jieba custom user dictionary to improve the accuracy of word segmentation. Input the word segmentation results into the Bert-Base-Chinese model, which is an open source Chinese BERT model, to obtain the candidate word vectors for each word.
[0060] Step 1.2: Then vectorize the text in the text dataset as a whole. Specifically, input the text into the SentenceTransformer model to obtain the text vector.
[0061] Step 1.3: Use the cosine similarity calculation method to calculate the vector similarity between the candidate word vector and the text vector. The formula is as follows:
[0062]
[0063] Cosine similarity measures the cosine value of the angle between two vectors. By calculating the inner product of two vectors and their respective norms, the cosine similarity can be obtained. The closer the cosine similarity score is to 1, the more similar the two vectors are. In this embodiment, candidate word vectors with a similarity score exceeding 0.8 are selected from the obtained similarity scores, and then through part-of-speech filtering, only nouns, verbs, or gerund phrases are retained as candidate keywords.
[0064] In step S102, the candidate keywords are finely screened by a language model, and the screening results are used as the final keywords, and then a mapping index file between the final keywords and the text dataset is constructed.
[0065] Specifically, the following steps are included:
[0066] Step 2.1: Construct a context Prompt statement from the candidate keywords and the text dataset, for example:
[0067] "<Instruction>Assume you are a text processing expert. Please carefully read the following text and screen out the real core keywords from the candidate keyword set.< / Instruction>
[0068] <Text>.... specific text content...< / Text>
[0069] <Candidate Keywords>[Vocabulary 1, Vocabulary 2, Vocabulary 3,...]< / Candidate Keywords>";
[0070] Step 2.2: Call the Qwen-Plus language model with the constructed context Prompt statement to obtain the final keywords after fine screening for each text, and construct a mapping index file between the final keywords and the text dataset.
[0071] In step S103, the SentenceTransformer model is fine-tuned using the final keywords, and the fine-tuned new SentenceTransformer model is saved.
[0072] The Sentence Transformer model is a natural language processing model that can classify or label a piece of text. The model uses the Transformer architecture, which can encode the input text and generate a vector representation of a fixed length. This vector representation can capture the semantic information of the input text. By comparing the vector representations of different sentences, the similarities or correlations between them can be determined, which can be used for classification tasks and improve classification accuracy. This embodiment fine-tunes the Sentence Transformer model through the final keywords obtained, so that when the user query statement is vectorized through the fine-tuned Sentence Transformer model, the keyword vector features are added, which improves the vector interaction feature matching between texts and improves the text recall accuracy of the vector database.
[0073] In step S104 and step S105, during the matching process, the texts with correct matching results are used as the positive sample data text pairs; and the multiple texts with similarity scores exceeding a set value in the texts with incorrect matching results are used as the negative sample data text pairs. Furthermore, the positive sample data text pairs are determined after multiple oversampling operations.
[0074] In specific implementation, the above-mentioned correct match and incorrect match standards are set according to the situation. Specifically, a similarity threshold can be set, and the situation where the similarity score is higher than the similarity threshold is identified as a "correct match", and the situation where the similarity score is lower than the similarity threshold is identified as a "false match". In addition, the three text pairs with the highest similarity scores are selected from the incorrectly matched text set as negative sample data text pairs. Using the mapping index file between keywords and texts, the keywords contained in the text are added to the text data prefix. In a further preferred embodiment, in order to balance the training data, the positive sample data text pairs are sampled three times.
[0075] In step S106, the model parameters of the contrastive learning model are trained using the positive and negative sample data sets to obtain the trained contrastive learning model, including: setting a penalty function based on text length, calculating the similarity between texts according to the penalty function, constructing a model training loss function of the contrastive learning model according to the similarity between the texts and the positive and negative sample data sets, and training the model parameters of the contrastive learning model through the model training loss function.
[0076] In the specific implementation, the loss function formula of the contrastive learning model training is constructed as follows:
[0077]
[0078] Among them, h = W*Text_Embedding, W is the model learning parameter, Text_Embedding is the text vector; (hi,hi+) is the text vector of the positive sample data text pair, (hi,hi-) is the text vector of the negative sample data text pair, and T is a hyperparameter. Sim is the similarity calculation formula, which is as follows:
[0079]
[0080] Among them, Sim(A, B) represents the similarity between text A and text B, and LenPenalty(A, B) represents the penalty function between text A and text B.
[0081] LenPenalty is a text length penalty function that alleviates the vector alignment problem caused by the large difference in length between text A and text B. The LenPenalty formula is as follows:
[0082] LenPenalty=log(|len(A)-len(B)|+1.01)
[0083] Among them, LenPenalty represents the penalty function, A and B represent text A and text B respectively.
[0084] like Figure 2 As shown, the present application also provides a vector database text recall device 200, comprising:
[0085] A keyword extraction module 201 is used to obtain a text data set and extract candidate keywords from the text data set;
[0086] The keyword extraction module 201 is further used to perform fine screening on the candidate keywords, use the screening results as final keywords, and construct a mapping index file between the final keywords and the text data set;
[0087] A model fine-tuning module 202, configured to fine-tune the SentenceTransformer model using the final keywords to obtain a fine-tuned SentenceTransformer model;
[0088] The training data set construction module 203 is used to obtain a user query statement, perform text matching between the user query statement and the text data set, and determine a positive sample data text pair and a negative sample data text pair according to the matching result;
[0089] The training data set construction module 203 is further used to add keywords corresponding to the text to the text data prefixes in the positive sample data text pair and the negative sample data text pair respectively according to the mapping index file to obtain positive and negative sample data sets;
[0090] A model training module 204 is used to train the model parameters of the contrastive learning model using the positive and negative sample data sets to obtain a trained contrastive learning model;
[0091] The result output module 205 is used to input the user query statement into the fine-tuned SentenceTransformer model and the trained contrastive learning model in sequence, perform text matching between the model output result and the text data set, and take the text with the highest similarity score in the matching result as the text recall result.
[0092] The vector database text recall device of the embodiment of the present invention extracts keywords from the text data set in the database, adds keyword vector features when vectorizing the text, and then uses a comparative learning method to solve the alignment and uniformity defects of positive and negative samples in the text vector space, thereby improving the text vector matching similarity score and enhancing the text recall effect of the vector database.
[0093] In specific implementation, the keyword extraction module 201 is used to perform word segmentation on the text in the text data set, and then vectorize the word segmentation results to obtain candidate word vectors; perform similarity calculation on the candidate word vectors and the text data set, and perform part-of-speech filtering on the candidate word vectors whose similarity scores exceed a set threshold to serve as the candidate keywords. The candidate keywords are then finely screened through a large language model, and the screening results are used as the final keywords.
[0094] The training data set construction module 203 is used to use the texts with correct matching results as the positive sample data text pairs; and use multiple texts with similarity scores exceeding a set value in the texts with incorrect matching results as the negative sample data text pairs.
[0095] The model training module 204 is used to set a penalty function based on text length, calculate the similarity between texts according to the penalty function, construct a model training loss function of the contrastive learning model according to the similarity between the texts and the positive and negative sample data sets, and train the model parameters of the contrastive learning model through the model training loss function.
[0096] In one embodiment, a computer device is provided, such as Figure 3 As shown, it includes a memory 301, a processor 302, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, any of the above-mentioned vector database text recall methods is implemented.
[0097] Specifically, the computer device may be a computer terminal, a server or a similar computing device.
[0098] In this embodiment, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program for executing any of the above-mentioned vector database text recall methods.
[0099] Specifically, computer-readable storage media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer-readable storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable storage media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0100] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present invention are not limited to any specific combination of hardware and software.
[0101] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A vector database text recall method, characterized in that: include: Acquire a text data set, and extract candidate keywords from the text data set; Performing fine screening on the candidate keywords, taking the screening results as final keywords, and constructing a mapping index file between the final keywords and the text data set; Fine-tune the SentenceTransformer model using the final keywords to obtain a fine-tuned SentenceTransformer model; Obtaining a user query statement, performing text matching on the user query statement and the text data set, and determining a positive sample data text pair and a negative sample data text pair according to the matching result; According to the mapping index file, keywords corresponding to the text are added to the text data prefixes in the positive sample data text pair and the negative sample data text pair respectively to obtain positive and negative sample data sets; Using the positive and negative sample data sets to train model parameters of a contrastive learning model to obtain a trained contrastive learning model; The user query statement is input into the fine-tuned SentenceTransformer model and the trained contrastive learning model in sequence, the output result of the contrastive learning model is matched with the text dataset, and the text with the highest similarity score in the matching result is taken as the text recall result.
2. The vector database text recall method according to claim 1, characterized in that: Obtaining a text data set, and extracting candidate keywords from the text data set, including: Perform word segmentation on the text in the text data set, and then vectorize the word segmentation results to obtain candidate word vectors; The similarity between the candidate word vector and the text data set is calculated, and the candidate word vectors whose similarity scores exceed a set threshold are subjected to part-of-speech filtering to be used as the candidate keywords.
3. The vector database text recall method according to claim 1, characterized in that: The candidate keywords are carefully screened and the screening results are used as the final keywords, including: The candidate keywords are carefully screened through a large language model, and the screening results are used as final keywords.
4. The vector database text recall method according to claim 1, characterized in that: According to the matching results, the positive sample data text pairs and the negative sample data text pairs are determined, including: The texts with correct matching results are taken as the positive sample data text pairs; and the multiple texts with similarity scores exceeding a set value in the texts with incorrect matching results are taken as the negative sample data text pairs.
5. The vector database text recall method according to claim 4, characterized in that: Also includes: The positive sample data text pair is determined after multiple oversampling operations.
6. The vector database text recall method according to claim 1, characterized in that: The model parameters of the contrastive learning model are trained using the positive and negative sample data sets to obtain the trained contrastive learning model, including: A penalty function based on text length is set, the similarity between texts is calculated according to the penalty function, a model training loss function of the contrastive learning model is constructed according to the similarity between the texts and the positive and negative sample data sets, and the model parameters of the contrastive learning model are trained through the model training loss function.
7. The vector database text recall method according to claim 6, characterized in that: The formula of the penalty function based on text length is as follows: LenPenalty=log(|len(A)-len(B)|+1.01) Among them, LenPenalty represents the penalty function, A and B represent text A and text B respectively; The formula for the similarity between the texts is as follows: Among them, Sim(A, B) represents the similarity between text A and text B, and LenPenalty(A, B) represents the penalty function between text A and text B.
8. A vector database text recall device, characterized in that: include: A keyword extraction module, used to obtain a text data set and extract candidate keywords from the text data set; The keyword extraction module is further used to perform fine screening on the candidate keywords, use the screening results as final keywords, and construct a mapping index file between the final keywords and the text data set; A model fine-tuning module, used to fine-tune the SentenceTransformer model using the final keywords to obtain a fine-tuned SentenceTransformer model; A training data set construction module is used to obtain a user query statement, perform text matching between the user query statement and the text data set, and determine a positive sample data text pair and a negative sample data text pair according to the matching result; The training data set construction module is further used to add keywords corresponding to the text to the text data prefixes in the positive sample data text pair and the negative sample data text pair respectively according to the mapping index file to obtain positive and negative sample data sets; A model training module, used to train the model parameters of the contrastive learning model using the positive and negative sample data sets to obtain a trained contrastive learning model; The result output module is used to input the user query statement into the fine-tuned SentenceTransformer model and the trained contrastive learning model in sequence, perform text matching between the model output result and the text data set, and take the text with the highest similarity score in the matching result as the text recall result.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the vector database text recall method described in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the vector database text recall method according to any one of claims 1 to 7.
Citation Information
Cited By
Method and device for constructing feature dictionary, electronic equipment and program product
CN119670745A
Method for constructing feature dictionary, device thereof, electronic device, and program product
CN119670745B
Training method of multi-modal retrieval model and multi-modal retrieval method and device
CN119807751A
