Token efficient domain recommendations
Aspects of the invention provide a method, computer system, and computer program product for retrieval augmented generation. In one aspect, the method includes receiving a query. The method further includes classifying the query to a first domain within a multitude of domains. The method additionally includes retrieving an index of domain-specific vector embeddings corresponding to the domains. The method further includes prompting a Large Language Model (LLM) with the query and the domain-specific vector embeddings. The method also includes receiving a query response from the LLM as grounded with the most relevant index results. The method further includes forwarding the query response.
1 . A method comprising:
receiving a query;
classifying the query to a first domain within a plurality of domains, based at least in part on average computational resource usage across the plurality of domains, comprising:
calculating a token count adjusted confidence score for each domain of the plurality of domains as a quotient of a weighted confidence score of each domain and a function of an average token count of each domain modulated by a tunable hyperparameter;
retrieving an index of domain-specific vector embeddings corresponding to the plurality of domains;
prompting a Large Language Model (LLM) with the query and the index of domain-specific vector embeddings for retrieval augmented generation (RAG) of a query response;
generating, by the LLM, the query response grounded with a relevant domain-specific vector embedding of the index of domain-specific vector embeddings as a contextual anchor, wherein the query response is aligned with a semantic space of the relevant domain-specific vector embedding;
forwarding the query response over a network communication channel to a downstream application; and
displaying, by the downstream application, the query response in a user interface.
2 . The method of claim 1 , further comprising:
calculating a global confidence score; and
comparing the plurality of domains and suggesting the plurality of domains.
3 . The method of claim 1 , wherein the weighted confidence score is calculated as:
weighted
confidence
j
=
∑
i
=
1
k
(
sigmoid
i
j
×
weight
i
j
)
+
η
j
wherein:
j is a domain,
k is a number of top results,
i is a current index,
sigmoid is a sigmoid function,
weight is a confidence score weight, and
η j is a domain specific biasing constant.
4 . The method of claim 3 , wherein the domain specific biasing constant is calculated as:
η
j
=
ω
c
×
C
j
+
ω
h
×
H
j
+
ω
p
×
P
j
wherein:
ω c is a weight for a current context bias,
C j is a current context relevance to domain j,
ω h is a weight for a conversation history bias,
H j is a conversation history relevance to domain j,
ω p is a weight for a popularity bias, and
P j is a popularity of domain j.
5 . The method of claim 2 , wherein the global confidence score is calculated as:
GCS
=
μ
TCACS
+
β
+
σ
TCACS
wherein:
μ is a mean of TCACS across the plurality of domains,
β is a tunable hyperparameter, and
σ is a standard deviation of TCACS across the plurality of domains.
6 . The method of claim 2 , wherein comparing the plurality of domains further comprises:
if the token count adjusted confidence score of the first domain is greater than the global confidence score, retrieving results from the first domain; and
if the token count adjusted confidence score of the first domain is not greater than the global confidence score, retrieving the results from the plurality of domains.
7 . A system comprising:
a computer processor;
memory; and
instructions stored in the memory and executable by the computer processor to cause the computer processor to perform operations, the operations comprising:
receiving a query,
classifying the query to a first domain within a plurality of domains, based at least in part on average computational resource usage across the plurality of domains, comprising:
calculating a token count adjusted confidence score for each domain of the plurality of domains as a quotient of a weighted confidence score of each domain and a function of an average token count of each domain modulated by a tunable hyperparameter,
retrieving an index of domain-specific vector embeddings corresponding to the plurality of domains,
prompting a large language model with the query and the index of domain-specific vector embeddings for retrieval augmented generation (RAG) of a query response,
generating, by the LLM, the query response grounded with a relevant domain-specific vector embedding of the index of domain-specific vector embeddings as a contextual anchor, wherein the query response is aligned with a semantic space of the relevant domain-specific vector embedding;
forwarding the query response over a network communication channel to a downstream application; and
displaying, by the downstream application, the query response in a user interface.
8 . The system of claim 7 , further comprising:
calculating a global confidence score; and
comparing the plurality of domains and suggesting the plurality of domains.
9 . The system of claim 7 , wherein the weighted confidence score is calculated as:
weighted
confidence
j
=
∑
i
=
1
k
(
sigmoid
i
j
×
weight
i
j
)
+
η
j
wherein:
j is a domain,
k is a number of top results,
i is a current index,
sigmoid is a sigmoid function,
weight is a confidence score weight, and
η j is a domain specific biasing constant.
10 . The system of claim 9 , wherein the domain specific biasing constant is calculated as:
η
j
=
ω
c
×
C
j
+
ω
h
×
H
j
+
ω
p
×
P
j
wherein:
ω c is a weight for a current context bias,
C j is a current context relevance to domain j,
ω h is a weight for a conversation history bias,
H j is a conversation history relevance to domain j,
ω p is a weight for a popularity bias, and
P j is a popularity of domain j.
11 . The system of claim 8 , wherein the global confidence score is calculated as:
GCS
=
μ
TCACS
+
β
+
σ
TCACS
wherein:
μ is a mean of TCACS across the plurality of domains,
β is a tunable hyperparameter, and
σ is a standard deviation of TCACS across the plurality of domains.
12 . The system of claim 8 , wherein comparing the plurality of domains further comprises:
if the token count adjusted confidence score of the first domain is greater than the global confidence score, retrieving results from the first domain; and
if the token count adjusted confidence score is not greater than the global confidence score, retrieving the results from the plurality of domains.
13 . A computer program product comprising a non-transitory computer-readable medium having stored thereon program code that, when executed by one or more computer processors, causes the one or more computer processors to perform operations comprising:
receiving a query;
classifying the query to a first domain within a plurality of domains, based at least in part on average computational resource usage across the plurality of domains, comprising:
calculating a token count adjusted confidence score for each domain of the plurality of domains as a quotient of a weighted confidence score of each domain and a function of an average token count of each domain modulated by a tunable hyperparameter,
retrieving an index of domain-specific vector embeddings corresponding to the plurality of domains;
prompting a Large Language Model (LLM) with the query and the index of domain-specific vector embeddings for retrieval augmented generation (RAG) of a query response;
generating, by the LLM, the query response grounded with a relevant domain-specific vector embedding of the index of domain-specific vector embeddings as a contextual anchor, wherein the query response is aligned with a semantic space of the relevant domain-specific vector embedding;
forwarding the query response over a network communication channel to a downstream application; and
displaying, by the downstream application, the query response in a user interface.
14 . The computer program product of claim 13 , wherein classifying the query further comprises:
calculating a global confidence score;
comparing the plurality of domains; and
suggesting the plurality of domains.
15 . The computer program product of claim 13 , wherein the weighted confidence score is calculated as:
weighted
confidence
j
=
∑
i
=
1
k
(
sigmoid
i
j
×
weight
i
j
)
+
η
j
wherein:
j is a domain,
k is a number of top results,
i is a current index,
sigmoid is a sigmoid function,
weight is a confidence score weight, and
η j is a domain specific biasing constant.
16 . The computer program product of claim 15 , wherein the domain specific biasing constant is calculated as:
η
j
=
ω
c
×
C
j
+
ω
h
×
H
j
+
ω
p
×
P
j
wherein:
ω c is a weight for a current context bias,
C j is a current context relevance to domain j,
ω h is a weight for a conversation history bias,
H j is a conversation history relevance to domain j,
ψ p is a weight for a popularity bias, and
P j is a popularity of domain j.
17 . The computer program product of claim 14 , wherein the global confidence score is calculated as:
GCS
=
μ
TCACS
+
β
+
σ
TCACS
wherein:
μ is a mean of TCACS across the plurality of domains,
β is a tunable hyperparameter, and
σ is a standard deviation of TCACS across the plurality of domains.