LlamaIndex
Prerequisite
To use LlamaIndex and Cohere, you will need:
- LlamaIndex Package. To install it, run:
pip install llama-index
pip install llama-index-llms-cohere
(to use the Command models)pip install llama-index-embeddings-cohere
(to use the Embed models)pip install llama-index-postprocessor-cohere-rerank
(to use the Rerank models)
- Cohere’s SDK. To install it, run
pip install cohere
. If you run into any issues or want more details on Cohere’s SDK, see this wiki. - A Cohere API Key. For more details on pricing see this page. When you create an account with Cohere, we automatically create a trial API key for you. This key will be available on the dashboard where you can copy it, and it’s in the dashboard section called “API Keys” as well.
Cohere Chat with LlamaIndex
To use Cohere’s chat functionality with LlamaIndex create a Cohere model object and call the chat
function.
PYTHON
Cohere Embeddings with LlamaIndex
To use Cohere’s embeddings with LlamaIndex create a Cohere Embeddings object with an embedding model from this list and call get_text_embedding
.
PYTHON
Cohere Rerank with LlamaIndex
To use Cohere’s rerank functionality with LlamaIndex create a Cohere Rerank object and use as a node post processor.
PYTHON
Cohere RAG with LlamaIndex
The following example uses Cohere’s chat model, embeddings and rerank functionality to generate a response based on your data.
PYTHON
Cohere Tool Use (Function Calling) with LlamaIndex
To use Cohere’s tool use functionality with LlamaIndex, you can use the FunctionTool
class to create a tool that uses Cohere’s API.
PYTHON