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
模型