What this doc covers
- Introduce the OpenAI Exa Wrapper
- Show how to use it to perform RAG in one line of code
Get Started
First install both the Exa and OpenAI librariesShell
Get Exa API Key
Follow this link to get your API key
Python
Exa.wrap method takes your existing OpenAI client and wraps it with Exa-powered RAG capabilities.
Python
Python
Stdout
Motivation
Exa is designed from the ground up to enable seamless, accurate, and performant RAG (Retrieval-Augmented Generation). Exa provides factual, up to date information needed to ground LLM generations. But good RAG requires more than just great search. The client needs to decide when to use RAG, with what queries. They need to handle chunking, prompting, and chaining LLM calls. We provide the Exa OpenAI wrapper that, with one line of code, does all that and turns any OpenAI chat completion into an Exa powered RAG.Python
Advanced Usage
The Exa OpenAI wrapper will intelligently handle calling Exa and providing the relevant web data to the LLM, with good defaults. However, if you need more control, the Exa OpenAI wrapper’schat.completions.create() takes a few extra parameters.
Supporting models
Exa OpenAI wrapper supports any model that supports function calling (https://platform.openai.com/docs/guides/function-calling)Python
Supporting method
Exa OpenAI wrapper only supportschat.completion.create()currently.
Options to include Exa results
You can specifyuse_exa to determine whether to include Exa results for a given request:
autoExa will intelligently determine whether to include resultsrequiredExa results will always be includednoneExa results will never be included
Python
Number of Exa results to fetch
You can set the number of results Exa will fetch (default 3)Python
Maximum character fetched per Exa result
You can set the maximum length of each result Exa returns (default 2048 characters) NOTE: this is measured in characters, not tokensSupport for Exa search parameters
Moreover, the Exa OpenAI wrapper supports any parameters that theexa.search() function accepts:
Wrap up and end-to-end RAG code example
Below is a code block you can copy into any Python script or Jupyter notebook to test out a complete RAG exampleStdout

