介绍一个GO生态的轻量级内存向量数据库chromem-go[1] ,它是专为 Go 语言设计的嵌入式向量数据库,具有 Chroma-like 接口且无第三方依赖。其核心优势包括:
- 零依赖 :无需额外库或服务,简化开发环境。
- 嵌入式设计 :直接集成于 Go 应用,无需独立数据库。
- 高性能 :内存存储,支持可选持久化,查询速度快(Intel Core i5-1135G7/32 GB)上1,000 文档仅需 0.3 ms)。
支持多线程及多种嵌入模型,提供相似性搜索和过滤器功能。当前处于 beta 阶段,未来将优化性能、扩展嵌入模型支持,并增加复杂查询和数据类型。
安装简单:
go get github.com/philippgille/chromem-go@latest
接口与 chromadb 相似
package main
import "github.com/philippgille/chromem-go"
func main() {
// Set up chromem-go in-memory, for easy prototyping. Can add persistence easily!
// We call it DB instead of client because there's no client-server separation. The DB is embedded.
db := chromem.NewDB()
// Create collection. GetCollection, GetOrCreateCollection, DeleteCollection also available!
collection, \_ := db.CreateCollection("all-my-documents", nil, nil)
// Add docs to the collection. Update and delete will be added in the future.
// Can be multi-threaded with AddConcurrently()!
// We're showing the Chroma-like method here, but more Go-idiomatic methods are also available!
_ = collection.Add(ctx,
[]string{"doc1", "doc2"}, // unique ID for each doc
nil, // We handle embedding automatically. You can skip that and add your own embeddings as well.
[]map[string]string{{"source": "notion"}, {"source": "google-docs"}}, // Filter on these!
[]string{"This is document1", "This is document2"},
)
// Query/search 2 most similar results. You can also get by ID.
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
)
}
详细用法见 Godoc[2]。
chromem-go
旨在填补 Go 社区嵌入式向量数据库的空白,它能很好的和ollama,openai等集成,是轻量级 RAG 解决方案的理想选择。
参考资料
[1]
chromem-go
: https://github.com/philippgille/chromem-go
[2] Godoc: https://pkg.go.dev/github.com/philippgille/chromem-go
后台回复“进群”入群讨论