Skip to content

Commit 2f682e1

Browse files
authored
feat: update ChromaDB embedding function to use OpenAI API (#3538)
- Refactor the default embedding function to utilize OpenAI's embedding function with API key support. - Import necessary OpenAI embedding function and configure it with the environment variable for the API key. - Ensure compatibility with existing ChromaDB configuration model.
1 parent d4aa676 commit 2f682e1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/crewai/rag/chromadb/config.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""ChromaDB configuration model."""
22

3+
import os
34
import warnings
45
from dataclasses import field
56
from typing import Literal, cast
67

78
from chromadb.config import Settings
8-
from chromadb.utils.embedding_functions import DefaultEmbeddingFunction
99
from pydantic.dataclasses import dataclass as pyd_dataclass
1010

1111
from crewai.rag.chromadb.constants import (
@@ -49,7 +49,17 @@ def _default_embedding_function() -> ChromaEmbeddingFunctionWrapper:
4949
Returns:
5050
Default embedding function using all-MiniLM-L6-v2 via ONNX.
5151
"""
52-
return cast(ChromaEmbeddingFunctionWrapper, DefaultEmbeddingFunction())
52+
from chromadb.utils.embedding_functions.openai_embedding_function import (
53+
OpenAIEmbeddingFunction,
54+
)
55+
56+
return cast(
57+
ChromaEmbeddingFunctionWrapper,
58+
OpenAIEmbeddingFunction(
59+
api_key=os.getenv("OPENAI_API_KEY"),
60+
model_name="text-embedding-3-small",
61+
),
62+
)
5363

5464

5565
@pyd_dataclass(frozen=True)

0 commit comments

Comments
 (0)