Skip to main content
In this quickstart you’ll learn how to build a retrieval-augmented generation (RAG) workflow using Together AI in six quick steps that can be run in under five minutes! You’ll leverage the embedding, reranking, and inference endpoints.

Step 1: Register for an account

First, register for an account to get an API key. Once you’ve registered, set your account’s API key to an environment variable named TOGETHER_API_KEY:
Shell

Step 2: Install your preferred library

Together provides an official library for Python:
Shell
Python

Step 3: Process and chunk the data

You’ll RAG over Paul Graham’s latest essay titled Founder Mode. The code below will scrape and load the essay into memory.
Python
Chunk the essay:
Python

Step 4: Generate vector index and perform retrieval

You’ll now use multilingual-e5-large-instruct to embed the augmented chunks above into a vector index.
Python
The function below will help you perform vector search:
Python
You now have a way to retrieve from the vector index given a query.

Step 5: Rerank to improve quality

You’ll use a reranker model to improve retrieved chunk relevance quality:
Rerank models like Mxbai-Rerank-Large-V2 are only available with dedicated model inference. You can bring up a dedicated endpoint to use reranking in your applications.
Python

Step 6: Call generative model

You’ll pass the final three concatenated chunks into an LLM to get the final answer.
Python
If you want to learn more about how to best use open models refer to the docs here!