Skip to main content
Chroma is an open-source vector database that runs in your Python process or as a server. Its OpenAIEmbeddingFunction accepts an api_base, so Chroma can embed your documents and queries with a SambaStack embedding model. You then answer questions with a SambaNova chat model.
Embeddings are available on SambaStack only. E5-Mistral-7B-Instruct is not available on SambaCloud. See Implement embeddings features.On SambaCloud, you can still use Chroma. Set SAMBANOVA_BASE_URL to https://api.sambanova.ai/v1, leave out embedding_function so Chroma embeds with its built-in local model, and skip the instruction example in step 3. Then answer with a SambaNova chat model as in step 4. The LangChain section needs SambaStack.

Prerequisites

  • A SambaStack instance that serves E5-Mistral-7B-Instruct, plus the instance’s base URL and API key. See API keys and URLs.
  • A chat model on that instance. This guide uses gpt-oss-120b.
  • Python 3.10 or higher.
macOS ships with Python 3.9 and exposes it as python3 rather than python. Check your version with python3 --version. If it is below 3.10, install a supported version with pyenv, uv, or brew install python@3.12 before continuing.

Installation and setup

1

Create a virtual environment

2

Install dependencies

This guide was tested with chromadb 1.5.9 and openai 3.35.1.
3

Set your SambaStack base URL and API key

The base URL must end in /v1.

Embed, store, and query

Run the steps in this section in one Python file or session. Each step uses variables from the steps before it.
1

Create a collection that embeds with SambaNova

Pass api_base and api_key_env_var to Chroma’s OpenAIEmbeddingFunction. api_key_env_var makes Chroma read your SambaNova key instead of the default CHROMA_OPENAI_API_KEY. Do not set api_type. Chroma’s own example sets it to azure for Azure OpenAI, which is not what you want here.
PersistentClient saves the collection to ./chroma-data. Use chromadb.EphemeralClient() to keep everything in memory instead. Chroma defaults to squared L2 distance, so the configuration argument sets cosine distance, which is the usual choice for text embeddings.
2

Add your documents

Chroma calls the embedding function for you, so you pass text and never handle vectors.
3

Query the collection

Lower distance means a closer match. The closest match is doc1, the passage about the SN40L chip, at a cosine distance of about 0.24. The next closest is about 0.36.E5-Mistral-7B-Instruct is an instruction-tuned model. Chroma embeds query_texts as plain text, and this example still ranks the right passage first. To format a query as an instruction, embed it yourself and pass the vector instead:
4

Answer with a SambaNova chat model

Pass the retrieved passages to a chat model as context.
question is the same question you searched with in step 3.The model answers that SambaNova makes the SN40L chip.
5

Delete the collection when you are done

This removes the collection. To delete the stored data too, remove the ./chroma-data folder.

Use Chroma with LangChain

The langchain-chroma package wraps the same database. Install it with the OpenAI embeddings integration:
This guide was tested with langchain-chroma 1.1.0 and langchain-openai 1.7.2. Set check_embedding_ctx_length=False. LangChain otherwise sends token IDs instead of text, and the SambaStack embeddings endpoint rejects them.
The scores are cosine distances, the same as in the direct example. For a persistent store, pass persist_directory="./chroma-data" to Chroma.from_texts.

Additional resources

Chroma documentation

Official guides covering collections, querying, and running Chroma as a server.

Chroma OpenAI embedding function

Reference for OpenAIEmbeddingFunction and its parameters.

LangChain Chroma integration

Reference for the langchain-chroma vector store.

Implement embeddings features

How to use SambaNova embedding models on SambaStack.

Troubleshooting

Chroma raises ValueError: The SAMBANOVA_API_KEY environment variable is not set. when the variable named in api_key_env_var is missing. Export it in the shell you run Python from. If you omit api_key_env_var, Chroma looks for CHROMA_OPENAI_API_KEY instead.
The base URL is missing /v1. Set SAMBANOVA_BASE_URL to your SambaStack base URL followed by /v1.
The key does not match the base URL. Use the key issued for your SambaStack instance.
You did not set model_name, so Chroma requested its default model, text-embedding-ada-002. Set model_name="E5-Mistral-7B-Instruct". If the error names E5-Mistral-7B-Instruct, your SambaStack instance does not serve it, or your key cannot access it. List the models the instance serves with curl -H "Authorization: Bearer $SAMBANOVA_API_KEY" "$SAMBANOVA_BASE_URL/models".
This error comes from the LangChain example. Pass check_embedding_ctx_length=False to OpenAIEmbeddings, as shown above.