chroma

Chroma 向量数据库

补充说明

Chroma 是轻量级向量数据库,API 简单,适合本地 RAG 原型和中小规模知识库。支持内存、持久化和客户端/服务端模式。

常用示例

安装并启动服务端:

pip install chromadb
chroma run --host 0.0.0.0 --port 8000 --path ./chroma-data

Python 客户端:

import chromadb

client = chromadb.HttpClient(host="localhost", port=8000)
collection = client.get_or_create_collection("docs")
collection.add(
    ids=["1", "2"],
    documents=["如何排查磁盘满", "如何查看端口占用"],
    metadatas=[{"source": "faq"}, {"source": "faq"}],
)
result = collection.query(query_texts=["磁盘"], n_results=3)
print(result)

按元数据过滤:

collection.query(
    query_texts=["磁盘"],
    n_results=3,
    where={"source": "faq"},
)

删除集合:

client.delete_collection("docs")

易错点与排错