Methods and devices for improved retrieval augmented generation
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
- Filing Date
- 2024-11-13
- Publication Date
- 2026-05-21
Smart Images

Figure CN2024131792_21052026_PF_FP_ABST
Abstract
Description
METHODS AND DEVICES FOR IMPROVED RETRIEVAL AUGMENTED GENERATIONFIELD
[0001] The present application relates to retrieval augmented generation, such as using a pre-trained large language model (LLM) and a domain-specific knowledge base to augment the pre-trained LLM.BACKGROUND
[0002] A retrieval augmented generation (RAG) system relies on an information retrieval system to augment a query input to a pre-trained LLM so as to help the LLM generate a response more relevant to a particular domain. For a domain-specific knowledge base, a domain-specific information retrieval system may be used to create an effective RAG system. In many cases, a domain-specific information retrieval system is realized through fine-tuning the embedding model. That is, the pre-trained embedding model used for embedding a domain-specific knowledge base may be refined or tailored to better correspond to the characteristics or context of the knowledge base. In some cases, this requires a labelled training dataset and the ability to access and fine-tune the transformer model, which is not always possible.
[0003] It would be advantageous to provide for an improved information retrieval system that does not necessarily rely on customizing the transformer-based embedding model to the domain-specific knowledge base and / or on a labelled training dataset. Such an improved information retrieval system may be useful in realizing an improved RAG system.
[0004] BRIEF SUMMARY
[0005] In accordance with one aspect, the present application describes an improved retrieval augmented generation. The method may include generating a vector space from a domain-specific knowledge base containing a plurality of records through embedding, with an encoder transformer-based model, a plurality of chunks of the domain-specific knowledge base as knowledge base vectors; embedding a plurality of queries using the encoder transformer-based model to obtain a plurality of query vectors; using a multi-agent reinforcement learning algorithm and a respective agent for each of the query vectors to modify a position of at least some of the knowledge base vectors relative to the query vectors within the vector space until an equilibrium condition is met and thereby producing a modified vector space; receiving a search query and embedding the search query to obtain a search query vector; retrieving a subset of the knowledge base vectors based on a semantic search within the modified vector space using the search query vector; and obtaining a query response from a large language model by inputting the subset of the knowledge base vectors and the search query vector.
[0006] In some implementations, using includes, for each respective agent and its associated query vector, identifying a respective subset of the knowledge base vectors in closest proximity to that query vector, applying a respective action to the position of each of the knowledge base vectors in the subset, and jointly evaluating reward functions for the agents.
[0007] In some implementations, the action is either a displacement away from or a displacement towards one of the query vectors. The reward function for one of the agents having an associated query vector may increase based on closer proximity of a relevant knowledge vector to the associated query vector and may decrease based on closer proximity of a non-relevant knowledge vector to the associated query vector. The increase or decrease based on proximity is based on relevance of the knowledge base vector to the associated query vector and a measure of distance between the associated query vector and the knowledge vector.
[0008] In some implementations, modifying the position includes, for one of the query vectors, adjusting the position of a nearby knowledge base vector to be further from said one of the query vectors or adjusting the position of the nearby knowledge base vector to be closer to said one of the query vectors.
[0009] In some implementations, the equilibrium condition is a Nash equilibrium condition.
[0010] In some implementations, the encoder transformer-based model is a pre-trained embedding model and wherein the method does not alter the pre-trained embedding model.
[0011] In some implementations, in the modified vector space, the proximity of one of the knowledge base vectors to one of the query vectors is indicative of the semantic relevance of said one of the knowledge base vectors to said one of the query vectors.
[0012] In another aspect, the present application describes a system for retrieval augmented generation. The system may include one or more computing devices having one or more processors and memory, the memory storing processor-executable instructions that, when executed by the one or more processors, are to cause the one or more processors to carry out operations of one or more of the methods described herein.
[0013] In yet a further aspect, the present application describes a computer-readable medium storing computer-executable instructions that, when executed by one or more processors, are to cause the one or more processors to carry out any one or more of the methods described herein.
[0014] In another aspect, the present application describes a computer program comprising instructions which, when executed by a computing device, are to cause the computing device to carry out any one or more of methods described herein.
[0015] In a further aspect, the present application describes a computing device having means to perform any one or more of the methods described herein.
[0016] Other aspects and features of the present application will be understood by those of ordinary skill in the art from a review of the following description of examples in conjunction with the accompanying figures.BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Reference will now be made, by way of example, to the accompanying drawings in which:
[0018] FIG. 1 shows a simplified diagram of an example retrieval augmented generation system;
[0019] FIG. 2 shows a diagram of an example multiple-agent reinforcement learning system;
[0020] FIG. 3 illustrates an example n-dimensional vector space;
[0021] FIG. 4 shows, in flowchart form, one example method for fine-tuning a domain-specific knowledge base for use in information retrieval;
[0022] FIG. 5 illustrates an example adjustment to the positions of knowledge base vectors in a vector space;
[0023] FIG. 6 shows, in flowchart form, one example method of creating and using an improved retrieval augmented generation system;
[0024] FIG. 7 shows a high-level diagram of an example computing device; and
[0025] FIG. 8 shows a simplified example of software components within the computing device.
[0026] Like reference numerals are used in the drawings to denote like elements and features.DETAILED DESCRIPTION
[0027] In recent years, Artificial Intelligence (AI) has experienced an exponential growth, gaining widespread adaption across industries. The advent of transformer-based architectures, an advanced type of deep neural network, has played a crucial role in the expansion and adoption of AI. Large Language Models (LLMs) are a transformer-based model characterized by their significant size and extensive training on vast amounts of text data. Their large size and training make them capable of handling a wide range of natural language processing tasks, including generative operation in which an input prompt, such as a natural language query, causes the model to generate an answer to the prompt. The answer may be in the form of a newly-generated text or image or other media, for example.
[0028] Although LLMs may generally exhibit a broad understanding of human language, their knowledge is cut-off in time based on the training phase, and they are normally trained on public data. Therefore, at times an LLM may hallucinate and generate incorrect or unrealistic output. Hallucinations or errors may be more common when a prompt references domain specific private data or a concept evolved after cut-off time. Accordingly, in some cases, a general LLM trained on a vast array of public data may be fine-tuned on domain specific data. Through fine-tuning the domain specific knowledge can be incorporated into the parametric memory of the model. This typically requires that the domain-specific data be pre-labelled.
[0029] In some cases, where an LLM has not been trained on domain specific data or if fine-tuning of the LLM is not possible, an alternative solution is Retrieval Augmented Generation (RAG) . RAG leverages external knowledge sources, such as organizational documents, to enhance the generation process by retrieving relevant information and feeding it to the LLM together with the prompt or query. Through this approach, the information will be stored in non-parametric memory of the model. Relevant chunks of domain-specific information may be retrieved and sent to model for context-aware response generation. In other words, an information retrieval system is used to obtain relevant domain-specific data and that relevant domain-specific data is used to augment the prompt that is then used by an LLM to generate the requested response.
[0030] Classical IR systems mainly relied on the occurrence and frequency of keywords within documents and queries to assess relevance. While they were effective for straightforward queries, these methods often struggled with the complexities of natural language and semantic meaning. One existing IR technique is a Boolean Retrieval Model in which exact match criteria are used with Boolean operators (AND, OR, NOT) . Another technique is a Term Frequency Inverse Document Frequency (TF-IDF) technique, which calculates weights based on term frequency in documents and inverse document frequency across the corpus. Yet another technique is BM25, which is an enhancement of TF-IDF that takes into account document length normalization and term saturation effects, which improves retrieval performance for longer documents.
[0031] More modern IR systems primarily focus on vector-based semantic search which utilizes distributed representation of text by mapping the documents and query into high-dimensional vectors. This approach provides a semantic understanding of text by encoding the meaning, similarity and relationship between words, phrases and documents into vectors. Neural networks, especially transformer-based architectures, are widely-used tools to generate embedding vectors for the purpose of encoding and comparing text in vector form. Transformer models like BERT are pre-trained on large corpora, enabling them to capture and contextualize embedding of the words and sentences. In IR, these models can be fine-tuned on domain specific documents and queries making them capable of performing domain specific IR. However, fine-tuning requires a substantial labeled training dataset, along with significant investments in computational resources and training time.
[0032] FIG. 1 illustrates one example of a modern vector-based IR technique for implementing a RAG system 100. The system 100 includes an LLM 102. The LLM 102 may be a general transformer-based model pre-trained on a large corpus of data. The RAG element relies on a domain-specific knowledge base 106. The domain-specific knowledge base 106 may include indexed chunks of the knowledge-based documents or records. The chunks of the domain-specific knowledge base 106 are then embedded using an encoder transformer-based model, as indicated by numeral 108, which produces a set of vectors stored in a vector database 110.
[0033] To process a search query 104, the same encoder transformer-based model is used to embed the search query 104, as indicated by numeral 112, resulting in an n-dimensional query vector. That query vector is then used to identify one or more vectors in the vector database 110 that are most relevant to the search query 104. In some cases, this is carried out through determining which of the vectors representing chunks of the domain-specific knowledge base 106 in the vector database 110 are most closely aligned with the vector representation of the search query 104. From this process, an augmented query 114 may be determined, which includes the embedded query and the most-relevant one or more chunks (typically in vector form) from the vector database 110. This augmented query 114 is then input to the LLM 102 to obtain an output query response to the search query 104.
[0034] A key element of a RAG system is its Information Retrieval (IR) component, which plays a crucial role in efficiently retrieving and incorporating relevant information, thereby ensuring the LLM can deliver precise and insightful outputs tailored to specific business needs.
[0035] However, classical IR systems often fall short due to their lack of semantic understanding. For modern IR systems, while they use pre-trained embedding models to generate a contextualized vector database and are capable of performing semantic search, they may be constrained by their reliance on these models and may not perform well when it comes to highly specialized domains or terminologies. Resolving that issue for transformer-based IR systems requires fine-tuning of the encoder transformer-based model, which involves creating domain-specific training datasets and allocating sufficient resources for the fine-tuning process; this can lead to significant computational and time overhead, and in some cases, may not be feasible if the pre-trained transformer model is closed source and cannot be downloaded for fine-tuning.
[0036] In cases where the model can be fine-tuned, the process involves preparing a large task-specific training dataset, and significant computational and time resources to perform the fine-tuning. Moreover, it requires labelled training data.
[0037] In accordance with one aspect, the present application provides methods and systems that enable RAG systems without necessarily requiring a labelled domain-specific training dataset. Through the use of Reinforcement Learning (RL) , the present application enables the model to learn the optimal action through interaction with the environment. RL can be used to generate or refine domain-specific embedding vectors without the need for fine-tuning or change to the core pre-trained embedding model. Compared to the conventional fine-tuning techniques, the proposed technique does not require a labeled training dataset and extensive computational resources for fine-tuning.
[0038] In the embodiments described below, a pre-trained embedding model is used to generate an initial vector database from the domain-specific knowledge base. RL is then used to adjust the embedding vectors stored in the vector database.
[0039] In one aspect, the RL process used in implementations of the present application may be a multi-agent reinforcement learning (MARL) algorithm, in which multiple agents simultaneously act upon the n-dimensional vector space until, over the course of multiple rounds, an equilibrium state is reached. The MARL process may rely on a plurality of queries, where each query is represented as an embedded query vector in the vector database and there is an “agent” that corresponds to each query. Each agent then acts upon a subset of nearby knowledge base vectors in close proximity to its corresponding query vector. Each agent may make small adjustments to the position of the knowledge base vectors, where the knowledge base vectors are n-dimensional vectors each encoding a chunk of the knowledge base. At each round, a reward function may be evaluated to assess the collective experience of the agents. The adjustments and reward evaluation are continued until some condition is reached. The condition may be an equilibrium condition, e. g. a condition in which none of the agents can further improve their respective rewards by unilaterally deviating from their strategy while other agents retain their strategies.
[0040] Reference is now made to FIG. 2, which shows an example MARL system 200. In this example the system 200 includes n agents 204 (shown individually as 204a, 204b, …, 204n) . The agents 204 act upon an environment 202. In the examples below, the environment 202 is an n-dimensional vector search space containing a plurality of knowledge base vectors. The vectors are generated through embedding of chunks of the knowledge base using a pre-trained embedding model. Each agent 204 is associated with a query, where the query is embedded using the same pre-trained embedding model. This means that each query maps to a query vector in the environment 202, i.e. it maps to a location or point within the environment.
[0041] Each agent 204 takes action at the same time. The action taken in this example is to displace nearby chunks of the knowledge base. That is, each agent 204 is associated with a query vector and that query vector has a set of nearby knowledge base vectors. The agent 204 takes action to push or pull those knowledge base vectors, i.e. to move them closer or to push them further away from the query vector location. More particularly, the agent 204 prefers to push unrelated knowledge base vectors away and to pull related knowledge base vectors closer. The agents 204 take action simultaneously, and each agent 204 is unaware at the time of what actions the other agents 204 are taking, making the environment 202 non-stationary from each agent’s point of view.
[0042] MARL algorithms try to find a solution that is mutually beneficial to all agents. Each agent 204 tries to optimize its own action-selection strategy while striving for a cooperative equilibrium that maximizes overall utilities across all agents 204. The MARL process may continue until a stopping condition is met. In some cases, the stopping condition is achievement of an equilibrium state. The equilibrium state may be a Nash equilibrium condition in some examples. The MARL process may be implemented as a general-sum normal game model.
[0043] To evaluate the state of the environment, a “reward” expression may be defined that evaluates or measures the effect of the actions. The reinforcement leaning aspect of the MARL process may employ a Deep Q-network (DQN) , which employs a deep neural network to learn and optimize action-value functions. In this manner, the agents 204 independently act upon their nearby environment until the overall network moves towards convergence. The outcome of the MARL process is an updated environment 202 in which the locations of the embedded knowledge base vectors have been fine-tuned using a set of queries relevant to the domain-specific knowledge base. This results in a fine-tuned embedded knowledge base that will tend to perform better for information retrieval tasks when used in a RAG system.
[0044] Reference is now made to FIG. 3, which shows one example of an n-dimensional vector space 300. For ease of illustration, a three-dimensional Cartesian coordinate system is illustrated, but it will be appreciated that in reality the vector space 300 may be expanded to many more dimensions. The black dots represent the locations of embedded knowledge base vectors. The X symbols represent the locations of embedded query vectors. As will be described in greater detail below, during the action-phase of the MARL process, each agent determines an action to take with regard to nearby points. In particular, a parameter k may be selected to determine the number of closest points on which to act. In this example, k is set to k=5, such that each agent identifies the k closest knowledge base vectors (in a Euclidean sense) to its query vector. The example circles in FIG. 3 show the nearest k points (knowledge base vectors) to a particular query vector where k=5.
[0045] In one example implementation, if no pre-trained embedding model is available, the knowledge base vectors and the query vectors may be initially randomly scattered in the vector space.
[0046] FIG. 4 shows, in flowchart form, one example method 400 of fine-tuning a domain-specific knowledge base for use in information retrieval. The method 400 may be implemented on one or more computing devices. The method 400 may be carried out by one or more processors based on processor-executable instructions stored in memory within the one or more computing devices. The method 400 is aimed at generating a fine-tuned domain-specific vector search space for use in information retrieval from an unlabelled domain-specific knowledge base (KB) .
[0047] In operation 402, an n-dimensional vector search space is initialized by embedding chunks of the knowledge base as knowledge base vectors using a pre-trained embedding model. The pre-trained embedding model may be a transformer-based model and may correspond to the transformer-based model utilized in a LLM for which the information retrieval system is intended to be used. Each chunk of the knowledge base is embedded as one of the knowledge base vectors. The term “chunk” will be understood to mean a document or record from the knowledge base or a part of a document or record from the knowledge base.
[0048] In operation 404, a set of queries is embedded using the same pre-trained embedding model to obtain a set of query vectors within the vector search space. In some examples, the RAG system may be operated for a period of time without fine-tuning of the vector space so as to collect and store a set of queries. After collection of a threshold number of queries, the system may then be refined using the processes described herein. In some cases, the fine-tuning of the vector space may be carried out periodically as new sets of queries are collected.
[0049] The set of all knowledge base chunks is Ψ= {1, 2, …, C} . The set of all queries is Θ={1, 2, …, N} . The points associated with knowledge base vectors are at positions Pc where c ∈ Ψ, and the points associated with query vectors are at positions where n∈Θ. Each query, q, has an associated agent, λq, and the set of agents is Λ={λ1, λ2, …, λN} .
[0050] The initialization operations 402 and 404 may further include initializing each agent’s Joint-Action Value DQN Q with weights θn. The Joint-Action Value DQN Q may be referred to as the main network. In addition, a target network, Joint-Action Value DQN Q′may be initialized with weights θ′n. A replay buffer of the experience of each agent may also be initialized. These networks and memory allocations are used in action selection and reward evaluation as part of the MARL process.
[0051] In operation 406, each agent selects actions to impose on nearby knowledge base vectors. The value k may indicate the number of nearby (e.g. closest) knowledge base vectors on which each agent acts.
[0052] In some examples, each agent may employ an ε-greedy strategy to achieve an exploration-exploitation trade off. For instance, with probability p= ε each agent λn, where n∈Θ, selects a random action for points where i ∈ {1, …, k} and Kn denotes the set of k closet points to query n. This may be referred to as an Exploration phase. Then, with probability p=1-ε each agent λn takes action according to its action-selection policy obtained from the current target DQN Q′. The actions, for each agent λn may be obtained according to a policy approximated through the DQN. Intuitively, for the ith KB chunk that is related to the query and that contributes to a positive reward, the action will be “negative” so as to bring the knowledge base point closer to the query at point The displacement of point may be expressed as:
[0053] where, is the new or adjusted position of after displacement and, uni is the unit vector in the direction from to according to:
[0054] FIG. 5 illustrates the example vector search space showing the displacement of two points, and to their new positions, and through the actions taken by the agent associated with the query vectors at point
[0055] Referring still to FIG. 4, in operation 408 a joint reward function is evaluated after all of the selected actions have been carried out. The joint reward may be a measure of the relevance of the n-dimensional knowledge base vectors to the query vectors and their relative proximity. In one example, the reward function for agent λn may be expressed as:
[0056] In the above expression, the eval function is 0 if the knowledge base vector is related to the query and 1 if the knowledge base vector is not related to the query. In other words, it makes the reward positive for related vectors and negative for unrelated vectors. The sign function is applied to the distance metric that measures the distance between the query vector and the knowledge base vector. The eval function may be expressed as:
[0057] The determination of relevance may, in one implementation, be based on a human evaluation of relevance, i.e. the manual labelling of whether certain chunks of the knowledge base are relevant to a particular query or not. However, in many implementations, a pre-trained LLM may be used to assess and determine relevance as between particular chunks of the knowledge base and particular queries.
[0058] The experiences, including the action, the reward, the original state and the resulting state of the environment, for each agent n are then stored. The stored experience may be expressed as: The state of the environment is given by The set of all actions, i.e. joint actions, carried out by the agents at time t is and rnt is the immediate reward received by agent n.
[0059] In accordance with the learning aspect of the DQN, for each agent n, a main network Q may then be trained on the collected experiences ent. In particular, a batch of the experiences may be selected. The weights θ of the main network Q, may then be updated based on the selected batch of experiences by performing a gradient descent on ( (yt-Q (st) ) 2) , where yt is:
[0060] Where a′n, t is the Best Response action for agent n (considering the action of all other agents (i.e., ) ) :
[0061] When considering the joint actions, the expected Q-values estimated by the DQNs, will align with the Best Response algorithm in terms of maximizing the agents’ expected rewards, which tends to move the environment toward an equilibrium solution. In this sense, the expression reflects a measure of future reward or expected reward. The factor γ is discount factor intended to discount future rewards. Every C steps, where C is a hyper parameter specifying the update frequency of the Q′network, the parameters of the Q network are copied to the Q′network (θ→θ′) .
[0062] In operation 410, the method 400 evaluates whether an equilibrium state has been reached, e.g. a Nash equilibrium. That is, the system determines whether no agent can further improve its reward value through deviating its strategy whilst all other agents keep their action strategies the same.
[0063] If equilibrium has not been reached, the method 400 returns to operation 406 to again select and carry out actions to displace nearby knowledge base vectors and to reevaluate the impact on the collective reward. If equilibrium has been reached, then in operation 412, the resulting environment, i.e. the vector search space containing the fine-tuned knowledge base vectors reflecting embedding of the domain-specific knowledge base, may then be used for information retrieval in response to queries. In some cases, this information retrieval function is carried out in the context of a retrieval augmented generation system, i.e. a RAG system having an LLM.
[0064] FIG. 6 shows, in flowchart form, one example method 600 of realizing and utilizing an improved RAG system. The method 600 may be implemented on one or more computing devices. The method 600 may be carried out by one or more processors based on processor-executable instructions stored in memory within the one or more computing devices.
[0065] In operation 602, a domain-specific knowledge base and a set of queries are embedded using a pre-trained transformer model. The pre-trained transform model may be the same transformer model used in an LLM. The embedding of the knowledge base chunks and the set of queries produces a set of knowledge base vectors and a set of query vectors in an n-dimensional vector space. In operation 604, a MARL process may be used to fine-tine the positions of the set of knowledge base vectors, as described above. Through reinforcement learning based on the set of queries, adjustments are made to the knowledge base vectors. Once convergence or equilibrium is reached, the resulting environment, i.e. the fine-tuned n-dimensional vector search space, represents a fine-tuned embedded knowledge base that is available for more accurate or more efficient and effective information retrieval.
[0066] In operation 606, a query is received. The query is embedded using the pre-trained transformer model. The embedded query is then used in operation 608 to search the fine-tuned vector search space that resulted from operation 604. The query-based search identifies and obtains one or more of the most relevant chunks of the knowledge base, i.e. the one or more most relevant knowledge base vectors. The most relevant chunks are those having the closest knowledge base vectors to the query vector, as determined using Euclidean-based semantic search.
[0067] In operation 610, the retrieved one or more most relevant knowledge base vectors (i.e. chunks) are input to the LLM along with the embedded query. That is, the query and the retrieved relevant chunks are used to create an augmented query, which is then input to the LLM as a prompt. In response, the LLM outputs generated content in operation 612, where the generated content is produced by the LLM in reply to the augmented query.
[0068] Reference will now be made to FIG. 7, which shows a high-level diagram of an example computing device 700. The example computing device 700 includes a variety of modules. For example, the example computing device 700 may include a processor 710, a memory 720, an I / O module 740, and a communications module 750. As illustrated, the foregoing example modules of the example computing device 700 are in communication over a bus 760.
[0069] The processor 710 in this example is a hardware processor. The processor 710 may, for example, be one or more ARM, Intel x86, PowerPC processors, or the like.
[0070] The memory 720 allows data to be stored and retrieved. The memory 720 may include, for example, random access memory, read-only memory, and persistent storage. Persistent storage may be, for example, flash memory, a solid-state drive or the like. Read-only memory and persistent storage are a computer-readable medium. A computer-readable medium may be organized using a file system such as may be administered by an operating system governing overall operation of the example computing device 700.
[0071] The I / O module 740 allows the example computing device 700 to receive input signals and to transmit output signal. Input signals may, for example, correspond to input received from a user. Some output signals may, for example, allow provision of output to a user. The I / O module 740 may serve to interconnect the example computing device 700 with one or more input devices. Input devices may, for example, include one or more of a touchscreen input, keyboard, trackball or the like. The I / O module 740 may serve to interconnect the example computing device 700 with one or more output devices. Output devices may include, for example, one or more display screens such as, for example, a liquid crystal display (LCD) , a touchscreen display. Additionally, or alternatively, output devices may include devices other than screens such as, for example, a speaker, indicator lamps (such as, for example, light-emitting diodes (LEDs) ) , and printers.
[0072] The communications module 750 allows the example computing device 700 to communicate with other electronic devices and / or various communications networks. For example, the communications module 750 may allow the example computing device 700 to send or receive communications signals. As an example, the communications module 750 may include a network connection, data port, or the like. Communications signals may be sent or received according to one or more protocols or according to one or more standards. For example, the communications module 750 may allow the example computing device 700 to communicate via a cellular data network, such as for example, according to one or more standards such as, for example, Global System for Mobile Communications (GSM) , Code Division Multiple Access (CDMA) , Evolution Data Optimized (EVDO) , Long-term Evolution (LTE) , 5G, 6G, or the like. Additionally, or alternatively, the communications module 650 may allow the example computing device 700 to communicate using near-field communication (NFC) , via Wi-Fi (TM) , via the Ethernet family of network protocols, using Bluetooth (TM) or via some combination of one or more networks or protocols. In some embodiments, all or a portion of the communications module 750 may be integrated into a component of the example computing device 700. In some examples, the communications module may be integrated into a communications chipset.
[0073] Software instructions are executed by the processor 710 from a computer-readable medium. For example, software may be loaded into random-access memory from persistent storage within memory 720. Additionally, or alternatively, instructions may be executed by the processor 710 directly from read-only memory of the memory 720.
[0074] FIG. 8 depicts a simplified organization of software components stored in memory 720 of the example computing device 700. As illustrated, these software components include, at least, application software 810 and an operating system 800.
[0075] The application software 810 adapts the example computing device 700, in combination with the operating system 800, to operate as a device performing a particular function. While a single application software 810 is illustrated in FIG. 8, in operation, the memory 720 may include more than one application software and different application software may perform different operations.
[0076] The operating system 800 is software. The operating system 800 allows the application software 810 to access the processor 710, the memory 720, the I / O module 740, and the communications module 750. The operating system 800 may, for example, be iOSTM, AndroidTM, LinuxTM, Microsoft WindowsTM, or the like.
[0077] The application software 810 and / or operating system 800 may, when executed, cause the processor 710 to carry out operations to implement at least some portion of one or more of the methods described herein.
[0078] In the present disclosure, the terms “a” , “an” and “one” are defined to mean “at least one” , that is, these terms do not exclude a plural number of items, unless stated otherwise.
[0079] In the present disclosure, terms such as “substantially” , “generally” and “about” , which modify a value, condition or characteristic of a feature of an embodiment, should be understood to mean that the value, condition or characteristic is defined within tolerances that are acceptable for the proper operation of this embodiment for its intended application.
[0080] In the present disclosure, unless stated otherwise, the terms “connected” and “coupled” , and derivatives and variants thereof, refer herein to any structural or functional connection or coupling, either direct or indirect, between two or more elements. For example, the connection or coupling between the elements can be acoustical, mechanical, optical, electrical, thermal, logical, or any combinations thereof.
[0081] In the present disclosure, expressions such as “match” , “matching” and “matched” , including variants and derivatives thereof, are intended to refer herein to a condition in which two or more elements are either the same or within some predetermined tolerance of each other. That is, these terms are meant to encompass not only “exactly” or “identically” matching the two elements but also “substantially” , “approximately” or “subjectively” matching the two or more elements, as well as providing a higher or best match among a plurality of matching possibilities.
[0082] In the present disclosure, the expression “based on” is intended to mean “based at least partly on” , that is, this expression can mean “based solely on” or “based partially on” , and so should not be interpreted in a limited manner. More particularly, the expression “based on” could also be understood as meaning “depending on” , “representative of” , “indicative of” , “associated with” or similar expressions.
[0083] In the present disclosure, the terms "system" and "network" may be used interchangeably in embodiments of this application. "At least one" means one or more, and "a plurality of" means two or more. The term "and / or" describes an association relationship of associated objects and indicates that three relationships may exist. For example, A and / or B may indicate the following three cases: Only A exists, both A and B exist, and only B exists, where A and B may be singular or plural. The character " / " usually indicates an "or" relationship between associated objects. "At least one of the following items (pieces) " or a similar expression thereof indicates any combination of these items, including a single item (piece) or any combination of a plurality of items (pieces) . For example, "at least one of A, B, or C" includes A, B, C, A and B, A and C, B and C, or A, B, and C, and "at least one of A, B, and C" may also be understood as including A, B, C, A and B, A and C, B and C, or A, B, and C. In addition, unless otherwise specified, ordinal numbers such as "first" and "second" in embodiments of this application are used to distinguish between a plurality of objects, and are not used to limit a sequence, a time sequence, priorities, or importance of the plurality of objects.
[0084] In the present application, the phrase “at least one of…or…” is intended to cover any one or more of the listed elements, including any one of the listed elements alone, any sub-combination, or all of the elements, without necessarily excluding any additional elements, and without necessarily requiring all of the elements. The term “and / or” is intended to indicate that either of the two elements may be included or both of the elements may be included.
[0085] A person skilled in the art will understand that embodiments of this application may be provided as a method, an apparatus (or system) , a computer-readable storage medium, or a computer program product. Therefore, this application may use a form of a hardware-only embodiment, a software-only embodiment, or an embodiment with a combination of software and hardware. Moreover, this application may use a form of a computer program product that is implemented on one or more computer-usable storage media (including but not limited to a disk memory, an optical memory, and the like) that include computer-usable program code.
[0086] This application is described with reference to the flowcharts and / or block diagrams of the method, the device (system) , and the computer program product according to this application. It should be understood that computer program instructions may be used to implement each process and / or each block in the flowcharts and / or the block diagrams and a combination of a process and / or a block in the flowcharts and / or the block diagrams. The computer program instructions may be provided for a general-purpose computer, a dedicated computer, an embedded processor, or a processor of another programmable data processing device to generate a machine, so that the instructions executed by the computer or the processor of the another programmable data processing device generate an apparatus for implementing a specific function in one or more procedures in the flowcharts and / or in one or more blocks in the block diagrams.
[0087] The computer program instructions may alternatively be stored in a computer-readable memory that can indicate a computer or another programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate an artifact that includes an instruction apparatus. The instruction apparatus implements a specific function in one or more procedures in the flowcharts and / or in one or more blocks in the block diagrams.
[0088] The computer program instructions may alternatively be loaded onto a computer or another programmable data processing device, so that a series of operations and steps are performed on the computer or the another programmable device, so that computer-implemented processing is generated. Therefore, the instructions executed on the computer or the another programmable device provide steps for implementing a specific function in one or more procedures in the flowcharts and / or in one or more blocks in the block diagrams.
[0089] It will be understood that a person skilled in the art may make various modifications and variations to this application without departing from the scope of this application. This application is intended to cover these modifications and variations of this application provided that they fall within the scope of protection defined by the following claims and their equivalent technologies.
[0090] Throughout the present disclosure, a processor, a processor system, an application processor, a baseband processor, a processor circuit, or a processor core may be collectively referred to as a processor. A processor may include one or more of a central processing unit (CPU) , a digital signal processor (DSP) , a microprocessor unit (MPU) , a microcontroller unit, (MCU) , a graphics processing unit (GPU) , a field programmable gate array (FPGA) , an artificial intelligence (AI) processor, or a neural network processing unit (NPU) , or a combination of at least two of these integrated circuit forms.
[0091] Throughout the present disclosure, a memory may include one or more of the following storage media: a RAM, a static random access memory (SRAM) , a dynamic random access memory (DRAM) , a phase-change memory (PCM) , a resistive random access memory (ReRAM) , a magnetoresistive random access memory (MRAM) , a ferroelectric random access memory (FRAM) , a cache, a register, a read-only memory (ROM) , a flash memory, an erasable programmable read-only memory (EPROM) , a hard disk, and / or the like. In an example, the computer program instructions used to execute embodiments contained herein may be stored in a non-volatile memory. When a terminal runs, part or all of corresponding computer program instructions may be loaded into a memory that has a higher transmission speed with a corresponding processor, for example, the instructions may be loaded into at least a part of a memory such that the processor executes the computer program instructions to perform the steps in of embodiments described herein.
[0092] The various embodiments presented above are merely examples and are in no way meant to limit the scope of this application. Variations of the innovations described herein will be apparent to persons of ordinary skill in the art, such variations being within the intended scope of the present application. In particular, features from one or more of the above-described example embodiments may be selected to create alternative example embodiments including a sub-combination of features which may not be explicitly described above. In addition, features from one or more of the above-described example embodiments may be selected and combined to create alternative example embodiments including a combination of features which may not be explicitly described above. Features suitable for such combinations and sub-combinations would be readily apparent to persons skilled in the art upon review of the present application as a whole. The subject matter described herein and in the recited claims intends to cover and embrace all suitable changes in technology.
Claims
1.A method of improved retrieval augmented generation, the method comprising:generating a vector space from a domain-specific knowledge base containing a plurality of records through embedding, with an encoder transformer-based model, a plurality of chunks of the domain-specific knowledge base as knowledge base vectors;embedding a plurality of queries using the encoder transformer-based model to obtain a plurality of query vectors;using a multi-agent reinforcement learning algorithm and a respective agent for each of the query vectors to modify a position of at least some of the knowledge base vectors relative to the query vectors within the vector space until an equilibrium condition is met and thereby producing a modified vector space;receiving a search query and embedding the search query to obtain a search query vector;retrieving a subset of the knowledge base vectors based on a semantic search within the modified vector space using the search query vector; andobtaining a query response from a large language model by inputting the subset of the knowledge base vectors and the search query vector.2.The method of claim 1, wherein using includes, for each respective agent and its associated query vector,identifying a respective subset of the knowledge base vectors in closest proximity to that query vector,applying a respective action to the position of each of the knowledge base vectors in the subset, andjointly evaluating reward functions for the agents.3.The method of claim 2, wherein the action is either a displacement away from or a displacement towards one of the query vectors.4.The method of claim 3, wherein the reward function for one of the agents having an associated query vector increases based on closer proximity of a relevant knowledge vector to the associated query vector and decreases based on closer proximity of a non-relevant knowledge vector to the associated query vector.5.The method of claim 4, wherein the increase or decrease based on proximity is based on relevance of the knowledge base vector to the associated query vector and a measure of distance between the associated query vector and the knowledge vector.6.The method of claim 1, wherein modifying the position includes, for one of the query vectors, adjusting the position of a nearby knowledge base vector to be further from said one of the query vectors or adjusting the position of the nearby knowledge base vector to be closer to said one of the query vectors.7.The method of claim 1, wherein the equilibrium condition is a Nash equilibrium condition.8.The method of claim 1, wherein the encoder transformer-based model is a pre-trained embedding model and wherein the method does not alter the pre-trained embedding model.9.The method of claim 1, wherein, in the modified vector space, the proximity of one of the knowledge base vectors to one of the query vectors is indicative of the semantic relevance of said one of the knowledge base vectors to said one of the query vectors.10.A system for retrieval augmented generation, the system comprising:one or more computing devices having one or more processors and memory, the memory storing processor-executable instructions that, when executed by the one or more processors, are to cause the one or more processors to:generate a vector space from a domain-specific knowledge base containing a plurality of records through embedding, with an encoder transformer-based model, a plurality of chunks of the domain-specific knowledge base as knowledge base vectors;embed a plurality of queries using the encoder transformer-based model to obtain a plurality of query vectors;use a multi-agent reinforcement learning algorithm and a respective agent for each of the query vectors to modify a position of at least some of the knowledge base vectors relative to the query vectors within the vector space until an equilibrium condition is met and thereby produce a modified vector space;receive a search query and embed the search query to obtain a search query vector;retrieve a subset of the knowledge base vectors based on a semantic search within the modified vector space using the search query vector; andobtain a query response from a large language model by inputting the subset of the knowledge base vectors and the search query vector.11.The system of claim 10, wherein the processor-executable instructions, when executed by the one or more processors, are to cause the one or more processors to use the multi-agent reinforcement learning algorithm by causing the one or more processor to, for each respective agent and its associated query vector,identify a respective subset of the knowledge base vectors in closest proximity to that query vector,apply a respective action to the position of each of the knowledge base vectors in the subset, andjointly evaluate reward functions for the agents.12.The system of claim 11, wherein the action is either a displacement away from or a displacement towards one of the query vectors.13.The system of claim 12, wherein the reward function for one of the agents having an associated query vector increases based on closer proximity of a relevant knowledge vector to the associated query vector and decreases based on closer proximity of a non-relevant knowledge vector to the associated query vector.14.The system of claim 13, wherein the increase or decrease based on proximity is based on relevance of the knowledge base vector to the associated query vector and a measure of distance between the associated query vector and the knowledge vector.15.The system of claim 10, wherein the processor-executable instructions, when executed by the one or more processors, are to cause the one or more processors to modify the position by causing the one or more processor to, for one of the query vectors, adjust the position of a nearby knowledge base vector to be further from said one of the query vectors or adjust the position of the nearby knowledge base vector to be closer to said one of the query vectors.16.The system of claim 10, wherein the equilibrium condition is a Nash equilibrium condition.17.The system of claim 10, wherein the encoder transformer-based model is a pre-trained embedding model and wherein the processor-executable instructions, when executed, do not alter the pre-trained embedding model.18.The system of claim 10, wherein, in the modified vector space, the proximity of one of the knowledge base vectors to one of the query vectors is indicative of the semantic relevance of said one of the knowledge base vectors to said one of the query vectors.19.A non-transitory computer readable medium storing processor-executable instructions that, when executed by one or more processors, are to cause the one or more processors to carry out the method claimed in any one of claims 1 to 9.20.A computer program comprising instructions which, when executed by a computing device, are to cause the computing device to carry out the method claimed in any one of claims 1 to 9.