{/* Trang này được tạo tự động từ SKILL.md của kỹ năng bởi website/scripts/generate-skill-docs.py. Chỉnh sửa nguồn SKILL.md, không phải trang này. */}
Sắc tố
Cơ sở dữ liệu nhúng mã nguồn mở cho các ứng dụng AI. Lưu trữ các phần nhúng và siêu dữ liệu, thực hiện tìm kiếm vectơ và toàn văn bản, lọc theo siêu dữ liệu. API 4 chức năng đơn giản. Cân từ sổ ghi chép đến cụm sản xuất. Sử dụng để tìm kiếm ngữ nghĩa, ứng dụng RAG hoặc truy xuất tài liệu. Tốt nhất cho các dự án phát triển địa phương và nguồn mở.
Siêu dữ liệu kỹ năng
| Nguồn | Tùy chọn — cài đặt với |
| `Hermes skills install official/mlops/chroma | |
| ` | |
| Đường dẫn |
optional-skills/mlops/chroma ` | | Phiên bản |
1.0.0 ` | | Tác giả | Nghiên cứu dàn nhạc | | Giấy phép | MIT | | Phụ thuộc |
ChromaDB
,
sentence-transformers |
| Nền tảng | Linux, macOS, Windows |
| Thẻ |
RAG
, `Chroma
, `Vector Database
, `Embeddings
, `Semantic Search
, `Open Source
, `Self-Hosted
, `Document Retrieval
,
Metadata Filtering |
Tham khảo: đầy đủ SKILL.md
Sau đây là định nghĩa kỹ năng đầy đủ mà Hermes tải khi kỹ năng này được kích hoạt. Đây là những gì tác nhân coi là hướng dẫn khi kỹ năng được kích hoạt.
Chroma - Cơ sở dữ liệu nhúng mã nguồn mở
Cơ sở dữ liệu gốc AI để xây dựng các ứng dụng LLM bằng bộ nhớ.
Khi nào nên sử dụng Chroma`Sử dụng Chroma khi:
- Xây dựng ứng dụng RAG (retrieval-tăng cường thế hệ)
- Cần cơ sở dữ liệu vector cục bộ/tự lưu trữ
- Muốn có giải pháp nguồn mở (Apache 2.0)
- Tạo mẫu trên sổ tay
- Tìm kiếm ngữ nghĩa trên tài liệu
- Lưu trữ các phần nhúng với siêu dữ liệu`Số liệu:
- 24.300+ sao GitHub
- 1.900+ phuộc
- v1.3.3 (bản phát hành ổn định, hàng tuần)
- Giấy phép Apache 2.0`Thay vào đó hãy sử dụng các lựa chọn thay thế:
- Pinecone: Đám mây được quản lý, tự động mở rộng quy mô
- FAISS: Tìm kiếm tương tự thuần túy, không có siêu dữ liệu
- Weaviate: Cơ sở dữ liệu gốc ML sản xuất
- Qdrant: Hiệu suất cao, dựa trên Rust
Bắt đầu nhanh
Cài đặt
# Python
pip install ChromaDB
# JavaScript/TypeScript
npm install ChromaDB @chroma-core/default-embed
`
### Cách sử dụng cơ bản (Python)
``` python
import ChromaDB
# Create CLIent
CLIent = ChromaDB.CLIent()
# Create collection
collection = CLIent.create_collection(name="my_collection")
# Add documents
collection.add(
documents=["This is document 1", "This is document 2"],
metadatas=[\{"source": "doc1"}, \{"source": "doc2"}],
ids=["id1", "id2"]
)
# Query
results = collection.query(
query_texts=["document about topic"],
n_results=2
)
print(results)
`
``##Hoạt động cốt lõi
### 1. Tạo bộ sưu tập
`Python
# Simple collection
collection = CLIent.create_collection("my_docs")
# With custom embedding function
from ChromaDB.utils import embedding_functions
OpenAI_ef = embedding_functions.OpenAIEmbeddingFunction(
API_key="your-key",
model_name="text-embedding-3-small"
)
collection = CLIent.create_collection(
name="my_docs",
embedding_function=OpenAI_ef
)
# Get existing collection
collection = CLIent.get_collection("my_docs")
# Delete collection
CLIent.delete_collection("my_docs")
`
### 2. Thêm tài liệu
``` python
# Add with auto-generated IDs
collection.add(
documents=["Doc 1", "Doc 2", "Doc 3"],
metadatas=[
\{"source": "web", "category": "tutorial"},
\{"source": "pdf", "page": 5},
\{"source": "API", "timestamp": "2025-01-01"}
],
ids=["id1", "id2", "id3"]
)
# Add with custom embeddings
collection.add(
embeddings=[[0.1, 0.2, ...], [0.3, 0.4, ...]],
documents=["Doc 1", "Doc 2"],
ids=["id1", "id2"]
)
`
### 3. Truy vấn (tìm kiếm tương tự)
``` python
# Basic query
results = collection.query(
query_texts=["machine learning tutorial"],
n_results=5
)
# Query with filters
results = collection.query(
query_texts=["Python programming"],
n_results=3,
where=\{"source": "web"}
)
# Query with metadata filters
results = collection.query(
query_texts=["advanced topics"],
where={
"$and": [
\{"category": "tutorial"},
\{"difficulty": \{"$gte": 3}}
]
}
)
# Access results
print(results["documents"]) # List of matching documents
print(results["metadatas"]) # Metadata for each doc
print(results["distances"]) # Similarity scores
print(results["ids"]) # Document IDs
`
### 4. Nhận tài liệu
``` python
# Get by IDs
docs = collection.get(
ids=["id1", "id2"]
)
# Get with filters
docs = collection.get(
where=\{"category": "tutorial"},
limit=10
)
# Get all documents
docs = collection.get()
`
### 5. Cập nhật tài liệu
``` python
# Update document content
collection.update(
ids=["id1"],
documents=["Updated content"],
metadatas=[\{"source": "updated"}]
)
`
### 6. Xóa tài liệu
``` python
# Delete by IDs
collection.delete(ids=["id1", "id2"])
# Delete with filter
collection.delete(
where=\{"source": "outdated"}
)
`
## Lưu trữ liên tục
``` python
# Persist to disk
CLIent = ChromaDB.PersistentCLIent(path="./chroma_db")
collection = CLIent.create_collection("my_docs")
collection.add(documents=["Doc 1"], ids=["id1"])
# Data persisted automatically
# Reload later with same path
CLIent = ChromaDB.PersistentCLIent(path="./chroma_db")
collection = CLIent.get_collection("my_docs")
`
## Nhúng hàm
### Mặc định (Biến đổi câu)
``` python
# Uses sentence-transformers by default
collection = CLIent.create_collection("my_docs")
# Default model: all-MiniLM-L6-v2
`
### OpenAI
``` python
from ChromaDB.utils import embedding_functions
OpenAI_ef = embedding_functions.OpenAIEmbeddingFunction(
API_key="your-key",
model_name="text-embedding-3-small"
)
collection = CLIent.create_collection(
name="OpenAI_docs",
embedding_function=OpenAI_ef
)
`
### Ôm Mặt
`Python
huggingface_ef = embedding_functions.HuggingFaceEmbeddingFunction(
API_key="your-key",
model_name="sentence-transformers/all-mpnet-base-v2"
)
collection = CLIent.create_collection(
name="hf_docs",
embedding_function=huggingface_ef
)
`
### Chức năng nhúng tùy chỉnh
`Python
from ChromaDB import Documents, EmbeddingFunction, Embeddings`class MyEmbeddingFunction(EmbeddingFunction):
def __call__(self, input: Documents) -> Embeddings:
# Your embedding logic
return embeddings`my_ef = MyEmbeddingFunction()
collection = CLIent.create_collection(
name="custom_docs",
embedding_function=my_ef
)
`
## Lọc siêu dữ liệu
``` python
# Exact match
results = collection.query(
query_texts=["query"],
where=\{"category": "tutorial"}
)
# Comparison operators
results = collection.query(
query_texts=["query"],
where=\{"page": \{"$gt": 10}} # $gt, $gte, $lt, $lte, $ne
)
# Logical operators
results = collection.query(
query_texts=["query"],
where={
"$and": [
\{"category": "tutorial"},
\{"difficulty": \{"$lte": 3}}
]
} # Also: $or
)
# Contains
results = collection.query(
query_texts=["query"],
where=\{"tags": \{"$in": ["Python", "ml"]}}
)
`
## Tích hợp LangChain
``` python
from langchain_chroma import Chroma
from langchain_OpenAI import OpenAIEmbeddings
from langchain.text_splitter import RecursiveCharacterTextSplitter
# Split documents
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000)
docs = text_splitter.split_documents(documents)
# Create Chroma vector store
vectorstore = Chroma.from_documents(
documents=docs,
embedding=OpenAIEmbeddings(),
persist_directory="./chroma_db"
)
# Query
results = vectorstore.similarity_search("machine learning", k=3)
# As retriever
retriever = vectorstore.as_retriever(search_kwargs=\{"k": 5})
`
## Tích hợp LlamaIndex
`Python
from Llama_index.vector_stores.chroma import ChromaVectorStore
from Llama_index.core import VectorStoreIndex, StorageContext
import ChromaDB
# Initialize Chroma
db = ChromaDB.PersistentCLIent(path="./chroma_db")
collection = db.get_or_create_collection("my_collection")
# Create vector store
vector_store = ChromaVectorStore(chroma_collection=collection)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
# Create index
index = VectorStoreIndex.from_documents(
documents,
storage_context=storage_context
)
# Query
query_engine = index.as_query_engine()
response = query_engine.query("What is machine learning?")
`
``##Chế độ máy chủ
`Python
# Run Chroma server
# Terminal: chroma run --path ./chroma_db --port 8000
# Connect to server
import ChromaDB
from ChromaDB.config import Settings
CLIent = ChromaDB.HttpCLIent(
host="localhost",
port=8000,
settings=Settings(anonymiZed_telemetry=False)
)
# Use as normal
collection = CLIent.get_or_create_collection("my_docs")
`
## Các phương pháp hay nhất
1. **Sử dụng ứng dụng khách liên tục** - Không mất dữ liệu khi khởi động lại
2. **Thêm siêu dữ liệu** - Cho phép lọc và theo dõi
3. **Thao tác hàng loạt** - Thêm nhiều tài liệu cùng một lúc
4. **Chọn đúng mô hình nhúng** - Cân bằng tốc độ/chất lượng
5. **Sử dụng bộ lọc** - Thu hẹp không gian tìm kiếm
6. **ID duy nhất** - Tránh va chạm
7. **Sao lưu thường xuyên** - Sao chép thư mục chroma_db
8. **Giám sát kích thước bộ sưu tập** - Mở rộng quy mô nếu cần
9. **Kiểm tra chức năng nhúng** - Đảm bảo chất lượng
10. **Sử dụng chế độ máy chủ để sản xuất** - Tốt hơn cho nhiều người dùng
## Hiệu suất
| Hoạt động | Độ trễ | Ghi chú |
|----------|--------------|-------|
| Thêm 100 tài liệu | ~1-3 giây | Với nhúng |
| Truy vấn (top 10) | ~50-200ms | Phụ thuộc vào kích thước bộ sưu tập |
| Bộ lọc siêu dữ liệu | ~10-50ms | Nhanh chóng với việc lập chỉ mục thích hợp |
## Tài nguyên
- **GitHub**: https://GitHub.com/chroma-core/chroma ⭐ 24.300+
- **Tài liệu**: https://docs.trychroma.com
- **Discord**: https://Discord.gg/MMeYNTmh3x
- **Phiên bản**: 1.3.3+
- **Giấy phép**: Apache 2.0