System and method for generating weighted query representations for enhanced retrieval augmented generation
A method, computer program product, and computing system for processing a query using a generative artificial intelligence (AI) model. A topic of the query is extracted. A weighting for the topic of the query is generated. A weighted query topic embedding for the topic of the query is generated. A candidate chunk is identified from a plurality of chunks of a target document by determining a similarity between the weighted query topic embedding and a plurality of chunk embeddings for the plurality of chunks. A prompt is generated using the query and the candidate chunk. The prompt is provided to the generative AI model.
1 . A computer-implemented method, executed on a computing device, comprising:
receiving a query to be processed by a generative artificial intelligence (AI) model;
extracting a query topic from the query;
generating a weighted query topic embedding for the query topic;
generating a plurality of weighted chunk topic embeddings for a plurality of chunks based on a frequency of each term in a particular chunk from a plurality of chunks of a target document and each term's frequency across all of the plurality of chunks;
identifying a candidate chunk from the plurality of chunks by determining a similarity between the weighted query topic embedding and the plurality of weighted chunk topic embeddings for the plurality of chunks;
generating a prompt using the query and the candidate chunk; and
providing the prompt to the generative AI model.
2 . The computer-implemented method of claim 1 , wherein identifying a candidate chunk includes identifying a predefined number of most similar candidate chunks.
3 . The computer-implemented method of claim 1 , further comprising:
generating the plurality of chunks for a plurality of text portions of the target document;
generating a plurality of chunk topics by extracting a topic for each respective chunk of the plurality of chunks; and
generating a weighting for the topic for each respective chunk of the plurality of chunks.
4 . The computer-implemented method of claim 3 , further comprising:
generating a weighted chunk topic embedding for each topic of a plurality of topics for a respective chunk; and
generating a weighted average chunk topic embedding for the respective chunk from the weighted chunk topic embedding for each topic of the plurality of topics for the respective chunk.
5 . The computer-implemented method of claim 1 , wherein extracting the query topic includes extracting a plurality of topics for the query.
6 . The computer-implemented method of claim 5 , wherein generating the weighted query topic embedding includes generating a weighting for each topic of the plurality of topics for the query.
7 . The computer-implemented method of claim 6 , wherein generating the weighted query topic embedding includes:
generating a weighted query topic embedding for each topic; and
generating a weighted average query topic embedding from the weighted query topic embedding for each topic.
8 . A computer program product residing on a non-transitory computer readable medium having a plurality of instructions stored thereon which, when executed by a processor, cause the processor to perform operations comprising:
receiving a query to be processed by a generative artificial intelligence (AI) model;
extracting a query topic from the query;
generating a weighted query topic embedding for the query topic;
generating a plurality of weighted chunk topic embeddings for a plurality of chunks based on a frequency of each term in a particular chunk from a plurality of chunks of a target document and each term's frequency across all of the plurality of chunks;
identifying a candidate chunk from the plurality of chunks by determining a similarity between the weighted query topic embedding and the plurality of weighted chunk topic embeddings for the plurality of chunks;
generating a prompt using the query and the candidate chunk; and
providing the prompt to the generative AI model.
9 . The computer program product of claim 8 , wherein identifying a candidate chunk includes identifying a predefined number of most similar candidate chunks.
10 . The computer program product of claim 8 , wherein the operations further comprise:
generating the plurality of chunks for a plurality of text portions of the target document;
generating a plurality of chunk topics by extracting a topic for each respective chunk of the plurality of chunks; and
generating a weighting for the topic for each respective chunk of the plurality of chunks.
11 . The computer program product of claim 8 , wherein the operations further comprise:
generating a weighted chunk topic embedding for each topic of a plurality of topics for a respective chunk; and
generating a weighted average chunk topic embedding for the respective chunk from the weighted chunk topic embedding for each topic of the plurality of topics for the respective chunk.
12 . The computer program product of claim 8 , wherein extracting the query topic includes extracting a plurality of topics for the query.
13 . The computer program product of claim 12 , wherein generating the weighted query topic embedding includes generating a weighting for each topic of the plurality of topics for the query.
14 . The computer program product of claim 13 , wherein generating the weighted query topic embedding includes:
generating a weighted query topic embedding for each topic; and
generating a weighted average query topic embedding from the weighted query topic embedding for each topic.
15 . A computing system comprising:
a memory; and
a processor configured to:
receive a query to be processed by a generative artificial intelligence (AI) model,
extract a query topic from the query,
generate a weighted query topic embedding for the query topic,
generate a plurality of weighted chunk topic embeddings for a plurality of chunks based on a frequency of each term in a particular chunk from a plurality of chunks of a target document and each term's frequency across all of the plurality of chunks,
identify a candidate chunk from the plurality of chunks by determining a similarity between the weighted query topic embedding and the plurality of weighted chunk topic embeddings for the plurality of chunks,
generate a prompt using the query and the candidate chunk, and
provide the prompt to the generative AI model.
16 . The computing system of claim 15 , wherein identifying a candidate chunk includes identifying a predefined number of most similar candidate chunks.
17 . The computing system of claim 15 , wherein the processor is further configured to:
generate the plurality of chunks for a plurality of text portions of the target document;
generate a plurality of chunk topics by extracting a topic for each respective chunk of the plurality of chunks; and
generate a weighting for the topic for each respective chunk of the plurality of chunks.
18 . The computing system of claim 17 , wherein the processor is further configured to:
generate a weighted chunk topic embedding for each topic of a plurality of topics for a respective chunk; and
generate a weighted average chunk topic embedding for the respective chunk from the weighted chunk topic embedding for each topic of the plurality of topics for the respective chunk.
19 . The computing system of claim 15 , wherein extracting the topic includes extracting a plurality of topics for the query.
20 . The computing system of claim 19 , wherein generating the weighting for the topic includes generating a weighting for each topic of the plurality of topics for the query.