IP Library Granted Patent US 12,632,489
Granted Patent B1
US 12,632,489 · App. 19/007,679 · Granted May 19, 2026

Generation of context for a question submitted to a generative language machine learning model

Inventors: Joseph Raby (Long Beach, CA); Diane McPhee (Huntington Beach, CA); Haibing Qiao (Irvine, CA)
Assignee: International Business Machines Corporation
G06F16/383G06F40/35
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12,632,489
App. No.
19/007,679
Granted
May 19, 2026
Kind
B1
Abstract

A method, computer program product, and computer system. An embedding model is applied to a question to generate a question embedding. The question is to be submitted with context to a trained generative language machine learning model. N documents for inferring the context are a subset of a corpus of C documents that was divided into chunks and associated chunk embeddings. A document tracking database is queried to select M unallowed documents due to lack of access permission. A nearest neighbor (NN) search algorithm is determined to be a K-Nearest Neighbor (KNN) or an Approximate Nearest Neighbor (ANN) search algorithm. An ordered list of ranked chunk embeddings, which is generated by executing the NN search algorithm to match the question embedding to a subset of the chunk embeddings, does not include the chuck embeddings of: the M unallowed documents and the C documents exclusive of the N documents.

Claims (56)

1 . A method, the method comprising:

applying an embedding model to a question to generate a question embedding associated with the question, the question having been received from a user, the question configured to be submitted with associated context to a trained generative language machine learning model;

receiving a specification of N documents from which the context may be inferred, the N documents being a subset of a corpus of C documents that was divided into chunks and chunk embeddings respectively associated with the chunks, wherein 1<N≤C, wherein the chunk embeddings of the C documents are stored in a vector database, and wherein U unused documents consist of the C documents exclusive of the N documents;

querying a document tracking database to select, from the N documents which are referenced in the document tracking database, M unallowed documents to which the user does not have access permission, wherein 0≤M<N;

determining whether N is less than a number-of-documents threshold (N th ), and if so then determining that a nearest neighbor (NN) search algorithm is a K-Nearest Neighbor (KNN) search algorithm, and if not then determining that the NN search algorithm is an Approximate Nearest Neighbor (ANN) search algorithm; and

generating an ordered list of ranked chunk embeddings, the generating the ordered list comprising performing a NN search using the NN search algorithm to match the question embedding to a subset of the chunk embeddings of the C documents in the vector database, wherein the generated ordered list of ranked chuck embeddings does not include the chunk embeddings of the U unused documents and the chuck embeddings of the M unallowed documents.

2 . The method of claim 1 , the method further comprising:

determining, from the chunks associated with the ranked chunk embeddings, the context associated with the question;

formatting, from the question and the context, a prompt; and

executing the trained generative language machine learning model using the prompt as input, and receiving, from the trained generative language machine learning model, an answer to the prompt.

3 . The method of claim 1 , wherein N<N th , wherein R documents consist of the N documents exclusive of the M unallowed documents, and wherein the performing the NN search comprises performing the KNN search by applying the KNN search algorithm to perform the KNN search to match the question embedding to the chunk embeddings of the R documents in the vector database.

4 . The method of claim 3 , wherein the method comprises:

querying the document tracking database to identify multiple versions of same documents of the N documents having different release dates, wherein the generated ordered list of ranked chunk embeddings does not include non-current chunk embeddings which encompass chunk embeddings of any non-current release version of any same document, and wherein the non-current chunk embeddings are excluded from the KNN search.

5 . The method of claim 3 , wherein N<C.

6 . The method of claim 3 , wherein N═C.

7 . The method of claim 1 , wherein N≥N th , and wherein the performing the NN search comprises:

performing an ANN search by applying the ANN search algorithm to perform the ANN search to match the question embedding to the chunk embeddings of the C documents in the vector database; and

after the performing the ANN search, removing, from the ordered list of ranked chunk embeddings, the chunk embeddings of the U unused documents and the chunk embeddings of the M unallowed documents.

8 . The method of claim 7 , wherein the method comprises:

querying the document tracking database to identify multiple versions of same documents of the N documents having different release dates; and

after the performing the ANN search and the querying the document tracking database, removing, from the ordered list of ranked chunk embeddings, non-current chunk embeddings which are chunk embeddings of any non-current release version of any same document.

9 . The method of claim 7 , wherein N<C.

10 . The method of claim 7 , wherein N═C.

11 . A computer program product, comprising one or more computer readable storage media storing computer readable program instructions, the program instructions executable by one or more processors of a computer system to cause the computer system to perform operations, the operations comprising:

applying an embedding model to a question to generate a question embedding associated with the question, the question having been received from a user, the question configured to be submitted with associated context to a trained generative language machine learning model;

receiving a specification of N documents from which the context may be inferred, the N documents being a subset of a corpus of C documents that was divided into chunks and chunk embeddings respectively associated with the chunks, wherein 1<N≤C, wherein the chunk embeddings of the C documents are stored in a vector database, and wherein U unused documents consist of the C documents exclusive of the N documents;

querying a document tracking database to select, from the N documents which are referenced in the document tracking database, M unallowed documents to which the user does not have access permission, wherein 0≤M<N;

determining whether N is less than a number-of-documents threshold (N th ), and if so then determining that a nearest neighbor (NN) search algorithm is a K-Nearest Neighbor (KNN) search algorithm, and if not then determining that the NN search algorithm is an Approximate Nearest Neighbor (ANN) search algorithm; and

generating an ordered list of ranked chunk embeddings, the generating the ordered list comprising performing a NN search using the NN search algorithm to match the question embedding to a subset of the chunk embeddings of the C documents in the vector database, wherein the generated ordered list of ranked chuck embeddings does not include the chunk embeddings of the U unused documents and the chuck embeddings of the M unallowed documents.

12 . The computer program product of claim 11 , the operations further comprising:

determining, from the chunks associated with the ranked chunk embeddings, the context associated with the question;

formatting, from the question and the context, a prompt; and

executing the trained generative language machine learning model using the prompt as input, and receiving, from the trained generative language machine learning model, an answer to the prompt.

13 . The computer program product of claim 11 , wherein N<N th , wherein R documents consist of the N documents exclusive of the M unallowed documents, and wherein the performing the NN search comprises performing the KNN search by applying the KNN search algorithm to perform the KNN search to match the question embedding to the chunk embeddings of the R documents in the vector database.

14 . The computer program product of claim 13 , wherein the operations further comprise:

querying the document tracking database to identify multiple versions of same documents of the N documents having different release dates, wherein the generated ordered list of ranked chunk embeddings does not include non-current chunk embeddings which encompass chunk embeddings of any non-current release version of any same document, and wherein the non-current chunk embeddings are excluded from the KNN search.

15 . The computer program product of claim 11 , wherein N≥N th , and wherein the performing the NN search comprises:

performing an ANN search by applying the ANN search algorithm to perform the ANN search to match the question embedding to the chunk embeddings of the C documents in the vector database; and

after the performing the ANN search, removing, from the ordered list of ranked chunk embeddings, the chunk embeddings of the U unused documents and the chunk embeddings of the M unallowed documents.

16 . The computer program product of claim 15 , wherein the operations further comprise:

querying the document tracking database to identify multiple versions of same documents of the N documents having different release dates; and

after the performing the ANN search and the querying the document tracking database, removing, from the ordered list of ranked chunk embeddings, non-current chunk embeddings which are chunk embeddings of any non-current release version of any same document.

17 . A computer system, comprising one or more processors, one or more memories, and one or more computer readable storage media, and computer readable program instructions executable by the one or more processors via the one or more memories to cause the computer system to perform operations, the operations comprising:

applying an embedding model to a question to generate a question embedding associated with the question, the question having been received from a user, the question configured to be submitted with associated context to a trained generative language machine learning model;

receiving a specification of N documents from which the context may be inferred, the N documents being a subset of a corpus of C documents that was divided into chunks and chunk embeddings respectively associated with the chunks, wherein 1<N≤C, wherein the chunk embeddings of the C documents are stored in a vector database, and wherein U unused documents consist of the C documents exclusive of the documents;

querying a document tracking database to select, from the N documents which are referenced in the document tracking database, M unallowed documents to which the user does not have access permission, wherein 0≤M<N;

determining whether N is less than a number-of-documents threshold (N th ), and if so then determining that a nearest neighbor (NN) search algorithm is a K-Nearest Neighbor (KNN) search algorithm, and if not then determining that the NN search algorithm is an Approximate Nearest Neighbor (ANN) search algorithm; and

generating an ordered list of ranked chunk embeddings, the generating the ordered list comprising performing a NN search using the NN search algorithm to match the question embedding to a subset of the chunk embeddings of the C documents in the vector database, wherein the generated ordered list of ranked chuck embeddings does not include the chunk embeddings of the U unused documents and the chuck embeddings of the M unallowed documents.

18 . The computer system of claim 17 , the operations further comprising:

determining, from the chunks associated with the ranked chunk embeddings, the context associated with the question;

formatting, from the question and the context, a prompt; and

executing the trained generative language machine learning model using the prompt as input, and receiving, from the trained generative language machine learning model, an answer to the prompt.

19 . The computer system of claim 17 , wherein N<N th , wherein R documents consist of the N documents exclusive of the M unallowed documents, and wherein the performing the NN search comprises performing the KNN search by applying the KNN search algorithm to perform the KNN search to match the question embedding to the chunk embeddings of the R documents in the vector database.

20 . The computer system of claim 17 , wherein N≥N th , and wherein the performing the NN search comprises:

performing an ANN search by applying the ANN search algorithm to perform the ANN search to match the question embedding to the chunk embeddings of the C documents in the vector database; and

after the performing the ANN search, removing, from the ordered list of ranked chunk embeddings, the chunk embeddings of the U unused documents and the chunk embeddings of the M unallowed documents.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Jan 2, 2025
From: RABY, JOSEPH; MCPHEE, DIANE; QIAO, HAIBING
To: INTERNATIONAL BUSINESS MACHINES CORPORATION
Reel/Frame 069717/0175 →
References Cited (21)
US 8645390B1 · Oztekin · 2014 [cited by examiner]
US 11977854B2 · Tunstall-Pedoe et al. · 2024 [cited by applicant]
US 12222898B1 · Madan · 2025 [cited by examiner]
US 12353469B1 · Mahabadi · 2025 [cited by examiner]
US 20230205824A1 · Jablokov · 2023 [cited by examiner]
US 20240078337A1 · Kamyshenko et al. · 2024 [cited by applicant]
US 20240362497A1 · Grenader · 2024 [cited by examiner]
US 20250156458A1 · Lee · 2025 [cited by examiner]
US 20250298798A1 · Kane · 2025 [cited by examiner]
CN 117951274A · 2024 [cited by applicant]
CN 117592489B · 2024 [cited by applicant]
CN 118210908A · 2024 [cited by applicant]
CN 118069815B · 2024 [cited by applicant]
CN 118364087A · 2024 [cited by applicant]
Pregasen, M. How to Optimize Long Prompts with Corpus-In-Context Prompting. Jul. 2024. [online], [retrieved on Oct. 30, 2025]. Retrieved from the Internet <URL: https://www.vellum.ai/blog/how-to-optimize-long-context-pr… [cited by examiner]
Ong, R. Anthropic's Contextual Retrieval: A Guide With Implementation. Nov. 2024. [online] [retrieved on Oct. 31, 2025]. Retrieved from the Internet <URL: https://www.datacamp.com/tutorial/contextual-retrieval-anthropic… [cited by examiner]
Poliakov et al., “Multi-Meta-RAG: Improving RAG for Multi-Hop Queries using Database Filtering with LLM-Extracted Metadata”, arXiv:2406.13213v2 [cs.CL], Aug. 19, 2024, 10 pages. [cited by applicant]
International Searching Authority, “Notification of Transmittal of the International Search Report and the Written Opinion of the International Searching Authority, or Declaration,” Patent Cooperation Treaty, Feb. 20, 2… [cited by applicant]
Jean-Charles Risch, “Securing AI Knowledge: Implementing User Permissions in RAG Systems for Enhanced Data Protection”, Medium, Aug. 19, 2024, 16 pages, doi: https://medium.com/@jcrsch/securing-ai-knowledge-implementing… [cited by applicant]
Luis Angel Pérez Ramos, “LLM Models and RAG Applications Step-by-Step—Part II—Creating the Context”, InterSystems, Oct. 14, 2024, 5 pages, doi: https://community.intersystems.com/post/llm-models-and-rag-applications-ste… [cited by applicant]
Usman Malik, “How to build an authorization system for your RAG applications with LangChain, Chroma DB and Cerbos”, CERBOS, Dec. 20, 2024, 39 pages, doi: https://www.cerbos.dev/blog/authorization-for-rag-applications-la… [cited by applicant]