Retrieval-Augmented Generation
Galadriel API provides an embedding endpoint, that can be used for Retrieval-Augmented Generation (RAG)
Retrieval-Augmented Generation (RAG) is a technique in natural language processing that combines retrieval systems with generative models to improve the accuracy and relevance of generated content. It is particularly useful for tasks that require up-to-date or domain-specific knowledge not included in the generative model’s training data.
This example demonstrates how to use the Galadriel API to perform embeddings and LLM inference for question-answering tasks. We will be using Lanchain to load and format a dataset, and ChromaDB, which is an open-source vector database, for storing and querying the embeddings, gotten from the Galadriel API.
First set up the required project requirements
Sign up to get an API key
- Create an account here
- Create an API key on the dashboard
Setup the environment
- create a file called
.env
, and add your API key there, together with the LLM to be used:
- Create a python environment
- Install the required dependencies
Load the variables
First, in our Python file, we must load the environment variables
Create a vector datastore
Next, we can download the dataset and create a vector datastore, which we will be using later for storing our embeddings and querying the relevant context.
Create embeddings
Now we can create embeddings for our dataset and store them in our vector datastore. We can also create embeddings for our search query.
Call the LLM
To call the LLM, we need to format the prompt, so it includes the user query, and the relevant context retrieved from the vector datastore.
You should see something like this, when running the code:
The output of the code also shows the full prompt that was used, which contains the relevant context queried from the datastore!
Conclusion
The above example shows how to build a RAG (Retrieval-Augmented Generation) system using Galadriel, Langchain and ChromaDB. This can be used to build powerful LLM powered systems that have access to real-time data!