Development
Learn how to use Ground API
In this guide, you will use Python with the Ground API to create the following functions:
- upload documents to the RAG
- query against the documents to obtain similarity rankings
- input the similarity ranking into an LLM to get an answer So let’s get started.
You will need an API key from Ground (get it by following the first 3 steps in Quickstart), and an API key from OpenAI.
1. Upload documents
First thing, you’ll need requests to make API calls.
Let’s create a first file, upload_document.py:
You’re able to upload most kind of text documents to Ground.
They will be embedded and saved on our platform.
2. Get the RAG ranking
Now that you can upload files, let’s query information from them!
For this example, let’s use OpenAI (but you can use whatever model you want).
Create a search_documents.py file.
Our first function in this file will use the /search/rrf endpoint from Ground’s API.
It will find matches for your query in the files you uploaded, and return a list of answers.
3. Pass the rankings in OpenAI
Now that Ground did it’s job, and you have a ranked list with results, input this list into ChatGPT 3.5 and let it come up with a nicely formatted answer.
For reference, here is the OpenAI documentation, and get your OpenAI API Key here.
The second function in search_documents.py takes the ranking results from Ground, and pass them to ChatGPT.
ChatGPT will use the rankings to come up with the answer to your question.
The prompt is very basic, asking to use the informations provided by the ranking, and to cite the parent_document_key.
And voila!
That’s the gist of it.
You have a working ChatGPT using the context you provided to it.
You can change the code to use open source, fine tuned, or other models.
Modify and play around with the prompts to get results that fit your needs.
If you have questions feel free to contact us.