# chromem-go

> Embeddable in-memory vector database for Go with a Chroma-like interface

- Category: Retrieval & Knowledge (RAG) / Vector Databases
- Language: Go
- Licence: MPL-2.0
- Repository: https://github.com/philippgille/chromem-go
- Canonical page: https://ai-tldr.dev/tools/chromem-go/

## In short

chromem-go is a vector database written in Go that you embed directly inside your application, the same way you would use SQLite instead of running PostgreSQL or MySQL. It stores documents and their embeddings in memory, with optional persistence, and has zero third-party dependencies. It sits in the Vector Databases category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Go and licensed MPL-2.0.

## Overview

chromem-go is a vector database written in Go that you embed directly inside your application, the same way you would use SQLite instead of running PostgreSQL or MySQL. It stores documents and their embeddings in memory, with optional persistence, and has zero third-party dependencies.

It is aimed at Go developers who want to add retrieval augmented generation (RAG), text and code search, recommendations, or classification to an app without standing up and maintaining a separate database service. Its API mirrors Chroma's core interface, so the create-collection, add, and query flow is familiar, while also offering more Go-idiomatic methods.

Within the embedded / in-process vector database category, chromem-go trades very large scale and a wide feature set for simplicity and good performance on common workloads. The README reports querying 1,000 documents in about 0.3 ms and 100,000 documents in about 40 ms on a mid-range 2020 laptop CPU. Note that it is in beta and may introduce breaking changes before v1.0.0.

## What it does

- Embeddable like SQLite: no client-server model and no separate database to run or maintain
- Chroma-like interface with CreateCollection, GetOrCreateCollection, Add, and Query methods
- Zero dependencies on third-party libraries
- In-memory storage with optional persistence
- Built-in embedding support for multiple providers and models, so you can pass plain text and let it create embeddings (or supply your own)
- Metadata and document-content filters on queries, plus concurrent adds via AddConcurrently

## Getting started

Install the module, then create a database, add documents to a collection, and run a nearest-neighbor query.

1. Install

   Add chromem-go to your Go module.

```bash
go get github.com/philippgille/chromem-go@latest
```

2. Create a DB and collection

   Set up an in-memory database and a collection to hold your documents.

```go
package main

import "github.com/philippgille/chromem-go"

func main() {
    db := chromem.NewDB()
    collection, _ := db.CreateCollection("all-my-documents", nil, nil)
}
```

3. Add documents and query

   Add documents (embeddings are created for you when you pass nil), then query for the most similar results. Optional metadata and content filters are supported.

```go
_ = collection.Add(ctx,
    []string{"doc1", "doc2"}, // unique ID for each doc
    nil,                       // embeddings handled automatically, or supply your own
    []map[string]string{{"source": "notion"}, {"source": "google-docs"}},
    []string{"This is document1", "This is document2"},
)

results, _ := collection.Query(ctx,
    "This is a query document",
    2,
    map[string]string{"metadata_field": "is_equal_to_this"}, // optional filter
    map[string]string{"$contains": "search_string"},          // optional filter
)
```

## When to use it

- Add retrieval augmented generation (RAG) or question answering to a Go app without running a separate vector database service
- Build text or code search over a local document set inside a single binary
- Power recommendation features from embeddings stored in-process
- Run classification or clustering experiments where embedding millions of documents is not required
