Skip to main content
This article walks you through integrating LlamaIndex by setting up your system, making your first call, querying your own documents, and then trying the example use cases. LlamaIndex is an open source data orchestration framework for building large language model (LLM) applications.

Prerequisites

Before you begin, ensure you have:
  • A SambaCloud account with an active API key. Create the key on the API keys page.
  • Python 3.10 or higher. llama-index-llms-sambanovasystems does not support Python 3.9 or earlier.
  • An embedding model, if you plan to follow Query your own documents. SambaCloud serves chat models, not embeddings, so that section runs a small embedding model on your own machine. You do not need a second provider API key for it.
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.

Setup

Follow the steps below to set up and integrate LlamaIndex:
  1. Create and activate a virtual environment, then confirm the version.
  1. Run the command below to install the llama-index-llms-sambanovasystems integration package and the SSEClient package. The integration package brings in llama-index-core, which supplies everything the examples on this page import from llama_index.core.
  1. Set your SambaCloud API key as an environment variable. The integration reads it automatically.
  1. Make your first call to confirm the integration works.
Always pass model explicitly. SambaNovaCloud defaults to Meta-Llama-3.1-8B-Instruct, which SambaCloud removed on April 14, 2026. Choose a current model ID from SambaCloud models.

Stream a response

sseclient-py from step 2 handles the server-sent events stream. Use stream_complete to print tokens as they arrive instead of waiting for the full response:
You should see the sentence appear a few characters at a time rather than all at once. stream_complete returns a generator of CompletionResponse objects. Each carries the incremental token in delta and the text so far in text.

Query your own documents

The section above uses SambaCloud as a plain chat model. LlamaIndex earns its place when you point it at your own files, so this section loads a document, indexes it, and answers a question from it. A VectorStoreIndex needs two models: a chat model to write the answer, and an embedding model to turn your text into vectors. SambaCloud provides the chat model. It does not provide the embedding model, because embeddings run on SambaStack rather than SambaCloud. If you leave Settings.embed_model unset, LlamaIndex falls back to OpenAI embeddings and the run fails asking for an OPENAI_API_KEY that has nothing to do with SambaNova. The steps below set the embedding model explicitly to a local one, so no second provider key is involved.
  1. Install the local embedding integration.
This package pulls in sentence-transformers and PyTorch, so it is a much larger and slower download than the LLM package. It runs entirely on your machine and needs no API key.
  1. Create a document to query.
  1. Build the index and query it.
You should see an answer drawn from your file, similar to the one below.
Three details are worth knowing before you extend this:
  • Settings is global. Every index and query engine you create afterwards in the same process uses the models you assigned to it, so you set them once rather than threading them through each call.
  • SambaNovaCloud defaults context_window to 4096, well under the 128k that Meta-Llama-3.3-70B-Instruct accepts. Setting it to the model’s real window stops LlamaIndex from trimming retrieved text it did not need to trim. Confirm the window for your model on the SambaCloud models page.
  • SimpleDirectoryReader reads plain text files with no extra packages. To load PDF, DOCX, PPTX, CSV, or Excel files, also install llama-index-readers-file.

Example use cases

The two notebooks below provide information on applying LlamaIndex with SambaCloud in real-world use cases.
  1. Use the Patient Case Summary notebook to build a workflow that processes patient information, compares it against medical standards, and generates summaries for review.
  2. Use the Contract Review notebook to build a compliance system that checks documents against provided regulations and guidelines.

Troubleshooting

macOS does not provide a python executable, only python3. Use python3 -m venv .venv to create the environment. After you activate it with source .venv/bin/activate, python works as expected inside the environment.
SAMBANOVA_API_KEY is not visible to the process. SambaNovaCloud reads it while the object is being constructed, so this fails on the SambaNovaCloud(...) line before any request is sent. Confirm with echo $SAMBANOVA_API_KEY. An export applies only to the shell it ran in, so a new terminal or editor session needs it again.If you would rather set the key in Python than in your shell, assign the environment variable before you construct the client:
Set the key this way rather than passing a sambanova_api_key argument. In llama-index-llms-sambanovasystems 0.6.0, the constructor derives sambanova_url from that same argument, so passing it also replaces the request URL with your key and the call then fails on an invalid URL.
The virtual environment is not active. Run source .venv/bin/activate, confirm the prompt shows (.venv), then re-run the install command.
sseclient-py handles the server-sent events stream and installs separately from the integration package. Confirm it is present with pip show sseclient-py.
The key is set but is not valid. Unlike the missing-key case, this one reaches SambaNova and comes back rejected, so the message arrives as a RuntimeError from the request rather than a ValueError at construction. Copy the key again from the SambaCloud portal.
Your key reached SambaNova and the request itself was rejected. The most common cause is a model value that SambaCloud no longer serves. Check the ID against SambaCloud models and Model deprecations. The text after the status code in the error is the raw API response and names the failing field.
You built an index without setting Settings.embed_model, so LlamaIndex tried its default OpenAI embedding model and could not find that package. This is not a SambaNova error. Set Settings.embed_model as shown in Query your own documents. Do not install the OpenAI package to make the message go away, because the next run then asks for an OpenAI key instead.
The same missing Settings.embed_model as above, seen from an environment where the OpenAI embeddings package is already installed, usually because you installed the llama-index meta package. The fallback got as far as looking for OPENAI_API_KEY. You do not need an OpenAI key. Set Settings.embed_model to a local embedding model instead.
LlamaIndex retrieved nothing to answer from. Confirm that SimpleDirectoryReader actually loaded something with print(len(documents)). A count of 0 means the directory you passed is empty or the path is wrong. If the count is non-zero but the answers are nonsense, you are probably indexing a binary format such as PDF or DOCX that was read as raw bytes. Install llama-index-readers-file so those files get a real parser.
You followed an older LlamaIndex tutorial. ServiceContext was replaced by Settings and now raises on construction. Configure your models through Settings.llm and Settings.embed_model, as shown in Query your own documents.

Additional resources

  • SambaNova LLM integration in the LlamaIndex documentation, for constructor options, chat messages, and async calls.
  • Embedding models in the LlamaIndex documentation, for other embedding options if a local model does not suit you.
  • SambaCloud models for current model IDs and context windows.