RAG
You can add a knowledge base to your LLM app or agent. A knowledge base is broadly useful for including lots of information in the context — information that is too long to always include in the prompt.
This technique, called Retrieval Augmented Generation (RAG), is a combination of a retriever and a generator. The retriever finds the relevant information from the knowledge base, and the generator uses this information to generate a response. In our case, the generator is an LLM, and as explained below, you can use a vector database through the Galadriel oracle as the retriever.
Before you can call any of the steps above, you need to:
- Extract text from your documents (PDFs, books, websites, etc).
- Upload the chunks to IPFS.
- Request the oracle to index it.
We have provided a script that does this for you — follow the steps in this README; this is a prerequisite for your contract to be able to call the below methods.
After indexing your documents, you should have an IPFS CID representing your knowledge base (the above script provides this).
createKnowledgeBaseQuery
This method makes a call to query the knowledge base. The oracle will return the documents that match the query in the callback: see onOracleKnowledgeBaseQueryResponse
.
Arguments
Identifier which will be passed into the callback.
IPFS CID representing the indexed knowledge base, which will be queried.
The query to be used to retrieve the documents from the knowledge base.
Maximum number of documents to retrieve.
Returns
An internal counter of the oracle, which is incremented on every call.
onOracleKnowledgeBaseQueryResponse
Called when the result of a knowledge base query, created with createKnowledgeBaseQuery
, is ready.
Arguments
The identifier you passed into the createKnowledgeBaseQuery
method.
A list of document contents that were retrieved from the knowledge base.
An error message. Contains an empty string if there was no error, and a description of the error otherwise.