Electronic archive retrieval method and system based on large language model
Generate documents and query vectors through large language models, and use semantic indexing technology to solve the problems of low retrieval efficiency and insufficient accuracy in electronic archives management systems, achieve efficient and intelligent archive retrieval, and improve user experience.
Patent Information
- Application Number
- CN202411124464.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-16
- Publication Date
- 2024-09-13
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing electronic archive management systems have deficiencies in retrieval efficiency and accuracy. Especially as the number of electronic archives increases, traditional keyword matching methods are difficult to handle complex situations, resulting in low retrieval efficiency, low accuracy, and poor user experience.
An electronic archive retrieval method based on a large language model is adopted. Through document vector database and semantic indexing technology, pre-trained models such as BERT are used to generate documents and query vectors for in-depth semantic understanding and analysis to achieve efficient retrieval and accurate matching.
It significantly improves the accuracy and intelligence level of archive retrieval, improves user experience, provides more comprehensive and relevant retrieval results, and solves the problems of low retrieval efficiency and insufficient accuracy in traditional methods.
Smart Images

Figure CN118643148A
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of artificial intelligence and archive retrieval, and in particular relates to an electronic archive retrieval method and system based on a large language model. Background Art
[0002] Compared with traditional paper archives, electronic archives have the advantages of easy storage, convenient retrieval, and fast information transmission. However, with the rapid increase in the number of electronic archives, how to efficiently manage and use these archives has become an urgent problem to be solved.
[0003] Early electronic archive management systems were mainly based on simple electronic file storage, with relatively simple functions, mainly including document storage, retrieval and simple classification management. These systems usually rely on basic keyword matching and metadata indexing technology to achieve document retrieval. However, with the continuous increase in the number of electronic archives and the increasing complexity of user needs, these traditional methods have gradually shown many shortcomings in performance and effect. First, the retrieval efficiency is low. With the rapid increase in the number of electronic archives, the traditional keyword retrieval method needs to match a large number of documents, and the retrieval efficiency has dropped significantly. Secondly, the accuracy is insufficient. Keyword matching depends on the precise words entered by the user, and it is difficult to handle complex situations such as synonyms and polysemous words, resulting in low accuracy of retrieval results. In addition, the user experience is poor. When searching, users need to master certain professional knowledge and understand specific keywords or document structures, which increases the difficulty and threshold of use.
[0004] In recent years, large language models (such as GPT, BERT, etc.) have made significant progress in the field of natural language processing. These models can understand and generate natural language by training massive amounts of text data, and have powerful language understanding and processing capabilities. This has led to the widespread use of large language models in many application scenarios, such as text generation, automatic question answering, and machine translation. Although the application of large language models to the field of electronic archive management is still in its infancy, it has great potential.
[0005] How to effectively combine large language models with electronic archive retrieval systems is one of the effective ways to solve the problems of low efficiency, insufficient accuracy and poor user experience in traditional electronic document retrieval. Summary of the invention
[0006] In order to solve the deficiencies of the prior art, improve retrieval efficiency, retrieval accuracy, and enhance user experience, the present invention adopts the following technical solutions:
[0007] The electronic archive retrieval method based on the large language model includes the following steps:
[0008] Step S1, obtaining electronic archive data to construct a document vector database and extracting a summary;
[0009] Step S2: using the pre-trained model, convert the extracted summary document into a document vector, which can better capture the characteristics of the document and facilitate the subsequent storage and retrieval process;
[0010] Step S3, storing the electronic file and the document vector obtained in step S2 in a document vector database for efficient retrieval and use, and then constructing a semantic index through the document vector to help quickly find and access specific data in the document vector database and quickly obtain required information;
[0011] Step S4: Generate a query vector based on the retrieval query content and the extended content using the pre-trained model;
[0012] Step S5: performing document retrieval through the semantic index based on the similarity between the query vector and the document vector;
[0013] Step S6: Output the search results according to the similarity sorting.
[0014] Furthermore, in the step S1, the document data is preprocessed, and / or in the step S4, the query vector is preprocessed, the preprocessing includes text cleaning, punctuation processing, word segmentation, stop word removal, stemming and word form restoration, to ensure that the data is pure, unified and standardized, thereby improving the effect of natural language processing;
[0015] Text cleaning is to ensure that the data input into the system is pure text data by removing elements that do not belong to the text content in the document. Its role is to reduce interference with subsequent processing steps, thereby improving processing efficiency and accuracy;
[0016] Punctuation processing refers to the normalization and cleaning of punctuation in documents to ensure that the data input into the system has consistent punctuation usage rules. Its role is to help with word segmentation and grammatical analysis, and improve the accuracy of subsequent processing steps;
[0017] Word segmentation refers to the process of dividing a continuous text string into independent words or phrases according to certain rules. Its function is to decompose the text into basic language units to facilitate subsequent text analysis and processing.
[0018] Stop word removal is to delete words that appear frequently in the text but do not contribute much to semantic understanding, which helps reduce data redundancy, improve processing efficiency, and allow the model to focus more on meaningful words;
[0019] Stemming is the process of restoring words to their basic form. By reducing the number of word variants, the model can recognize words with the same root but different morphology.
[0020] Lemmatization is the process of converting words to their lexical form, thereby improving the accuracy of semantic analysis.
[0021] Furthermore, in step S1, the document data is subjected to document summary extraction by using the trained large language model to extract and retain key descriptive features from the document; the model is subjected to autoregressive training to predict the next word one by one based on all the previous words, thereby performing well in generating coherent paragraphs and articles. The specific process is as follows:
[0022] First, the preprocessed document data is converted into a word vector sequence X={x1,x2,…,x n}, these word vectors are converted into vector representations of fixed dimensions through the embedding layer;
[0023] Next, the input sequence is encoded through a multi-layer Transformer, each layer of which contains a self-attention mechanism and a feedforward neural network. The self-attention mechanism allows the model to focus on important words and contextual relationships in the document and generate a contextual representation H={h1,h2,…,h n}, During the encoding process, the output of each layer will be used as the input of the next layer, continuously accumulating and optimizing context information;
[0024] After the encoding is completed, the decoding part starts to generate the summary. The summary generation process is expressed as:
[0025]
[0026] Among them, P(y i |y 1:i1 ,X) represents the probability of generating the i-th word given the previously generated words and the input document; the decoding takes the final output of the encoding as the initial input, and combines the previously generated summary words to generate the target summary sequence Y={y1,y2,…,y m}, each word y i are all words generated before the given i-1} and the input document, ensuring that the generated summary is both coherent and can accurately reflect the main content of the original text.
[0027] Furthermore, in step S2, the BERT pre-trained model is used to generate a text vector, and / or in step S4, the pre-trained model is used to generate a query vector, including the following steps:
[0028] Step S2.1, load the BERT pre-trained model;
[0029] Step S2.2, perform BERT text encoding on the text content; add tags to both ends of the text sequence to obtain the original input, and map the original input according to the word vector, block vector and position vector to obtain the text encoding of the BERT pre-trained model;
[0030] Step S2.3: Input the text encoding into the encoding layer of the BERT pre-trained model, encode it based on the multi-head attention mechanism and feedforward network, and obtain the corresponding document vector.
[0031] Furthermore, in step S2.2, the input representation of BERT is composed of the sum of the word vector, the block vector, and the position vector;
[0032] E=E token +E segment +E position
[0033] Among them, E token Represents word vector, E segment represents the block vector, E position represents the position vector;
[0034] The word vector maps each word or subword of the input into a vector representation of a fixed dimension, y1,y2,…,y i represents the input sequence, where y i Represents the i-th word, then the word vector is expressed as:
[0035]
[0036] The block vector is used to distinguish different sentences in the two-sentence pair task. Each word is assigned a segmentation embedding according to the sentence it belongs to, E A represents the segmentation embedding of the first sentence, E B represents the segmentation embedding of the second sentence, then the segmentation embedding is expressed as:
[0037] E segment ={E A ,E A ,…,E A ,E B ,E B ,…,E B}
[0038] The position vector represents the position of each word in the sequence, n represents the length of the input sequence, and the position embedding is expressed as:
[0039] E position ={E0,E1,…,E n-1}
[0040] For the input text sequence y1,y2,…,yi , add BERT model specific tags [CLS] and [SEP] at both ends of the sequence to get the original input of the model:
[0041] Y=[CLS] y1,y2,…,y i [SEP]
[0042] Map Y by word vector, block vector, and position vector to get the text encoding of the model:
[0043] E = InputRepresentation(Y)
[0044] In step S2.3, after multiple layers of Transformer encoding, the text encoding E uses the [CLS] tag at the beginning of the text as the text feature representation in the output generated by the last layer, that is, the required document vector, thereby completing the feature extraction process of the encoder. The formula is as follows:
[0045]
[0046] Among them, T represents the feature representation corresponding to the text encoding E, TransformerLayer i Represents the i-th layer Transformer encoder, T output at the last layer [cls] As a feature representation of text.
[0047] Further, in step S2.3, the encoding layer of the BERT pre-trained model includes multiple Transformer encoders, wherein the Transformer encoder includes a multi-head attention sublayer and a feedforward network sublayer;
[0048] The multi-head attention layer passes the input sequence through three different weight matrices to obtain Q, K, and V matrices, and divides these matrices into multiple heads through the multi-head attention mechanism, each with a dimension of d k , calculated in independent subspaces, each head has its own unique weight matrix, mapping Q, K, V to Q i , K i 、V i , the attention weight is calculated using the scaled dot product attention mechanism, that is, the dot product of the query Q and the key K is calculated first, the weight is obtained by activating the softmax function after scaling, and then multiplied by the value V matrix to obtain the output of each head. The outputs of all heads are concatenated into a long vector, and finally mapped back to the original dimension through a linear transformation to obtain the final output;
[0049] The feed-forward network sublayer consists of two linear layers and a ReLU activation function, which provides nonlinear transformation for Transformer;
[0050] For the multi-head attention sub-layer and the feed-forward network sub-layer, their outputs need to pass through an additional residual layer.
[0051] Furthermore, the calculation formula of the multi-head attention layer is as follows:
[0052]
[0053]
[0054]
[0055]
[0056]
[0057] Among them, W Q , W K and W V represents the weight matrix, , , represents the weight matrix unique to each head, represents the scaling factor, MultiHead represents the multi-head attention mechanism, and W o represents the final weight matrix;
[0058] The calculation formula of the feedforward network sublayer is as follows:
[0059]
[0060] Among them, x represents the input, W1 and W2 represent the weights of the two linear layers, and b1 and b2 represent the biases of the two linear layers;
[0061] The residual layer calculation formula is as follows:
[0062]
[0063] Among them, SubLayer represents the multi-head attention sublayer and the feedforward network sublayer, and LayerNorm represents layer normalization.
[0064] Furthermore, in step S4, query expansion is performed on the acquired search query content, and a query vector is generated based on the search query content and the expanded content. The query expansion includes the following steps:
[0065] Step S4.1.1, through the continuous bag of words model, the input query word is converted into a vector in the form of one-hot encoding, and the result obtained by multiplying the vector with the weight matrix between the input layer and the hidden layer is used as the output of the hidden layer, the output of the hidden layer is multiplied by the weight matrix from the hidden layer to the output layer, and the normalized probability is used to predict the word;
[0066] Step S4.1.2: Train the continuous bag-of-words model based on the loss function. The loss function is as follows:
[0067]
[0068] in, represents the loss function, N represents the total number of words in the training sample, represents the i-th target word, Represents the probability of predicting the i-th target word.
[0069] Furthermore, the similarity calculation in step S3 and / or step S5 is performed by constructing a vector graph with a multi-level structure, and performing similarity calculation from top to bottom based on the insertion vector to obtain a multi-level graph structure of the insertion vector and similar vectors of each layer, using a cosine similarity function, and the formula is as follows:
[0070]
[0071] Among them, A represents the new vector to be inserted, B represents the node vector of the current layer, A·B represents the dot product of the new vector A and the node vector B, and ||A|| and ||B|| represent the Euclidean norm of vectors A and B respectively (i.e., the length of the vector).
[0072] The electronic archive retrieval system based on the large language model includes a document extraction module, a document vector generation module, a semantic indexing module, a query vector generation module, and a document retrieval module;
[0073] The document extraction module is used to obtain electronic archive data to construct a document vector database and perform summary extraction;
[0074] The document vector generation module converts the extracted summary document into a document vector using a pre-trained model. The document vector can better capture the characteristics of the document and facilitate subsequent storage and retrieval processes.
[0075] The semantic indexing module stores the electronic archive and the document vector obtained in step S2 in a document vector database for efficient retrieval and use, and then constructs a semantic index through the document vector to help quickly find and access specific data in the document vector database and quickly obtain required information;
[0076] The query vector generation module generates a query vector based on the retrieval query content and the extended content using a pre-trained model;
[0077] The document retrieval module performs document retrieval through the semantic index based on the similarity between the query vector and the document vector, and outputs the retrieval results according to the similarity ranking.
[0078] The advantages and beneficial effects of the present invention are:
[0079] The present invention combines a large language model with electronic archives, and uses the powerful natural language processing capabilities of the large language model to perform in-depth semantic understanding and analysis of electronic archives. For the intelligent retrieval function, the large language model performs semantic understanding and analysis of queries, no longer relying on a single keyword match, but instead generates queries with similar contexts of words and phrases through query expansion, and then uses semantic retrieval to deeply understand the semantics of the query statement for more accurate matching, thereby significantly improving the accuracy and intelligence level of archive retrieval. This not only improves the intelligence level and work efficiency of archive management, but also provides a new solution for archive retrieval of various organizations. BRIEF DESCRIPTION OF THE DRAWINGS
[0080] Figure 1 It is a flow chart of an electronic archive retrieval method based on a large language model in an embodiment of the present invention.
[0081] Figure 2 It is a structural diagram of an electronic archive retrieval system based on a large language model in an embodiment of the present invention. DETAILED DESCRIPTION
[0082] The specific implementation of the present invention is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described here is only used to illustrate and explain the present invention, and is not used to limit the present invention.
[0083] Today's electronic archive management systems have many problems in the efficient management and use of archives, such as inaccurate retrieval results caused by reliance on keyword searches, and low retrieval efficiency. Therefore, the present invention proposes an electronic archive retrieval method based on a large language model. First, the original archive data is collected and preprocessed and document summaries are extracted. The BERT model is then used to convert the document data into document vectors, and then the documents and document vectors are stored in a document vector database, and a semantic index is constructed for fast search and access to specific data. For natural language queries entered by users through the system, query expansion is first performed and then converted into query vectors through the BERT model. Finally, the similarity between the query vector and the document vector is calculated, and the results are sorted accordingly to ensure that the most accurate and relevant retrieval results are displayed to users first, such as Figure 1 As shown, the specific steps include:
[0084] Step S1: Collect the original electronic file data to construct a document vector database, and perform preprocessing and document summary extraction on the document data.
[0085] In the constructed document vector database, the document set is represented as D = {d1, d2, …, d i , …, d n}, where d i represents the i-th document data in the document set D, and n represents the total number of data.
[0086] The preprocessing and document summary extraction include the following steps:
[0087] Step S1.1: Preprocess the collected document data, specifically including steps such as text cleaning, punctuation processing, word segmentation, stop word removal, stemming, and lemmatization, to facilitate subsequent processing.
[0088] Text cleaning refers to removing elements that do not belong to the text content in the document, such as HTML tags, special symbols, formatting errors, etc., to ensure that the data input into the system is pure text data. Its role is to reduce interference in subsequent processing steps, thereby improving processing efficiency and accuracy.
[0089] Punctuation processing refers to normalizing and cleaning the punctuation marks in the document, such as removing unnecessary punctuation marks, unifying the punctuation mark format, etc., to ensure that the data input into the system has consistent punctuation mark usage rules. Its role is to assist in word segmentation and syntactic analysis, improving the accuracy of subsequent processing steps.
[0090] Word segmentation refers to splitting continuous text strings into independent words or phrases according to certain rules, such as using a dictionary or statistical methods for word segmentation. Its role is to decompose the text into basic language units, facilitating subsequent text analysis and processing, such as semantic analysis, text classification, and information retrieval.
[0091] Stop word removal is to delete words that frequently appear in the text but contribute little to semantic understanding, such as "de", "shi", "zai", etc. This helps reduce data redundancy, improve processing efficiency, and enable the model to focus more on meaningful words.
[0092] Stemming is a technique that reduces words to their basic forms. For example, reducing "running" to "run". By reducing the number of word variants, stemming enables the model to recognize words with the same root but different forms.
[0093] Lemmatization is similar to stemming, which is the process of converting words into their dictionary form, such as unifying different tenses of verbs into a basic tense, thereby improving the accuracy of semantic analysis. Taken together, these technologies work together in the text preprocessing stage to ensure that the data is clean, unified, and standardized, thereby improving the effect of natural language processing.
[0094] Step S1.2: The pre-processed document data is summarized by a large language model, which can extract and retain key descriptive features from the document. These comprehensive measures interact with each other and ultimately improve the efficiency and accuracy of the system.
[0095] In an embodiment of the present invention, the large language model adopts the GPT pre-training model. GPT (Generative Pre-trained Transformer) is a pre-training model for natural language processing. Unlike previous unidirectional language models or shallow feature representation models, GPT uses the Transformer architecture in the pre-training stage. It trains the autoregressive language model (Autoregressive Language Model) of a large-scale corpus to capture the deep semantic relationship between vocabulary and context. The autoregressive task can be described as given a piece of text, the model needs to predict the next word one by one based on all the previous words. Unlike BERT, the GPT model is unidirectional, that is, when generating the next word, only the previously generated words are considered. This method enables GPT to perform well in generating coherent paragraphs and articles. The specific process is as follows:
[0096] First, the preprocessed document data is converted into a word vector sequence X={x1,x2,…,x n}. These word vectors are converted into vector representations of fixed dimensions through an embedding layer.
[0097] Next, the input sequence is encoded through a multi-layer Transformer, each layer of which contains a self-attention mechanism and a feed-forward neural network. The self-attention mechanism allows the model to focus on important words and contextual relationships in the document, thereby generating a contextual representation H={h1,h2,…,h n During the encoding process, the output of each layer will be used as the input of the next layer, continuously accumulating and optimizing contextual information.
[0098] After the encoding is completed, the decoder part starts to generate the summary. The summary generation process is expressed as:
[0099]
[0100] Among them, P(y i |y 1:i1,X), represents the probability of generating the i-th word given the previously generated words and the input document.
[0101] The decoder uses the final output of the encoder as the initial input, and combines the previously generated summary words to generate the target summary sequence Y={y1,y2,…,y m}, each word y i are all words generated before the given i-1} and the input document, ensuring that the generated summary is both coherent and can accurately reflect the main content of the original text.
[0102] Step S2: Generate document vectors. Using the BERT model, convert the documents preprocessed and extracted in S1 into document vector representations. Document vectors can better capture the characteristics of documents and facilitate subsequent storage and retrieval processes.
[0103] In an embodiment of the present invention, a BERT (Bidirectional Encoder Representations from Transformers) pre-training model is used to generate text vectors. BERT is an advanced natural language processing model that revolutionizes traditional unidirectional language models and shallow feature representation models. In the pre-training stage, BERT uses a bidirectional Transformer architecture and is trained by performing Masked Language Model (MLM) and Next Sentence Prediction (NSP) tasks on a large-scale corpus to capture the deep semantic relationship between vocabulary and its context. The Masked Language Model MLM task involves randomly erasing one or more words in a given sentence, and then the model predicts these erased words based on the remaining vocabulary. The next sentence prediction NSP task is given two sentences, and the model needs to determine whether the second sentence follows the first sentence in the original text. Specifically, it includes the following steps:
[0104] Step S2.1, load the BERT pre-trained model;
[0105] Since the parameters of the BERT pre-trained model are not affected by specific tasks, the trained parameters can be used directly. The pre-trained model used in the present invention is from BERT-Base-Chinese released by Google, which uses Chinese Wikipedia as a corpus, including 25 million sentences.
[0106] Step S2.2: Perform BERT text encoding on the data that has been preprocessed and summarized in S1.
[0107] The input representation of BERT consists of the sum of word vectors, block vectors, and position vectors;
[0108] E=E token +E segment +E position
[0109] Among them, E token Represents word vector, E segment represents the block vector, E position Represents the position vector.
[0110] The word vector maps each word or subword of the input into a vector representation of a fixed dimension. Let the input sequence be y1, y2, …, y i , where y i Represents the i-th word, then the word vector can be expressed as:
[0111]
[0112] The chunk vector is used to distinguish different sentences in the two sentence pair task. Each word is assigned a segmentation embedding according to the sentence it belongs to. The segmentation embedding of the first sentence is denoted as E A , the segmentation embedding of the second sentence is E B , then the segmentation embedding can be expressed as:
[0113] E segment ={E A ,E A ,…,E A ,E B ,E B ,…,E B}
[0114] The position vector represents the position of each word in the sequence. Let the length of the input sequence be n, then the position embedding can be expressed as:
[0115] E position ={E0,E1,…,E n-1}
[0116] For the text sequence y1,y2,…,y i For example, specific tags of the BERT model are added to both ends of the sequence, that is, a [CLS] and [SEP] field needs to be added before and after the text respectively, so as to obtain the original input Y of the model.
[0117] Y=[CLS] y1,y2,…,y i [SEP]
[0118] Next, Y is mapped according to the above word vector, block vector, and position vector processing methods to obtain the text encoding E of the model.
[0119] E = InputRepresentation(Y)
[0120] Step S2.3: Input the text encoding into the encoding layer of BERT to generate a document vector.
[0121] In the encoding layer of the BERT model, there are multiple encoder parts of the Transformer model, of which the basic version of BERT has 12 layers and the large version of BERT has 24 layers. The Transformer encoder part consists of two main sublayers: the multi-head attention sublayer and the feedforward network sublayer. In addition, each sublayer is followed by a residual connection layer.
[0122] The multi-head attention layer passes the input sequence through three different weight matrices to obtain Q, K, and V matrices. The multi-head attention mechanism divides these matrices into multiple heads, each with a dimension of d k , calculated in independent subspaces, each head has its own unique weight matrix, mapping Q, K, V to Q i , K i 、V i Next, the attention weights are calculated using the scaled dot product attention mechanism: the dot product of the query and the key is calculated first, scaled and passed through the softmax function to get the weights, and then multiplied by the value matrix to get the output of each head. The outputs of all heads are concatenated into a long vector, and finally mapped back to the original dimension through a linear transformation to get the final output.
[0123]
[0124]
[0125]
[0126]
[0127]
[0128] Among them, W Q , W K and W V is the weight matrix, , , is a weight matrix unique to each head, is the scaling factor, MultiHead represents the multi-head attention mechanism, and W o is the final weight matrix.
[0129] The feed-forward network sublayer consists of two linear layers and a ReLU activation function, which provides nonlinear transformation for the Transformer.
[0130]
[0131] For the multi-head attention sub-layer and the feed-forward network sub-layer, their outputs need to go through an additional residual layer:
[0132]
[0133] Among them, SubLayer represents the multi-head attention sublayer and the feedforward network sublayer, and LayerNorm represents layer normalization.
[0134] After multiple layers of Transformer encoding, the text encoder E uses the [CLS] tag at the beginning of the text as the text feature representation in the output generated by the last layer, that is, the required document vector, thus completing the feature extraction process of the encoder.
[0135]
[0136] Among them, TransformerLayer i Represents the i-th layer Transformer encoder, T output at the last layer [cls] As a feature representation of text.
[0137] Step S3: Build a semantic index. The document and the document vector obtained in step S2 are stored in a document vector database for efficient retrieval and use. Then, a semantic index is built through the document vector to help quickly find and access specific data in the document vector database and quickly obtain the required information.
[0138] In an embodiment of the present invention, the document vector database adopts Elasticsearch, which is an innovative search and analysis tool that combines traditional inverted indexes with modern vector representation methods. By using natural language processing technology to generate high-dimensional vectors, Elasticsearch can capture the semantic similarities between documents, thereby achieving more accurate search and recommendation. When a query is received, Elasticsearch not only performs keyword matching, but also uses document embedding vectors for similarity searches to find semantically related documents. The document vector database supports the creation of indexes containing vector fields and performs efficient queries based on these vectors, significantly improving the relevance and accuracy of search results, and performs particularly well in fields such as recommendation systems, information retrieval, and large-scale text data analysis.
[0139] First, upload the document and the document vector data obtained from S2 to the document vector database. In this process, ensure that each document vector is accurately mapped to the corresponding specific document. Next, Elasticsearch uses the HNSW (Hierarchical Navigable Small World) algorithm to build a semantic vector index.
[0140] The HNSW algorithm organizes vectors by creating a multi-level small world graph. This multi-level structure enables vectors to be approximated for nearest neighbor search in an efficient manner. When a new vector is inserted, it is first inserted into the highest level. In the highest level, a starting node is randomly selected and then navigated down layer by layer from this node. In each layer, the cosine similarity is used to calculate the similarity between the new vector and all nodes in the current layer.
[0141] As the vector is inserted downwards, at each layer, the new vector is connected to the most similar nodes. These nodes are selected based on the results of the cosine similarity calculation. This process is repeated until the new vector reaches the bottom layer. Eventually, the new vector is connected to the most similar nodes in each layer, forming a multi-level graph structure.
[0142] The calculation formula of the cosine similarity function is:
[0143]
[0144] Where A is the new vector to be inserted, B is the node vector of the current layer, A·B is the dot product of the new vector A and the node vector B, and ||A|| and ||B|| are the Euclidean norms (i.e., the lengths of the vectors) of vectors A and B, respectively.
[0145] Step S4: obtain the search query input by the user, expand the query keywords, and then use the pre-trained model to generate a query vector by combining the query content and the expanded content.
[0146] The user inputs the search query, which is the query content that the user needs to search through the system interface. These query contents can be complete sentences or paragraphs, and specific types of content such as titles, abstracts, keywords, units, etc. can be selected to further refine the search scope. This design allows users to flexibly design queries according to specific needs, so as to more accurately locate the required documents.
[0147] Expanding query keywords means that after the system receives the query sentence input by the user, it uses the language model to expand the query content and generate queries with semantically similar words and phrases, thereby generating a wider query range. This processing can ensure the comprehensiveness and relevance of the search results and help users find more potential matching documents.
[0148] In order to improve the accuracy of the query, in an embodiment of the present invention, the Word2Vec algorithm is used to expand the query. Word2Vec is a popular word embedding technology that learns the vector representation of words by training a neural network model. These vectors can capture the semantic and syntactic relationships between words. When we receive a query, the Word2Vec model analyzes the keywords in the query and generates an embedding vector for it, and further generates other words with similar meanings.
[0149] For example, if the query contains "computer", Word2Vec may recommend words such as "computer", "laptop", or "hardware" as expansions. In this way, we are able to express the query intent more fully, thereby improving the accuracy and coverage of the retrieval system.
[0150] Query expansion specifically includes the following steps:
[0151] Step S4.1.1, Word2Vec provides two core model architectures, namely, continuous bag of words (CBOW) and Skip-gram, for generating word embeddings. In the example of the present invention, the CBOW model is selected to implement query expansion.
[0152] The CBOW model first converts the input word into a one-hot representation, making each word a unique vector. Then the vector is multiplied by the weight matrix W between the input layer and the hidden layer to obtain the output of the hidden layer. There is also a weight matrix W' from the hidden layer to the output layer. Therefore, the output of the hidden layer is multiplied by the weight matrix W', and the output is passed through the softmax function to normalize each element in the output vector to a probability between 0 and 1. The word with the highest probability is the predicted word.
[0153] The calculation formula of the softmax function is:
[0154]
[0155] in, yes The exponential function result of K is the total number of categories, and the denominator is the total number of categories. Sum to ensure that the sum of the output probabilities is 1.
[0156] Step S4.1.2, the loss function of the CBOW model usually takes the following form:
[0157]
[0158] in, is the loss function, N is the total number of words in the training sample, is the i-th target word, is the probability of predicting the i-th target word.
[0159] Generate query vectors. Use the BERT model to convert query statements and query keywords after query expansion into query vector representations. Query vectors can better capture the characteristics of query statements and facilitate subsequent retrieval processes. The specific steps include the following:
[0160] Step S4.2.1: Perform a series of preprocessing steps on the query expansion statement, including text cleaning, punctuation processing, word segmentation, stop word removal, stemming and word form restoration. These operations are the same as the preprocessing in the S2 stage, and are intended to prepare for the next step of inputting the BERT model.
[0161] Step S4.2.2: The preprocessed query expansion sentence will be sent to the BERT model to generate a query vector.
[0162] Similar to the way document vectors are processed in step S2, the BERT model is used to encode the preprocessed query sentence. The input representation of the BERT model consists of the sum of word vectors, block vectors, and position vectors, where the word vector maps each word or subword to a vector of fixed dimension, the block vector is used to distinguish sentences, and the position vector indicates the position of each word in the sequence.
[0163] During the processing, [CLS] and [SEP] tags are added before and after the query statement to obtain the original input of the model. This input is then mapped to a text encoding. Next, the text encoding is input into BERT's multi-layer Transformer encoder. The Transformer encoder includes a multi-head attention sublayer and a feedforward network sublayer, and processes the input through multiple encoding layers. Finally, in the output of the last layer, the [CLS] tag at the beginning of the text is used as the representation of the query vector, thus completing the vectorization process of the query statement.
[0164] Step S5, searching for documents. Based on the semantic index constructed in step S3, the query vector generated in step S4 is used to search in the document management library. During the search process, the similarity between the query vector and the document vector is calculated using a cosine similarity function.
[0165] Specifically, after storing the documents and document vectors in the Elasticsearch document vector database and constructing a semantic index in step S3, the query vector generated in step S4 is input into the Elasticsearch system. Elasticsearch uses the HNSW (Hierarchical Navigable Small World) algorithm for similarity retrieval, starting from the top layer, by randomly selecting a starting node and then navigating down layer by layer. In each layer, the cosine similarity between the query expansion vector and all node vectors in the current layer is calculated. This process continues until the bottom layer is reached. At the bottom layer, by calculating the cosine similarity between the query expansion vector and all nodes, several most similar nodes are found to form the final query result. These most similar nodes represent the documents that are semantically closest to the query vector. Finally, Elasticsearch returns these most similar documents and their corresponding similarity scores, completing the entire semantic search process.
[0166] The cosine similarity function determines the relevance of the document to the query by measuring the proximity of two vectors in direction, ensuring that the most relevant documents are presented to the user first. The calculation formula of the cosine similarity function is:
[0167]
[0168] Among them, A is the document vector of the current layer, B is the query vector, A·B is the dot product of the document vector A and the query vector B of the current layer, and ||A|| and ||B|| are the Euclidean norms (i.e., the lengths of the vectors) of vectors A and B respectively.
[0169] Because the cosine similarity function can effectively measure the similarity between two vectors in direction while ignoring their size, the cosine similarity function is used here to measure the similarity between the query expansion vector and the document vector.
[0170] Step S6, sort and output the search results. The system sorts the retrieved document results from high to low according to the similarity score, and specifically sorts them according to relevance and other preset sorting rules. The system then outputs the sorted search results to the user in a list. The user can view and use the retrieved documents through the system interface to quickly obtain the required information. The system also supports multiple sorting methods, including sorting by release date, click-through rate, and user rating.
[0171] The release date sorting allows users to sort the results from new to old or from old to new based on the release date, making it easier for users to view the latest or earliest content. The click rate sorting sorts the results from high to low based on the number of times they are clicked or viewed, helping users find the most popular content. The user rating sorting sorts the results from high to low based on the user's rating, allowing users to see the results that other users think are most valuable.
[0172] In addition to the sorting function, the system also provides other practical interactive functions, such as filtering results, saving search results, exporting data or generating reports, etc., to fully meet the needs of users.
[0173] like Figure 2 As shown, the electronic archive retrieval system based on the large language model includes a document extraction module, a document vector generation module, a semantic indexing module, a query vector generation module, and a document retrieval module;
[0174] The document extraction module is used to obtain electronic archive data to construct a document vector database and perform summary extraction;
[0175] The document vector generation module converts the extracted summary document into a document vector using a pre-trained model. The document vector can better capture the characteristics of the document and facilitate subsequent storage and retrieval processes.
[0176] The semantic indexing module stores the electronic archive and the document vector obtained in step S2 in a document vector database for efficient retrieval and use, and then constructs a semantic index through the document vector to help quickly find and access specific data in the document vector database and quickly obtain required information.
[0177] The query vector generation module generates a query vector based on the retrieval query content and the extended content using a pre-trained model;
[0178] The document retrieval module performs document retrieval through the semantic index based on the similarity between the query vector and the document vector, and outputs the retrieval results according to the similarity ranking.
[0179] In summary, the innovation of combining the large language model with the intelligent electronic archive system lies in using the powerful natural language processing capabilities of the large language model to solve the shortcomings of the existing electronic archive system. The large language model can deeply understand and analyze the content of electronic archives, surpassing the traditional keyword matching method. The semantic retrieval function deeply analyzes the meaning of the query statement to achieve accurate matching and ensure that the search results are more in line with user needs. At the same time, the fuzzy matching function supports the query of synonyms and near-synonyms, which enhances the flexibility of retrieval and improves the user experience. In addition, the context understanding function uses relevant information for query expansion and ambiguity resolution, further improving the accuracy and relevance of the retrieval. The combination of these innovative functions significantly improves the accuracy and intelligence of archive retrieval.
[0180] With the further development and application of large language models, electronic archive retrieval systems will become more intelligent and efficient. The introduction of large language models can not only solve many problems in existing systems, but also provide users with a more convenient and efficient archive retrieval experience. This will greatly improve the work efficiency of various organizations, promote the development of electronic archive retrieval in the direction of intelligence and automation, and provide strong support for archive retrieval in the information age.
[0181] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some or all of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. An electronic archive retrieval method based on a large language model, characterized in that The steps include: Step S1, obtaining electronic archive data and extracting a summary; Step S2: using the pre-trained model, converting the extracted summary document into a document vector; Step S3: construct a semantic index through the document vector; Step S4: Generate a query vector based on the retrieval query content and the extended content using the pre-trained model; Step S5: performing document retrieval through the semantic index based on the similarity between the query vector and the document vector; Step S6: Output the search results according to the similarity sorting.
2. The electronic archive retrieval method based on a large language model according to claim 1, characterized in that: In the step S1, the document data is preprocessed, and / or in the step S4, the query vector is preprocessed, the preprocessing includes text cleaning, punctuation processing, word segmentation, stop word removal, stemming and lemmatization; Text cleaning refers to removing elements in a document that are not part of the text content; Punctuation processing refers to the normalization and cleaning of punctuation in documents; Word segmentation refers to dividing a continuous text string into independent words or phrases according to certain rules; Stop word removal is to delete words that appear frequently in the text but do not contribute much to semantic understanding; Stemming is the process of reducing vocabulary to its base form; Lemmatization is the conversion of words into their dictionary form.
3. The electronic archive retrieval method based on a large language model according to claim 1, characterized in that: In step S1, the document data is subjected to document summary extraction by using the trained large language model; the model is subjected to autoregressive training, and the next word is predicted one by one based on all the previous words, so that it performs well in generating coherent paragraphs and articles. The specific process is as follows: First, the document data is converted into a word vector sequence X, which is converted into a vector representation of fixed dimension through an embedding layer; Next, the input sequence is encoded through multiple layers, each of which contains a self-attention mechanism and a feedforward neural network. The self-attention mechanism allows the model to focus on important words and contextual relationships in the document and generate contextual representations that contain rich semantic information. During the encoding process, the output of each layer serves as the input of the next layer. After the encoding is completed, the decoding part starts to generate the summary. The summary generation process is expressed as: , Among them, P(y i |y 1:i1 ,X) represents the probability of generating the i-th word given the previously generated words and the input document; the decoding takes the final output of the encoding as the initial input, and combines the previously generated summary words to generate the target summary sequence Y={y1,y2,…,y m }, each word y i are all words generated before the given i-1 } and input documents.
4. The electronic archive retrieval method based on a large language model according to claim 1, characterized in that: In step S2, a pre-trained model is used to generate a text vector, and / or in step S4, a pre-trained model is used to generate a query vector, including the following steps: Step S2.1, loading the pre-trained model; Step S2.2, text encoding the text content; adding tags to both ends of the text sequence to obtain the original input, and mapping the original input according to the word vector, block vector and position vector to obtain the text encoding of the pre-trained model; Step S2.3: Input the text encoding into the encoding layer of the pre-trained model, encode it based on the multi-head attention mechanism and feedforward network, and obtain the corresponding document vector.
5. The electronic archive retrieval method based on a large language model according to claim 4 is characterized in that: In step S2.2, the input representation of BERT consists of the sum of the word vector, the block vector, and the position vector; E=E token +E segment +E position, Among them, E token Represents word vector, E segment represents the block vector, E position represents the position vector; The word vector maps each word or subword of the input into a vector representation of a fixed dimension, y1,y2,…,y i represents the input sequence, where y i Represents the i-th word, then the word vector is expressed as: , The block vector is used to distinguish different sentences in the two-sentence pair task. Each word is assigned a segmentation embedding according to the sentence it belongs to, E A represents the segmentation embedding of the first sentence, E B represents the segmentation embedding of the second sentence, then the segmentation embedding is expressed as: AND segment ={And A ,AND A ,…,AND A ,AND B ,AND B ,…,AND B }, The position vector represents the position of each word in the sequence, n represents the length of the input sequence, and the position embedding is expressed as: HAVE BEEN position ={E0,E1,…,E n-1 }, For the input text sequence y1,y2,…,y i , add BERT model specific tags [CLS] and [SEP] at both ends of the sequence to get the original input of the model: Y=[CLS] y1,y2,…,y i [SEP], Map Y by word vector, block vector, and position vector to get the text encoding of the model: E = InputRepresentation(Y), In step S2.3, after multiple layers of encoding, the text encoding E uses the [CLS] tag at the beginning of the text as the text feature representation in the output generated by the last layer, that is, the required document vector, and the formula is as follows: , Among them, T represents the feature representation corresponding to the text encoding E, TransformerLayer i Represents the i-th layer Transformer encoder, T output at the last layer [cls] As a feature representation of text.
6. The electronic archive retrieval method based on a large language model according to claim 4, characterized in that: In step S2.3, the encoding layer of the pre-trained model includes multiple Transformer encoders, wherein the Transformer encoder includes a multi-head attention sublayer and a feedforward network sublayer; The multi-head attention layer passes the input sequence through three different weight matrices to obtain Q, K, and V matrices, and divides these matrices into multiple heads through the multi-head attention mechanism, each with a dimension of d k , calculated in independent subspaces, each head has its own unique weight matrix, mapping Q, K, V to Q i , K i 、V i , the attention weight is calculated using the scaled dot product attention mechanism, that is, the dot product of the query Q and the key K is calculated first, the weight is obtained by the activation function after scaling, and then multiplied by the value V matrix to obtain the output of each head. The outputs of all heads are concatenated into a long vector, and finally mapped back to the original dimension through a linear transformation to obtain the final output; The feedforward network sublayer consists of two linear layers and an activation function, which provides nonlinear transformation for Transformer; For the multi-head attention sub-layer and the feed-forward network sub-layer, their outputs need to pass through an additional residual layer.
7. The electronic archive retrieval method based on a large language model according to claim 6 is characterized in that: The calculation formula of the multi-head attention layer is as follows: , , , , , Among them, W Q , W K and W V represents the weight matrix, , , represents the weight matrix unique to each head, represents the scaling factor, MultiHead represents the multi-head attention mechanism, and W o represents the final weight matrix; The calculation formula of the feedforward network sublayer is as follows: , Among them, x represents the input, W1 and W2 represent the weights of the two linear layers, and b1 and b2 represent the biases of the two linear layers; The residual layer calculation formula is as follows: , Among them, SubLayer represents the multi-head attention sublayer and the feedforward network sublayer, and LayerNorm represents layer normalization.
8. The electronic archive retrieval method based on a large language model according to claim 1, characterized in that: In step S4, query expansion is performed on the acquired search query content, and a query vector is generated based on the search query content and the expanded content. The query expansion includes the following steps: Step S4.1.1, through the continuous bag of words model, the input query word is converted into a vector in the form of one-hot encoding, and the result obtained by multiplying the vector with the weight matrix between the input layer and the hidden layer is used as the output of the hidden layer, the output of the hidden layer is multiplied by the weight matrix from the hidden layer to the output layer, and the normalized probability is used to predict the word; Step S4.1.2: Train the continuous bag-of-words model based on the loss function. The loss function is as follows: , in, represents the loss function, N represents the total number of words in the training sample, represents the i-th target word, Represents the probability of predicting the i-th target word.
9. The electronic archive retrieval method based on a large language model according to claim 1, characterized in that: The similarity calculation in step S3 and / or step S5 is performed by constructing a multi-level vector graph, performing similarity calculation from top to bottom based on the insertion vector, and obtaining a multi-level graph structure of the insertion vector and similar vectors of each layer, using a cosine similarity function, and the formula is as follows: , Among them, A represents the new vector to be inserted, B represents the node vector of the current layer, A·B represents the dot product of the new vector A and the node vector B, and ||A|| and ||B|| represent the Euclidean norm of vectors A and B respectively.
10. A retrieval system for the electronic archive retrieval method based on a large language model according to claim 1, comprising a document extraction module, a document vector generation module, a semantic indexing module, a query vector generation module, and a document retrieval module, characterized in that: The document extraction module is used to obtain electronic archive data and extract summary; The document vector generation module converts the extracted summary document into a document vector using a pre-trained model; The semantic index module constructs a semantic index through document vectors; The query vector generation module generates a query vector based on the retrieval query content and the extended content using a pre-trained model; The document retrieval module performs document retrieval through the semantic index based on the similarity between the query vector and the document vector, and outputs the retrieval results according to the similarity ranking.
Citation Information
Patent Citations
Intelligent law analysis method and system based on language graph model
CN117271748A
Guide method based on large model
CN118069812A
Class case retrieval system and method based on retrieval enhancement generation technology
CN118260391A
Cited By
Unstructured data processing system based on large language model and vector database
CN118939848A
Archive data application method based on large model
CN118964599A
Power system vector knowledge base construction method based on text vectorization
CN118964695A
Archive data retrieval method, system and device
CN119271630A
Method and system for querying synonyms based on database ES
CN119336789A
