mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 16:18:30 +00:00
Some checks failed
Notify Downstream / notify-downstream (push) Has been cancelled
Update Test Durations / update-durations (3.10) (push) Has been cancelled
Update Test Durations / update-durations (3.11) (push) Has been cancelled
Update Test Durations / update-durations (3.12) (push) Has been cancelled
Update Test Durations / update-durations (3.13) (push) Has been cancelled
Build uv cache / build-cache (3.10) (push) Has been cancelled
Build uv cache / build-cache (3.11) (push) Has been cancelled
Build uv cache / build-cache (3.12) (push) Has been cancelled
Build uv cache / build-cache (3.13) (push) Has been cancelled
- ignore line length errors globally - migrate knowledge/memory and crew query_knowledge to `SearchResult` - remove legacy chromadb utils; fix empty metadata handling - restore openai as default embedding provider; support instance-specific clients - update and fix tests for `SearchResult` migration and rag changes
66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
"""ChromaDB configuration model."""
|
|
|
|
import warnings
|
|
from dataclasses import field
|
|
from typing import Literal, cast
|
|
|
|
from chromadb.config import Settings
|
|
from chromadb.utils.embedding_functions import DefaultEmbeddingFunction
|
|
from pydantic.dataclasses import dataclass as pyd_dataclass
|
|
|
|
from crewai.rag.chromadb.constants import (
|
|
DEFAULT_DATABASE,
|
|
DEFAULT_STORAGE_PATH,
|
|
DEFAULT_TENANT,
|
|
)
|
|
from crewai.rag.chromadb.types import ChromaEmbeddingFunctionWrapper
|
|
from crewai.rag.config.base import BaseRagConfig
|
|
|
|
warnings.filterwarnings(
|
|
"ignore",
|
|
message=".*Mixing V1 models and V2 models.*",
|
|
category=UserWarning,
|
|
module="pydantic._internal._generate_schema",
|
|
)
|
|
|
|
warnings.filterwarnings(
|
|
"ignore",
|
|
message=r".*'model_fields'.*is deprecated.*",
|
|
module=r"^chromadb(\.|$)",
|
|
)
|
|
|
|
|
|
def _default_settings() -> Settings:
|
|
"""Create default ChromaDB settings.
|
|
|
|
Returns:
|
|
Settings with persistent storage and reset enabled.
|
|
"""
|
|
return Settings(
|
|
persist_directory=DEFAULT_STORAGE_PATH,
|
|
allow_reset=True,
|
|
is_persistent=True,
|
|
)
|
|
|
|
|
|
def _default_embedding_function() -> ChromaEmbeddingFunctionWrapper:
|
|
"""Create default ChromaDB embedding function.
|
|
|
|
Returns:
|
|
Default embedding function using all-MiniLM-L6-v2 via ONNX.
|
|
"""
|
|
return cast(ChromaEmbeddingFunctionWrapper, DefaultEmbeddingFunction())
|
|
|
|
|
|
@pyd_dataclass(frozen=True)
|
|
class ChromaDBConfig(BaseRagConfig):
|
|
"""Configuration for ChromaDB client."""
|
|
|
|
provider: Literal["chromadb"] = field(default="chromadb", init=False)
|
|
tenant: str = DEFAULT_TENANT
|
|
database: str = DEFAULT_DATABASE
|
|
settings: Settings = field(default_factory=_default_settings)
|
|
embedding_function: ChromaEmbeddingFunctionWrapper = field(
|
|
default_factory=_default_embedding_function
|
|
)
|