Build a local document search with Chroma and Python

Chroma is an open-source vector database that runs inside a Python process, so a first document search needs no cloud service. This tutorial takes you from installation to a first query and shows where such a prototype fits in a company.

Niklas Schult4 min read

Illustration: An open drawer with a magnifier over wooden cards and a small sprout in front, standing for a first local search prototype.

What you will have at the end and what you need

At the end you have a small Python script that creates a collection, stores two documents with metadata and returns the most similar ones for a query text. The prototype runs in memory on your own machine. None of the steps below calls a hosted service.

You need a working Python environment with pip and a few sample texts from your own context. The Chroma README describes the core API as four functions, and this article uses three of them: creating a collection, adding documents and querying. The README also offers a hosted product called Chroma Cloud, which this tutorial does not use.

Step 1: Install Chroma

The Python client is published on PyPI as the package chromadb, and one pip command installs it. A virtual environment keeps the dependencies apart from other projects, although the documentation does not require one.

Shell
pip install chromadb

For JavaScript the README names a separate npm package, and for client-server mode it mentions the command chroma run with a --path option. The README shows no further detail on that mode, so this prototype stays with the in-process client.

Step 2: Create a collection and add documents

The following script creates an in-memory client, makes a collection called all-my-documents and adds two documents. Each document gets a metadata entry and a unique id. According to the README, Chroma handles tokenisation, embedding and indexing automatically, and you may supply your own embeddings instead.

Python
import chromadb

# In-memory client, good for a first prototype
client = chromadb.Client()

# Create a collection for the documents
collection = client.create_collection("all-my-documents")

# Add documents, metadata and unique ids
collection.add(
    documents=["This is document1", "This is document2"],
    metadatas=[{"source": "notion"}, {"source": "google-docs"}],
    ids=["doc1", "doc2"],
)

The README also lists get_collection, get_or_create_collection and delete_collection for managing collections, and documents can be updated and deleted as well. In a real prototype the document strings would come from text you have extracted from your own files.

Step 3: Query the collection

A query takes one or more texts and returns the most similar stored documents. The call below asks for the two closest results and prints them. The two commented lines show the optional filters: where restricts results by metadata, and where_document restricts them by a string contained in the text.

Python
results = collection.query(
    query_texts=["This is a query document"],
    n_results=2,
    # where={"source": "notion"},  # optional metadata filter
    # where_document={"$contains": "document1"},  # optional text filter
)
print(results)

Metadata filters become useful once documents come from several places, for example different departments or folders. The README also says you can fetch entries directly by id with get.

Does it work? Checks and typical pitfalls

Run the script and look at the printed result. It should contain the ids and texts of doc1 and doc2, ordered by similarity to your query. If you uncomment the where line, only the document with the matching source value should remain.

  • The client in the README is in-memory. The comment says persistence can be added, but the README shows no code for it, so check the documentation before relying on stored data.
  • Every id must be unique within a collection. Reusing an id from an earlier run is a likely cause of errors.
  • The README calls Chroma a rapidly developing project and says new package versions usually appear on Mondays, so pin the version you tested.

Where the prototype belongs in a company

A script like this suits a test on non-sensitive sample files. Before real documents go in, clarify who operates it, who may read which documents and how long indexed content is kept. A vector index holds the content of the documents in another form, so it falls under the same access rules and, for personal data, under GDPR. A works council (Betriebsrat) may need to be involved if the search could reveal how employees work. See the page on GDPR and AI at work for the usual checks.

A prototype has no permission model, no connectors and no way to cite sources. Those parts take most of the effort in production, and the overview of local AI explains the operating options. If you would rather not build and maintain them, souveraen.ai offers knowledge management software that answers from connected sources with cited sources, hosted in Germany or on-premise. Teams that want to wire their own applications to it can use the developer API.

Sources

More articles

All articles

Using llama-server with curl and Python as a local API

The llama.cpp project ships llama-server, an HTTP server that offers an OpenAI-compatible chat completions route. This tutorial loads a local GGUF model and queries it from curl and Python, so prompts stay on your own machine.

Tutorial4 min

GDPR fines in November 2026 and what they mean for you

In November 2026 European data protection authorities fined companies from social media, banking, energy and dating, with amounts from 675,000 euros to 805 million euros. The cases point to three duties that any company using software or AI with personal data should secure first.

Data protection5 min

AI Act nudification ban: what it means for companies

Since 2 December 2026, the EU AI Act prohibits AI systems that generate non-consensual intimate images of identifiable people and child sexual abuse material. Companies that allow staff to use image generators should check which tools are in use and under what rules.

Regulation4 min

Test it with your own documents.

Free for 3 days, then from €24.90 per user per month. Cancellable monthly.