Embeddable vector database for Go with Chroma-like interface and zero third-party dependencies. In-memory with optional persistence.
Embeddable vector database for Go with Chroma-like interface and zero third-party dependencies. In-memory with optional persistence.
Embeddable vector database for Go with Chroma-like interface and zero third-party dependencies. In-memory with optional persistence.
Because chromem-go is embeddable it enables you to add retrieval augmented generation (RAG) and similar embeddings-based features into your Go app without having to run a separate database. Like when using SQLite instead of PostgreSQL/MySQL/etc.
It's not a library to connect to Chroma and also not a reimplementation of it in Go. It's a database on its own.
The focus is not scale (millions of documents) or number of features, but simplicity and performance for the most common use cases. On a mid-range 2020 Intel laptop CPU you can query 1,000 documents in 0.3 ms and 100,000 documents in 40 ms, with very few and small memory allocations. See Benchmarks for details.
⚠️ The project is in beta, under heavy construction, and may introduce breaking changes in releases before
v1.0.0. All changes are documented in theCHANGELOG.
With a vector database you can do various things:
Let's look at the RAG use case in more detail:
The knowledge of large language models (LLMs) - even the ones with 30 billion, 70 billion parameters and more - is limited. They don't know anything about what happened after their training ended, they don't know anything about data they were not trained with (like your company's intranet, Jira / bug tracker, wiki or other kinds of knowledge bases), and even the data they do know they often can't reproduce it exactly, but start to hallucinate instead.
Fine-tuning an LLM can help a bit, but it's more meant to improve the LLMs reasoning about specific topics, or reproduce the style of written text or code. Fine-tuning does not add knowledge 1:1 into the model. Details are lost or mixed up. And knowledge cutoff (about anything that happened after the fine-tuning) isn't solved either.
=> A vector database can act as the up-to-date, precise knowledge for LLMs:
text-embedding-3-small.chromem-go can do this for you and supports multiple embedding providers and models out-of-the-box.Check out the example code to see it in action!
Our original inspiration was the Chroma interface, whose core API is the following (taken from their README):
Chroma core interface
…
Our Go library exposes the same interface:
chromem-go equivalent
…
Initially chromem-go started with just the four core methods, but we added more over time. We intentionally don't want to cover 100% of Chroma's API surface though.
We're providing some alternative methods that are more Go-idiomatic instead.
For the full interface see the Godoc:
chromem.EmbeddingFunc)chromem-go create them$contains, $not_containsio.Writer/io.Reader so you can plug S3 buckets and other blob storage, see examples/s3-export-import for example codeEmbeddingFunc that downloads and shells out to llamafile$and, $or etc.)go get github.com/philippgille/chromem-go@latest
See the Godoc for a reference:
For full, working examples, using the vector database for retrieval augmented generation (RAG) and semantic search and using either OpenAI or locally running the embeddings model and LLM (in Ollama), see the example code.
This is taken from the "minimal" example:
…
Output:
ID: 1
Similarity: 0.6833369
Content: The sky is blue because of Rayleigh scattering.
Benchmarked on 2024-03-17 with:
…
go build ./...go test -v -race -count 1 ./...go test -benchmem -run=^$ -bench . (add > bench.out or similar to write to a file)go test -benchmem -run ^$ -cpuprofile cpu.out -bench .-cpuprofile, -memprofile, -blockprofile, -mutexprofile)benchstat: go install golang.org/x/perf/cmd/benchstat@latestbenchstat before.out after.outIn December 2023, when I wanted to play around with retrieval augmented generation (RAG) in a Go program, I looked for a vector database that could be embedded in the Go program, just like you would embed SQLite in order to not require any separate DB setup and maintenance. I was surprised when I didn't find any, given the abundance of embedded key-value stores in the Go ecosystem.
At the time most of the popular vector databases like Pinecone, Qdrant, Milvus, Chroma, Weaviate and others were not embeddable at all or only in Python or JavaScript/TypeScript.
Then I found @eliben's blog post and example code which showed that with very little Go code you could create a very basic PoC of a vector database.
That's when I decided to build my own vector database, embeddable in Go, inspired by the ChromaDB interface. ChromaDB stood out for being embeddable (in Python), and by showing its core API in 4 commands on their README and on the landing page of their website.
No open issues yet, or sync has not completed.