Chroma安装教程
Chroma
这里讲述的是windows环境
下载Chroma安装包
下载地址:https://github.com/chroma-core/chroma/releases
运行
chroma-windows.exe run --port 8000
通过心跳检测访问是否正常
http://localhost:8000/api/v2/heartbeat
快速使用
python
安装chromadb
python -m pip install chromadb
python代码
import chromadb
from chromadb.config import Settings# 连接到已经启动的 Chroma 服务
client = chromadb.HttpClient(host="localhost",port=8000,settings=Settings(allow_reset=True)
)# 创建一个名为"my_test"的集合
collection = client.create_collection(name="my_test")# 向集合中添加3条简单数据
collection.add(documents=["苹果是一种水果,红色或绿色,味道甜","小狗喜欢啃骨头,很活泼","计算机需要用电才能工作"],ids=["1", "2", "3"] # 给每条数据起个编号
)# 搜索与"哪种水果是甜的?"最像的内容
results = collection.query(query_texts=["哪种水果是甜的?"],n_results=1 # 只返回最像的1条
)# 打印结果
print("找到的答案:", results["documents"][0][0])
结果:
第一次加载会下载all-MiniLM-L6-v2
模型