Information query method and related equipment

By constructing a text vector library and knowledge graph, we can determine text with high similarity to the input text, which solves the problem of inaccurate data during training and deployment of the big model, and improves the accuracy of information query.

CN119691143APending Publication Date: 2025-03-25MASHANG CONSUMER FINANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411586010.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-07
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

During the training and deployment of large models, it is difficult to obtain the latest data and non-public data in specific vertical fields, resulting in inaccurate data.

Method used

Through the text vector library and knowledge graph built based on input text and preset text, text with high similarity to input text is determined, information query basis is expanded, and query accuracy is improved.

Benefits of technology

By expanding the basis for information query, the accuracy of information query is improved, so that the model can process based on more information during query.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119691143A_ABST
    Figure CN119691143A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of artificial intelligence, and relates to an information query method and device, a medium, electronic equipment and a computer program product. The method comprises the steps that a first text is determined on the basis of an input text and a text vector library constructed on the basis of a first preset text, and the similarity between a text vector of the first text and a text vector of the input text is larger than or equal to a first preset threshold value; based on the input text and a knowledge graph constructed based on a second preset text, determining a second text, the similarity between the triple of the second text and the triple of the input text being greater than or equal to a second preset threshold; and inputting the first text and the second text into a query model to obtain a query result of the input text. According to the information query method and device, the first text and the second text related to the input text are determined based on the input text, the text vector library, the input text and the knowledge graph, and the information amount of information query is expanded during query of the two texts, so that information during information query is increased, and the accuracy of information query is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure belongs to the field of artificial intelligence technology, and in particular, relates to an information query method, an information query device, an electronic device, a computer-readable storage medium, and a computer program product. Background Art

[0002] In the era of big models, more and higher-quality data can be used to train high-quality models.

[0003] However, the data used to train the big model is not necessarily the latest. It is possible that the training data used by the deployed big model is public data before a certain point in the past. In addition, it is difficult for the big model to learn the non-public data in a specific vertical field. Therefore, the data obtained by calling the big model is not accurate. Summary of the invention

[0004] The present disclosure provides an information query method, an information query device, an electronic device, a computer-readable storage medium, and a computer program product.

[0005] According to a first aspect of an embodiment of the present disclosure, there is provided an information query method, the method comprising: Determine a first text based on an input text and a text vector library constructed based on a first preset text, wherein a similarity between a text vector of the first text and a text vector of the input text is greater than or equal to a first preset threshold; Determine a second text based on the input text and a knowledge graph constructed based on a second preset text, wherein a similarity between a triple of the second text and a triple of the input text is greater than or equal to a second preset threshold; The first text and the second text are input into a query model to obtain a query result of the input text.

[0006] According to a second aspect of an embodiment of the present disclosure, there is provided an information query device, including: A first query module is configured to determine a first text based on an input text and a text vector library constructed based on a first preset text, wherein a similarity between a text vector of the first text and a text vector of the input text is greater than or equal to a first preset threshold; A second query module is configured to determine a second text based on the input text and a knowledge graph constructed based on a second preset text, wherein the similarity between a triple of the second text and a triple of the input text is greater than or equal to a second preset threshold; The model calling module is configured to input the first text and the second text into a query model to obtain a query result of the input text.

[0007] According to a third aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored. When the program instructions are executed by a processor, the steps of any one of the information query methods provided in the first aspect of the present disclosure are implemented.

[0008] According to a fourth aspect of an embodiment of the present disclosure, there is provided an electronic device, including: processor; a memory for storing processor-executable instructions; The processor is configured to: execute the executable instructions to implement the steps of any one of the information query methods provided in the first aspect of the present disclosure.

[0009] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, including: A computer program, which, when executed by a processor, implements the steps of any one of the information query methods provided in the first aspect of the present disclosure.

[0010] It can be seen that in the embodiment of the present disclosure, since the text vector library is constructed based on the preset text, a first text whose text vector is close to the text vector similarity of the input text can be determined based on the input text and the vector library, that is, it is determined that the obtained first text is relevant to the input text; in addition, since the knowledge graph is constructed based on the preset text, a second text whose triplet is close to the triplet similarity of the input text can be determined based on the input text and the knowledge graph, that is, it is determined that the obtained second text is relevant to the input text; since the first text and the second text are relevant to the input text, information query is performed through the first text and the second text, compared with information query only for the input text, the amount of information based on the information query is expanded, so that the model can rely on more information when performing information query, thereby improving the accuracy of information query. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0012] Figure 1 The schematic diagram of the processing flow of the information query technology in the related technology is shown schematically; Figure 2 A schematic diagram of a flow chart of an information query method in an exemplary embodiment of the present disclosure is schematically shown; Figure 3 A schematic diagram of a process of constructing a text vector library in an exemplary embodiment of the present disclosure is schematically shown; Figure 4 A schematic diagram schematically shows a flow chart of a method for dividing a third text in an exemplary embodiment of the present disclosure; Figure 5 A schematic diagram schematically shows a flow chart of a method for determining a first text in an exemplary embodiment of the present disclosure; Figure 6 A schematic diagram of a process for constructing a knowledge graph in an exemplary embodiment of the present disclosure is schematically shown; Figure 7 The schematic diagram of the structure of the knowledge graph constructed in the exemplary embodiment of the present disclosure is schematically shown; Figure 8 A flowchart schematically illustrates a method for determining a query result of an input text in an exemplary embodiment of the present disclosure; Fig. 9 A schematic diagram schematically illustrates a flow chart of an information query method in an application scenario in an exemplary embodiment of the present disclosure; Fig.10 A schematic diagram schematically shows the structure of an information query device in an exemplary embodiment of the present disclosure; Fig.11 A schematic diagram schematically shows the structure of another information query device in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION

[0013] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0014] It should be noted that all actions of acquiring signals, information or data in the present disclosure are carried out in compliance with the relevant data protection laws and policies of the country where the device is located and with the authorization given by the owner of the corresponding device.

[0015] A large model (Large Language Model, LLM) is a language model built with a deep neural network containing more than tens of billions of parameters, and is usually trained using a large amount of unlabeled text using self-supervised learning methods.

[0016] Since 2018, Google, OpenAI (an artificial intelligence research company), Meta (an Internet company), Baidu, Huawei and other companies and research institutions have successively released a variety of models including BERT (Bidirectional Encoder Representations from Transformers, a language representation model) and GPT (Generative Pre-Trained, a deep learning model), and they have performed well in almost all natural language processing tasks. In 2019, large models showed explosive growth, especially after the release of ChatGPT (Chat Generative Pre-trained Transformer, a chatbot program) in November 2022, it attracted widespread attention from all over the world.

[0017] Users can interact with the system using natural language to achieve various tasks from understanding to generation, including question answering, classification, summarization, translation, chatting, etc. Large-scale language models demonstrate a strong ability to grasp world knowledge and understand language.

[0018] In order to increase the retrieval capability of the big model, business knowledge in a specific field needs to be added when constructing the prompt so that the big model can give an accurate answer based on the prompt context.

[0019] A commonly used enhanced retrieval generation mode is the RAG (Retrieval Augmented Generation) technology. The RAG technology can enhance the generation capability of large models by adding prompt information to the retrieval knowledge base.

[0020] Among them, prompt can call the big model and send instructions to the big model, such as "tell a joke", "write a snake game in Python (a computer programming language)", "write a love letter to your boyfriend / girlfriend", etc.

[0021] Specifically, Figure 1 A schematic diagram of the processing flow of the retrieval enhancement generation technology in the related art is shown, such as Figure 1 As shown, the text data in the business domain is first vectorized and stored in a vector database, where the vector database is a database used to store and search vectors.

[0022] When the application receives a user's query request, it first vectorizes the query text and searches the vector database. Furthermore, it concatenates the search results and the user's query text into a complete prompt, and then calls the big model for query. The big model gives an accurate answer based on the prompt context.

[0023] For example, user input: How many parameters does the large model Llama 2 have? Searching a database of vectors for similar text: Llama 2 comes in a range of parametersizes—7B, 13B, and 70B—as well as pretrained and fine-tuned variations. The question entered by the user and the retrieved knowledge base text are concatenated into a complete prompt as follows: You are a question-answering robot.

[0024] Your task is to answer the user's question based on the known information given below.

[0025] Make sure your response is based solely on the known information listed below. Do not make up answers.

[0026] If the known information listed below is not sufficient to answer the user's question, please reply directly with "I can't answer your question."

[0027] Known information: Llama 2 comes in a range of parameter sizes—7B, 13B, and 70B—aswell as pretrained and fine-tuned variations. User asked: How many parameters does the large model LLaMa2 have? Please answer user questions in Chinese.

[0028] At this time, the large model responds: Llama2 includes models with 7 billion, 13 billion, and 70 billion parameters.

[0029] In the commonly used RAG scheme, there are two ways to generate text vectors.

[0030] A vector is a feature abstraction of unstructured data, such as emails, IoT sensor data, Instagram photos, protein structures, etc. Mathematically, a vector is an array of floating point or binary numbers. Modern embedding techniques are used to convert unstructured data into embedded vectors.

[0031] Specifically, the first method is to load the document and parse out the complete text.

[0032] Furthermore, paragraphs are cut according to line breaks, and a vector model is called according to each paragraph to generate a vector to be stored in a vector database.

[0033] In the query retrieval stage, paragraphs similar to the question content are retrieved from the vector database.

[0034] The second way is to load the document and parse out the complete text.

[0035] The text is cut according to fixed-length strings. Each time the text is cut, the vector model is called to generate a vector and stored in the vector database.

[0036] However, in the first method, when the text is segmented by paragraphs, if the paragraphs are too large, they contain a lot of irrelevant context information, resulting in inaccurate retrieval; if the paragraphs are too small, the information may be incomplete. In addition, the answer to the question may span two or more paragraphs.

[0037] In the second method, if the text is cut according to fixed-length strings, the cut text is not a complete semantic sentence, and the information expressed by the vector is missing. Some cuts will cut a word into two parts, resulting in loss of semantic information.

[0038] Regardless of whether the text is split by paragraphs or by fixed length, the triple relationships in the text are likely to span paragraphs or strings, resulting in the loss of some triple information.

[0039] In view of the problems existing in the related technologies, the present invention provides an information query method. Figure 2 is a flow chart of an information query method according to an exemplary embodiment. Figure 2 As shown, the method may at least include the following steps: Step S210: Based on the input text and the text vector library constructed based on the first preset text, determine the first text, the similarity between the text vector of the first text and the text vector of the input text is greater than or equal to a first preset threshold.

[0040] Step S220. Based on the input text and the knowledge graph constructed based on the second preset text, determine the second text, and the similarity between the triples of the second text and the triples of the input text is greater than or equal to a second preset threshold.

[0041] Step S230: Input the first text and the second text into the query model to obtain the query results of the input text.

[0042] In an exemplary embodiment of the present disclosure, since the text vector library is constructed based on a preset text, a first text whose text vector is close to the text vector similarity of the input text can be determined based on the input text and the vector library, that is, it is determined that the obtained first text is relevant to the input text; in addition, since the knowledge graph is constructed based on the preset text, a second text whose triplet is close to the triplet similarity of the input text can be determined based on the input text and the knowledge graph, that is, it is determined that the obtained second text is relevant to the input text; since the first text and the second text are relevant to the input text, information query is performed through the first text and the second text, which expands the amount of information based on the information query compared to information query only for the input text, so that the model can rely on more information when performing information query, thereby improving the accuracy of information query.

[0043] The following is a detailed description of each step of the information query method.

[0044] In step S210, a first text is determined based on the input text and a text vector library constructed based on a first preset text, and the similarity between the text vector of the first text and the text vector of the input text is greater than or equal to a first preset threshold.

[0045] In the exemplary embodiment of the present disclosure, the input text may be a question text input by the user, or other text representing the query content, which is not specifically limited in the exemplary embodiment. For example, the input text may be "how many parameters does the large model LLaMa2 have", or other question text may be input according to the actual situation.

[0046] The first text may be a similarity text retrieved from a text vector library according to a question text input by a user, and the similarity between a text vector of the similarity text and a text vector of the input text is greater than or equal to a first preset threshold.

[0047] The text vector library can be a vector library constructed from documents of a business knowledge base in a specific field, such as science, medicine, law, history, and literature, or a vector library constructed from other first preset texts selected according to actual conditions and needs, such as a vector library constructed based on a technical knowledge base, which covers professional knowledge of engineering technology and information technology, and provides technical specifications, operating guidelines, and the latest technical developments. This exemplary embodiment does not make any special limitations on this.

[0048] In an alternative embodiment, Figure 3 A flow chart of the method for constructing a text vector library is shown, as Figure 3As shown, the method may at least include the following steps: In step S310, the first preset text is parsed to obtain a third text.

[0049] Since the data in the first preset text such as the knowledge base document is unstructured, for example, the first preset text is a text in PDF (Portable Document Format), the open source component can be used to parse the first preset text to obtain a structured third text, for example, the third text can be a binary string obtained by parsing the text in the PDF. The first preset text may include multiple texts.

[0050] In step S320, the third text is divided to obtain a plurality of fourth texts.

[0051] In an alternative embodiment, Figure 4 A flow chart of a method for dividing the third text is shown, as shown in Figure 4 As shown, the method may at least include the following steps: In step S410, the third text is divided to obtain a plurality of fifth texts.

[0052] When generating a text vector library, the third text may be divided according to commas or periods in Chinese or English to obtain a plurality of fifth texts.

[0053] For example, the plurality of fifth texts may be: statement 1 statement 2 statement 3 statement 4 statement 5 statement 6..... statement n.

[0054] In step S420, a plurality of fourth texts are generated based on a plurality of fifth texts, the fourth text includes a plurality of fifth texts, and the fifth texts belonging to the same fourth text are adjacent in position in the third text.

[0055] In order to divide the third text, a preset number of sentences during the division may be obtained, and the preset number of sentences may be the number of sentences in a preset sliding window.

[0056] After the preset number of sentences is obtained, a plurality of fifth texts may be obtained by sliding and cutting according to the preset number of sentences.

[0057] Considering that when the text vector of each fourth text is determined later, when the fourth text is a sentence, the generated text vector focuses on the specific meaning of the sentence, and when compared with the text vectors of other sentences, such as the text vector of the input text, the comparison will naturally be made at the sentence level, which means that the comparison of text vectors may miss broader contextual information in a paragraph or document.

[0058] When the fourth text is a complete paragraph or document, the process of generating text vectors takes into account both the entire context and the relationship between sentences and phrases in the text, which can produce a more comprehensive vector representation that captures the broader meaning and theme of the text. However, on the other hand, longer fourth texts may introduce noise or dilute the importance of individual sentences or phrases, making it more difficult to find exact matches when querying.

[0059] Not only that, the length of the fourth text also affects the relationship between text vectors. Specifically, shorter fourth texts, such as single sentences or phrases, are more focused on details and are more suitable for matching with sentence-level text vectors. Longer fourth texts spanning multiple sentences or paragraphs are more suitable for paragraph- or document-level text vectors because they can help find a broader context or topic.

[0060] Based on this, the number of sentences in the preset sliding window can cover several types, namely, sentence blocks consisting of shorter sentences, semantic blocks consisting of a moderate number of sentences, and semantic blocks consisting of a longer number of sentences.

[0061] Among them, the sentence blocks consisting of shorter sentences are used to capture more fine-grained semantic information, which can be within 256 words or Chinese characters; A semantic block consisting of a moderate number of sentences is used to retain a relatively moderate context, which can be within 512 or 1024 words or Chinese characters; Semantic blocks consisting of longer sentences are used to retain more context and can be larger than 1024 words or Chinese characters.

[0062] Specifically, the number of statements in the small sliding window, the number of statements in the medium sliding window, and the number of statements in the large sliding window can be calculated by counting the first preset text such as the knowledge base document, or can be determined by other methods. This exemplary embodiment does not make any special limitations on this.

[0063] When the preset number of sentences is 3, the plurality of fifth texts are subjected to sliding cutting processing to generate a plurality of fourth texts. For example, the fourth text may be: Statement 1 Statement 2 Statement 3 Statement 4 Statement 2Statement 3Statement 4Statement 5 Statement 3Statement 4Statement 5Statement 6 In step S330 , a text vector of each fourth text is determined, and the text vector of the fourth text is associated with the fourth text and stored in a text vector library.

[0064] In order to determine the text vector of each fourth text, each fourth text may be vectorized using a vector model.

[0065] Among them, the vector model is a model used to generate text into vectors. For example, the commercial GPT provides an API (Application Programming Interface) for generating text vectors, the open source word2vec (word to vector, a language model), Glove (an unsupervised word representation tool), BERT, Sentence Transformer (a Python framework for sentence, text and image embedding), etc.

[0066] When the vector model is called to generate a text vector corresponding to the fourth text, it can be: Statement 1 Statement 2 Statement 3 Statement 4 [1.23,1.24,2.54.....2.32] Statement 2 Statement 3 Statement 4 Statement 5 [0.43,0.32,3.24.....8.52] Statement 3 Statement 4 Statement 5 Statement 6 [2.23,4.33,1.56.....1.17] Furthermore, the fourth text and the corresponding text vector may be stored in a text vector library to complete the construction of the text vector library.

[0067] Specifically, Table 1 shows the table structure of the text vector library storing the fourth text and the corresponding text vector:

[0068] Table 1 Therefore, the manner of storing the fourth text and the corresponding text vector in the text vector library is as shown in Table 2: doc_id start_index statement_count text vector 1 1 4 Statement 1 Statement 2 Statement 3 Statement 4 [1.23,1.24,2.54.....2.32] 1 2 4 Statement 2Statement 3Statement 4Statement 5 [0.43,0.32,3.24.....8.52] 1 3 4 Statement 3Statement 4Statement 5Statement 6 [2.23,4.33,1.56.....1.17] 2 1 4 Statement 1 Statement 2 Statement 3 Statement 4 [4.31,2.11,2.04.....0.21] ... ... ... ... ... 1 1 10 Statement 1 Statement 2 Statement 3 ... Statement 10 [1.23,1.24,2.54.....2.32] 1 2 10 Statement 2Statement 3Statement 4...Statement 11 [0.43,0.32,3.24.....8.52] 1 3 10 Statement 3 Statement 4 Statement 5 ... Statement 12 [2.23,4.33,1.56.....1.17] 2 1 10 Statement 1Statement 2Statement 3...Statement 10 [4.31,2.11,2.04.....0.21] ... ... ... ... ... 1 1 20 Statement 1 Statement 2 Statement 3 ... Statement 20 [1.23,1.24,2.54.....2.32] 1 2 20 Statement 2 Statement 3 Statement 4 ... Statement 21 [0.43,0.32,3.24.....8.52] 1 3 20 Statement 3 Statement 4 Statement 5 ... Statement 22 [2.23,4.33,1.56.....1.17] 2 1 20 Statement 1 Statement 2 Statement 3 ... Statement 20 [4.31,2.11,2.04.....0.21] ... ... ... ... ... Table 2 In this exemplary embodiment, the fourth text is generated by dividing and cutting the third text, and the vector model is called to generate the corresponding text vector. This solves the problems of inaccurate retrieval or incomplete information caused by cutting the text according to paragraphs, and also solves the problem of semantic information loss caused by cutting the text according to fixed-length strings. At the same time, it achieves the effect of increasing the text information stored in the vector database.

[0069] After the text vector library is established, the first text may be determined according to the input text and the vector database.

[0070] In an alternative embodiment, Figure 5 A flow chart of a method for determining a first text is shown, Figure 5As shown, the method may at least include the following steps: in step S510, based on the input text and the text vector library, multiple sixth texts are determined; the similarity between the text vector of the sixth text and the text vector of the input text is greater than or equal to a first preset threshold; the contents of different sixth texts are different, and the text positions of different sixth texts belonging to the same first preset text are different.

[0071] First, the vector model can be called to vectorize the input text to obtain the corresponding text vector.

[0072] Then, the Euclidean distance or cosine distance between the text vector of the input text and the text vectors in the text vector library may be calculated to retrieve a plurality of sixth texts in the text vector library whose similarity with the text vector of the input text is greater than or equal to a first preset threshold.

[0073] It is worth noting that when searching the text vector library, the most appropriate answer is not necessarily at the top of the search. Therefore, you can set top N when searching to return more of the sixth text.

[0074] For example, assuming that top N=3, the search returns multiple sixth texts as shown in Table 3:

[0075] Table 3 It can be seen from Table 3 that the contents of different sixth texts are different, and the text positions of different sixth texts belonging to the same first preset text are different.

[0076] In step S520, a first text is determined from a plurality of sixth texts.

[0077] For multiple sixth texts, corresponding document identifiers doc_id may be obtained from the text vector library, and the document identifiers doc_id of the multiple sixth texts may be compared to determine whether there is an identical document identifier doc_id.

[0078] For example, in the sixth text shown in Table 3, it can be found that the document identifier doc_id of the last two pieces of data is both 1, indicating that the two sixth texts belong to the same document.

[0079] Furthermore, for the sixth text belonging to the same document, the corresponding start_index may be obtained to determine the starting sentence position of the sixth text.

[0080] For example, in the last two sixth texts shown in Table 3, the corresponding starting sentence positions can be obtained as 1 and 3 respectively.

[0081] Furthermore, the starting sentence position of the sixth text belonging to the same document is calculated.

[0082] For example, in the last two sixth texts shown in Table 3, since the corresponding starting sentence positions are 1 and 3 respectively, the starting sentence position can be calculated as 3-1=2, so that the number of overlapping sentences in the last two sixth texts is 2.

[0083] Thus, the number of overlapping sentences is compared with the number of corresponding sentences to determine whether the sixth texts belonging to the same document are adjacent.

[0084] When the length of the sixth text corresponds to 4 sentences, and the number of overlapping sentences and the number of corresponding sentences is 2<4, it indicates that 2 sentences overlap within the prescribed number of sentences. Therefore, it can be determined that the two sixth texts are adjacent.

[0085] The number of overlapping sentences can be used as the number of sentences that need to be removed. For example, the adjacent sixth texts "sentence 1 sentence 2 sentence 3 sentence 4" and "sentence 3 sentence 4 sentence 5 sentence 6" in Table 3 are deduplicated. After removing the adjacent sentences with 2 overlapping sentences in one of the sixth texts, the deduplicated sixth text can be "sentence 1 sentence 2" and "sentence 3 sentence 4 sentence 5 sentence 6", or "sentence 1 sentence 2 sentence 3 sentence 4" and "sentence 5 sentence 6".

[0086] Furthermore, the sixth text after deduplication is spliced.

[0087] For example, when the sixth text after deduplication is "sentence 1 sentence 2" and "sentence 3 sentence 4 sentence 5 sentence 6", or "sentence 1 sentence 2 sentence 3 sentence 4" and "sentence 5 sentence 6", the sixth text after continuing the splicing processing is "sentence 1 sentence 2 sentence 3 sentence 4 sentence 5 sentence 6".

[0088] Therefore, the sixth text obtained in Table 3 is deduplicated and concatenated to obtain the final sixth text: Document 2: Statement 1 Statement 2 Statement 3 Statement 4 Document 1: Statement 1 Statement 2 Statement 3 Statement 4 Statement 5 Statement 6 Since the vector representation of the sixth text obtained after deduplication and splicing has changed, the vector model may be called again to determine the text vector of each sixth text after deduplication and splicing.

[0089] After the text vector of each sixth text is updated, the Euclidean distance or the cosine distance between the text vector of the input text and the text vector of the sixth text may be recalculated to obtain an updated similarity result.

[0090] Alternatively, the text vectors of each updated sixth text are sorted using a rearranger to determine the updated similarity result. The implementation principle of the rearranger is to use a semantic sorting model modeled by deep learning, and here the sorting can be performed by combining similarity calculation and the rearranger.

[0091] Among them, the rearranger can adopt the open source bge-rerank-base (a reranking model), bge-rerank-large (a reranking model), or the commercial closed source CohereRank (a commercial ranking model), etc.

[0092] Specifically, after the sixth text retrieved from the text vector library is de-duplicated and spliced, a de-duplicated and spliced ​​sixth text can be obtained, and a re-ranker is used to calculate a correlation ranking value r1 between the de-duplicated and spliced ​​sixth text and the input text; Then, the cosine similarity between the text vector of the input text and the text vector of the sixth text after deduplication and splicing is recalculated according to formula (1): sim(A,B) = cos( , ) = = (1) in, and They respectively represent the text vectors of the input text and the sixth text after deduplication and splicing in the n-dimensional vector space, and are sorted according to the values ​​of sim(A, B) to obtain the similarity ranking r2.

[0093] Then, the final sorting formula is shown in formula (2): r = + (2) Among them, k1 and k2 are the weights of the rearranger and cosine similarity, respectively, and + =1, r is the similarity result.

[0094] Therefore, the results are sorted according to the similarity, and the sixth text corresponding to the result with the highest similarity in the sorted results is taken as the first text.

[0095] Among them, the Sentence Transformer vector model can be called to reorder the results after deduplication and splicing: #Search results after deduplication and splicing: search_results #Query text entered by the user: user_query from sentence_transformers import CrossEncoder model = CrossEncoder('cross-encoder / ms-marco-MiniLM-L-6-v2', max_length=4096) scores = model.predict([(user_query, doc) for doc in search_results]) # Sort by score sorted_list = sorted(zip(scores, search_results), key=lambda x: x[0],reverse=True) for score, doc in sorted_list: print(f"{score}\t{doc}\n") In step S220, based on the input text and the knowledge graph constructed based on the second preset text, the second text is determined, and the similarity between the triples of the second text and the triples of the input text is greater than or equal to a second preset threshold.

[0096] In the exemplary embodiments of the present disclosure, a knowledge graph is a technical method that uses a graph model to describe knowledge and model the relationship between all things in the world. The knowledge graph consists of nodes and edges. Among them, a node can be an entity, such as a person, a book, etc., or an abstract concept, such as artificial intelligence, a knowledge graph, etc. An edge can be an attribute of an entity, such as a name, a book title, or a relationship between entities, such as a friend or a spouse.

[0097] The input text may be a question text input by the user, or other text representing the query content, which is not specifically limited in this exemplary embodiment. For example, the input text may be "how many parameters does the large model LLaMa2 have", or other question text may be input according to actual conditions.

[0098] The second text may be a similarity text retrieved from the knowledge graph based on the question text input by the user, and the similarity between the triples of the similarity text and the triples of the input text is greater than or equal to a second preset threshold.

[0099] In an alternative embodiment, Figure 6 A flow chart of the method for constructing a knowledge graph is shown, as Figure 6As shown, the method may at least include the following steps: In step S610, the second preset text is parsed to obtain a seventh text.

[0100] The second preset text may also be text in a knowledge base document, or other text selected according to actual conditions and requirements, and this exemplary embodiment does not specifically limit this.

[0101] Since the data in the second preset text such as the knowledge base document is unstructured, for example, the first preset text is a text in PDF format, the second preset text can be parsed using an open source component to obtain a structured seventh text, for example, the third text can be a binary string obtained by parsing the text in PDF. The second preset text includes multiple, and the second preset text and the first preset text can be the same or different, and this exemplary embodiment does not specifically limit this.

[0102] In step S620, the seventh text is divided to obtain a plurality of eighth texts.

[0103] When the text structure of the seventh text is composed of paragraphs, the seventh text may be divided into paragraphs to obtain a plurality of eighth texts.

[0104] Alternatively, when the text structure of the seventh text is to organize the directory according to chapters, the seventh text can be divided into chapters according to the chapters to obtain multiple eighth texts.

[0105] In step S630, feature extraction is performed on each of the plurality of eighth texts to obtain a triplet of each eighth text.

[0106] Specifically, a large model may be used to perform feature extraction processing on multiple eighth texts to obtain corresponding triples.

[0107] The richer the eighth text, the more complete the triples extracted will be, but make sure that the number of words called at one time does not exceed the word limit of the word prompt of the large model.

[0108] Specifically, the prompt for calling the large model is as follows: Your task is to identify and extract the knowledge graph triple information in the text and output it in JSON (JavaScript Object Notation, JS object notation) format. The field specifications are as follows: 1. The subject field represents the subject of the knowledge graph triple 2. The predicate field represents the knowledge graph triple predicate 3. The object field represents the object of the knowledge graph triple For example, { "subject":"Llama", "predicate":"developer", "object":"Meta" },{ "subject":"Llama", "predicate":"parameter", "object":"7B, 13B, and 70B" } ] In step S640, each triple of the eighth text and the corresponding eighth text are stored in the knowledge graph.

[0109] Furthermore, based on the JSON data returned by each call to the large model, each eighth text and the corresponding triplet can be stored in the knowledge graph.

[0110] In this exemplary embodiment, the text is segmented according to chapters or paragraphs to generate knowledge graph triples, and the complete entity relationships are preserved, thereby achieving the effect of storing complete triple relationships.

[0111] Figure 7 The schematic diagram of the structure of the constructed knowledge graph is shown in FIG. Figure 7 As shown, by calling the large model, the triples contained in the eighth text can be extracted and stored in the knowledge graph, and any information not directly mentioned in the text is not guessed, and no information with a null value is output.

[0112] After the knowledge graph is constructed, the second text can be determined based on the first text and the knowledge graph. It is worth noting that the first text can be used as a basis for searching the knowledge graph to determine the second text.

[0113] Specifically, the first text is used as input and the knowledge graph is searched using Llama Index. Specifically, a vector-based search method can be used to search for entities in the knowledge graph through vector similarity to obtain relevant information to obtain the second text.

[0114] Among them, Llama Index is an orchestration framework for simplifying the integration of private data with public data to build applications that use large language models. It provides data ingestion, indexing, and query tools, making it a versatile solution for generative artificial intelligence needs.

[0115] As an AI-based indexing tool, it uses natural language processing (NLP) technology to help users find information quickly. The core concept of Llama Index is to convert unstructured data (such as text, documents, web pages, etc.) into a queryable structured index, so that users can retrieve relevant information through simple natural language queries.

[0116] Llama Index usually uses a pre-trained language model to understand and parse data and create an index, which can be seen as a semantic map of the data. When a user asks a query, Llama Index can understand the intent of the query and quickly locate relevant information through the index.

[0117] This method can retrieve complex questions involving the relationships between multiple entities, ensuring the accuracy and effectiveness of the retrieval of the second text.

[0118] In step S230, the first text and the second text are input into the query model to obtain the query results of the input text.

[0119] In an exemplary embodiment of the present disclosure, after the first text and the second text are determined, the first text and the second text may be input into a query model to determine a corresponding query result.

[0120] In an alternative embodiment, Figure 8 A flow chart of a method for determining a query result of an input text is shown, Figure 8 As shown, the method may at least include the following steps: In step S810, the first text, the second text and the input text are concatenated to obtain a target text.

[0121] After obtaining the first text and the second text, ${vector_info} can be used to represent the first text retrieved by the text vector library, and ${kg_info} can be used to represent the second text retrieved by the knowledge graph.

[0122] Specifically, the first text and the second text are concatenated to obtain: Known information: ${vector_info} ${kg_info} Furthermore, ${user_question} may be used to represent the input text of the user query, so that the concatenated text of the first text and the second text is concatenated with the input text to obtain the target text.

[0123] For example, the target text could be: Known information: ${vector_info} ${kg_info} User asked: ${user_question} In step S820, the target text is input into the query model for processing to obtain a query result of the input text.

[0124] Among them, the query model can be a large model.

[0125] After obtaining the target text, you can use the target text as a prompt to call the large model to obtain the query results.

[0126] For example, the calling method can be: You are a question-answering robot.

[0127] Your task is to answer the user's question based on the known information given below.

[0128] Make sure your response is based solely on the known information listed below. Do not make up answers.

[0129] If the known information listed below is not sufficient to answer the user's question, please reply directly "I can't answer your question."

[0130] Known information: ${vector_info} ${kg_info} User asked: ${user_question} Please answer user questions in Chinese.

[0131] The information query method in the embodiment of the present disclosure is described in detail below in conjunction with an application scenario.

[0132] Fig. 9 A flow chart of the information query method in an application scenario is shown, such as Fig. 9 As shown, in step S910, the text is parsed and segmented.

[0133] Since the data in the knowledge base documents is unstructured, open source components can be used to parse the knowledge base documents to obtain structured text.

[0134] Furthermore, the structured text is segmented according to commas or periods in Chinese or English to obtain segmented text, for example: sentence 1 sentence 2 sentence 3 sentence 4 sentence 5 sentence 6 ... sentence n.

[0135] In step S920, the text is captured by sliding to generate a vector.

[0136] Slide and cut the divided text according to the preset number of sliding window sentences.

[0137] Assuming the number of sliding window statements is size = 4, the cut text is as follows: Statement 1 Statement 2 Statement 3 Statement 4 Statement 2Statement 3Statement 4Statement 5 Statement 3Statement 4Statement 5Statement 6 The segmented text is vectorized using a vector model to obtain a text vector.

[0138] When calling the vector model to generate a text vector, it can be: Statement 1 Statement 2 Statement 3 Statement 4 [1.23,1.24,2.54.....2.32] Statement 2 Statement 3 Statement 4 Statement 5 [0.43,0.32,3.24.....8.52] Statement 3 Statement 4 Statement 5 Statement 6 [2.23,4.33,1.56.....1.17] Furthermore, a text vector library is used to store text vectors. The table structure design in the text vector library is shown in Table 1, and the stored data is shown in Table 2, which will not be repeated here.

[0139] In step S930, the text is parsed and divided into paragraphs or chapters.

[0140] Since the data in the knowledge base documents is unstructured, open source components can be used to parse the knowledge base documents to obtain structured text.

[0141] When the text structure in the knowledge base document is composed of paragraphs, the text can be divided into paragraphs.

[0142] Or when the text structure in the knowledge base document is organized by chapters, the text can be divided into chapters.

[0143] In step S940, the large model is called to parse the triples and store them in the knowledge graph.

[0144] The text obtained from each segmentation can be used to call the big model to extract the triples required by the knowledge graph. The richer the text, the more complete the triples extracted will be, but it is necessary to ensure that the number of texts called at one time does not exceed the word limit of the word prompt of the big model.

[0145] Furthermore, based on the JSON data returned by each call to the large model, the triples can be stored in the knowledge graph.

[0146] In step S950, the vector library is searched and the concatenated statements are reordered.

[0147] Based on the question entered by the user, similar texts can be retrieved from the text vector library.

[0148] When searching a text vector library, the most appropriate answer may not be at the top of the search. Therefore, you can set top N when searching to return more text.

[0149] For example, assuming top N=3, the fifth text returned by the search is shown in Table 3.

[0150] From Table 3, we can see that the document identifier doc_id of the last two pieces of data is 1, indicating that the two pieces of text belong to the same document.

[0151] Furthermore, the starting sentence positions of the last two texts are 1 and 3 respectively. Therefore, the starting sentence position can be calculated as 3-1=2. Moreover, since 2<4, it indicates that there are two overlapping sentences within the specified number of sentences. Therefore, it can be determined that the two texts are adjacent sentence texts in the source document and can be deduplicated and spliced ​​into one text. The final text is: Document 2: Statement 1 Statement 2 Statement 3 Statement 4 Document 1: Statement 1 Statement 2 Statement 3 Statement 4 Statement 5 Statement 6 Since the vector representation of the text obtained after the deduplication and splicing process has changed, the vector model can be called again to determine each text after the deduplication and splicing process and recalculate the similarity ranking.

[0152] After the results are re-ranked, the result with the highest similarity can be selected as the retrieval result.

[0153] In step S960, the search results are used as input to search the knowledge graph.

[0154] Take the text with the highest similarity as input and use Llama Index to search the knowledge graph. Specifically, a vector-based search method can be used to find entities in the knowledge graph through vector similarity to obtain relevant information and obtain corresponding search results. This method can search for complex problems involving the relationship between multiple entities, ensuring the accuracy and effectiveness of the search.

[0155] In step S970, the two search result assembly prompts call LLM.

[0156] Specifically, ${vector_info} can be used to represent the text retrieved from the vector database, ${kg_info} to represent the text retrieved from the knowledge graph, and ${user_question} to represent the query text entered by the user. The corresponding texts are concatenated to obtain a complete prompt to call the large model to obtain the answer.

[0157] To summarize, in this application scenario, the document is first parsed to obtain the complete text.

[0158] The sentences are divided according to commas and periods, and the sliding window is set according to the preset number of sentences. The sliding window is aligned from the beginning of the text and gradually moved backwards. The text inside each sliding window is called by the vector model to generate vector data for storage in the text vector library.

[0159] Each paragraph of text is divided into paragraphs or chapters, and a large language model is called to generate the knowledge graph triples <subject, predicate, object> contained in the text. The triples are stored in the graph database, so that even entity relationships that exist across fragments and sentences can be fully preserved.

[0160] When searching the vector library, the most appropriate answer is not necessarily at the top of the search. Therefore, when searching, set topN to return more text and re-score and sort the query (query text) and document (file) through a ranking model.

[0161] The vector database search results are used as input to continue searching the knowledge graph. Vector-based search methods are used to find entities by vector similarity to obtain relevant information. This method can retrieve complex questions involving the relationship between multiple entities. The two search results are assembled and spliced ​​to enrich the context information in the prompt, and the large model is called.

[0162] In an exemplary embodiment of the present disclosure, since the text vector library is constructed based on a preset text, a first text whose text vector is close to the text vector similarity of the input text can be determined based on the input text and the vector library, that is, it is determined that the obtained first text is relevant to the input text; in addition, since the knowledge graph is constructed based on the preset text, a second text whose triplet is close to the triplet similarity of the input text can be determined based on the input text and the knowledge graph, that is, it is determined that the obtained second text is relevant to the input text; since the first text and the second text are relevant to the input text, information query is performed through the first text and the second text, which expands the amount of information based on the information query compared to information query only for the input text, so that the model can rely on more information when performing information query, thereby improving the accuracy of information query.

[0163] In addition, in an exemplary embodiment of the present disclosure, an information query device is also provided. Fig.10 The schematic diagram of the structure of the information query device is shown in FIG. Fig.10 As shown, the information query device 1000 may include: a first query module 1010, a second query module 1020 and a model calling module 1030. Among them: A first query module 1010 is configured to determine a first text based on an input text and a text vector library constructed based on a first preset text, wherein the similarity between the text vector of the first text and the text vector of the input text is greater than or equal to a first preset threshold; A second query module 1020 is configured to determine a second text based on the input text and a knowledge graph constructed based on a second preset text, wherein the similarity between a triple of the second text and a triple of the input text is greater than or equal to a second preset threshold; The model calling module 1030 is configured to input the first text and the second text into a query model to obtain a query result of the input text.

[0164] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0165] The present disclosure also provides a computer-readable storage medium having computer program instructions stored thereon, which implement the steps of the information query method provided by the present disclosure when the program instructions are executed by a processor.

[0166] In another exemplary embodiment, a computer program product is further provided. The computer program product includes a computer program that can be executed by a programmable device. The computer program has a code portion for executing the above information query method when executed by the programmable device.

[0167] Fig.11 1 is a block diagram of another information query device 1100 according to an exemplary embodiment. For example, the device 1100 may be provided as a server. Fig.11 The apparatus 1100 includes a processing component 1122, which further includes one or more processors, and a memory resource represented by a memory 1132 for storing instructions executable by the processing component 1122, such as an application. The application stored in the memory 1132 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1122 is configured to execute instructions to perform the above-mentioned information query method.

[0168] The device 1100 may also include a power supply component 1126 configured to perform power management of the device 1100, a wired or wireless network interface 1150 configured to connect the device 1100 to a network, and an input / output interface 1158. The device 1100 may operate based on an operating system stored in the memory 1132.

[0169] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the present disclosure. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

[0170] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. An information query method, characterized in that: include: Determine a first text based on an input text and a text vector library constructed based on a first preset text, wherein a similarity between a text vector of the first text and a text vector of the input text is greater than or equal to a first preset threshold; Determine a second text based on the input text and a knowledge graph constructed based on a second preset text, wherein a similarity between a triple of the second text and a triple of the input text is greater than or equal to a second preset threshold; The first text and the second text are input into a query model to obtain a query result of the input text.

2. The method according to claim 1, characterized in that The method further comprises: Parsing the first preset text to obtain a third text; Dividing the third text to obtain a plurality of fourth texts; A text vector of each of the fourth texts is determined, and the text vector of the fourth text is associated with the fourth text and stored in the text vector library.

3. The method according to claim 2, characterized in that The step of dividing the third text to obtain a plurality of fourth texts includes: Dividing the third text to obtain a plurality of fifth texts; The plurality of fourth texts are generated based on the plurality of fifth texts, the fourth text includes a plurality of fifth texts, and the positions of the fifth texts belonging to the same fourth text in the third text are adjacent.

4. The method according to claim 1, characterized in that The step of determining the first text based on the input text and the text vector library constructed based on the first preset text includes: Based on the input text and the text vector library, a plurality of sixth texts are determined; the similarity between the text vectors of the sixth texts and the text vector of the input text is greater than or equal to a first preset threshold; different sixth texts have different contents, and different sixth texts belonging to the same first preset text have different text positions; The first text is determined from the plurality of sixth texts.

5. The method according to claim 1, characterized in that The method further comprises: Parsing the second preset text to obtain a seventh text; Dividing the seventh text to obtain a plurality of eighth texts; Performing feature extraction on the plurality of the eighth texts respectively to obtain a triplet of each of the eighth texts; Each triple of the eighth text and the corresponding eighth text are stored in the knowledge graph.

6. The information query method according to claim 1, characterized in that: The step of inputting the first text and the second text into a query model to obtain a query result of the input text includes: Concatenating the first text, the second text and the input text to obtain a target text; The target text is input into the query model for processing to obtain a query result for the input text.

7. An information query device, characterized in that: include: A first query module is configured to determine a first text based on an input text and a text vector library constructed based on a first preset text, wherein a similarity between a text vector of the first text and a text vector of the input text is greater than or equal to a first preset threshold; A second query module is configured to determine a second text based on the input text and a knowledge graph constructed based on a second preset text, wherein the similarity between a triple of the second text and a triple of the input text is greater than or equal to a second preset threshold; The model calling module is configured to input the first text and the second text into a query model to obtain a query result of the input text.

8. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, the steps of the method described in any one of claims 1 to 6 are implemented.

9. An electronic device, characterized in that: include: a memory having a computer program stored thereon; A processor, configured to execute the computer program in the memory to implement the steps of the method according to any one of claims 1 to 6.

10. A computer program product, characterized in that The method comprises a computer program, wherein when the computer program is executed by a processor, the method implements the method according to any one of claims 1 to 6.