Computationally efficient language model
A method including receiving a query to a retrieval augmented generation (RAG) language model having electronic accesses to a number of potential contexts. A desired selected context is unknown when the query is received. A number of ranking models is executed on the query. Each of the number of ranking models outputs a corresponding candidate context from among the number of potential contexts. A number of vector data structures are generated by transforming, for each output of the number of ranking models, a combination of the query and the corresponding candidate context into a corresponding vector data structure. A predictor model is executed on the number of vector data structures to generate the selected context from among the number of potential contexts. The RAG language model is enhanced by applying the selected context to the RAG language model to generate an enhanced RAG language model.
1 . A method of increasing a computational efficiency of a computer executing a retrieval augmented generation (RAG) language model having electronic access to a plurality of potential contexts, the method comprising:
receiving a query to the RAG language model having electronic accesses to the plurality of potential contexts, wherein:
the plurality of potential contexts further include a selected context, applicable to the query, selected from among the plurality of potential contexts, and
the selected context is unknown when the query is received;
executing a plurality of ranking models on the query, wherein each of the plurality of ranking models outputs a corresponding candidate context from among the plurality of potential contexts,
wherein each of the plurality of ranking models are different from each other, and
wherein a plurality of candidate contexts are identified;
generating a plurality of vector data structures by transforming, for each output of the plurality of ranking models, a combination of the query and the corresponding candidate context into a corresponding vector data structure,
wherein each of the plurality of vector data structures corresponds to a different output of the plurality of ranking models, and
wherein transforming contextually relates each of the plurality of candidate contexts to the query;
executing a predictor model on the plurality of vector data structures to generate a plurality of probabilities, wherein each of the plurality of probabilities indicates a corresponding likelihood that the corresponding candidate context is the selected context;
selecting, according to the plurality of probabilities, the selected context from among the plurality of candidate contexts; and
enhancing the RAG language model by applying only the selected context to the RAG language model to generate an enhanced RAG language model.
2 . The method of claim 1 , further comprising:
executing the enhanced RAG language model on a combination of the selected context, the query, and a prompt to generate a response to the query; and
returning the response.
3 . The method of claim 1 , further comprising:
generating, prior to transforming the combination, a list of a plurality of candidate contexts from the corresponding candidate context output by the plurality of ranking models,
wherein the plurality of vector data structures are arranged in the list.
4 . The method of claim 3 , further comprising:
enhancing the enhanced RAG language model by applying a second selected context in the list to the RAG language model.
5 . The method of claim 1 , further comprising:
excluding, while executing the plurality of ranking models on the query, an output of a rejected ranking model in the plurality of ranking models.
6 . The method of claim 5 , wherein the rejected ranking model is rejected in response to the rejected ranking model exceeding a threshold latency time to return a rejected candidate context.
7 . The method of claim 1 , further comprising:
selecting, prior to executing the plurality of ranking models on the query, the plurality of ranking models from a superset of ranking models.
8 . The method of claim 7 , further comprising:
determining, prior to executing the predictor model, a type of the query,
wherein the plurality of ranking models is selected based on the type of the query.
9 . The method of claim 7 , further comprising:
determining, prior to executing the predictor model, a source of the query,
wherein the plurality of ranking models is selected based on the source of the query.
10 . The method of claim 1 , further comprising:
selecting the predictor model from among a plurality of predictor models.
11 . The method of claim 10 , further comprising:
determining, prior to executing the predictor model, a type of the query,
wherein the predictor model is selected based on the type of the query.
12 . The method of claim 10 , further comprising:
determining, prior to executing the predictor model, a source of the query,
wherein the predictor model is selected based on the source of the query.
13 . The method of claim 1 , wherein the predictor model comprises a plurality of predictor models that generate a plurality of prediction scores corresponding to the plurality of potential contexts, and wherein the method further comprises:
combining the plurality of prediction scores to determine a set of final prediction scores for the plurality of potential contexts; and
selecting the selected context according to a highest final prediction score from among the set of final prediction scores.
14 . The method of claim 13 , wherein the plurality of predictor models predict at least two of: an entropy of a term distribution in a prompt for the RAG language model, a readability score of the plurality of potential contexts, one or more sentences in the prompt, one or more terms in the prompt, and a semantic similarity of the plurality of potential contexts to the query.
15 . A system for increasing a computational efficiency of a retrieval augmented generation (RAG) language model having electronic access to a plurality of potential contexts, the system comprising:
a computer processor and the RAG language model, executable by the computer processor, wherein the computer processor comprises a hardware computer processor;
a data repository in communication with the computer processor and storing:
a query,
the plurality of potential contexts,
a selected context applicable to the query,
a corresponding candidate context, and
a plurality of vector data structures,
a plurality of ranking models which, when executed by the computer processor on the query, outputs, for each of the plurality of ranking models, the corresponding candidate context from among the plurality of potential contexts,
wherein each of the plurality of ranking models are different from each other, and
wherein a plurality of candidate contexts are identified;
a vector model which, when executed by the computer processor, transforms a combination of the query and the corresponding candidate context into a corresponding vector data structure for each output of the plurality of ranking models, wherein:
the plurality of vector data structures are generated by transforming,
each of the plurality of vector data structures corresponds to a different output of the plurality of ranking models, and
transforming contextually relates each of the plurality of candidate contexts to the query;
a predictor model which, when executed by the computer processor on the plurality of vector data structures, generates a plurality of probabilities, wherein each of the plurality of probabilities indicates a corresponding likelihood that the corresponding candidate context is the selected context; and
a server controller which, when executed by the computer processor, enhances the RAG language model by:
selecting, according to the plurality of probabilities, the selected context from among the plurality of candidate contexts, and
applying only the selected context to the RAG language model to generate an enhanced RAG language model.
16 . The system of claim 15 , further comprising:
the enhanced RAG language model.
17 . The system of claim 15 , further comprising:
a training controller which, when executed by the computer processor, trains the predictor model to identify a term frequency-inverse document frequency (TF-IDF) score based on a combination of the query and the plurality of potential contexts.
18 . The system of claim 15 , further comprising:
a ranking model selector which, when executed by the computer processor, selects, prior to executing the plurality of ranking models on the query, the plurality of ranking models from a superset of ranking models.
19 . The system of claim 15 , further comprising:
a predictor model selector which, when executed by the computer processor, selects the predictor model from among a plurality of predictor models.