[BUG] Custom embedder crashes Knowledge on ChromaDB: CustomEmbeddingFunction has no name()

未关闭
#9,841 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@Mriks42 已经在做这个了。

开始于 2026年11月26日。

  • #9842 来自 @Mriks42 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

Start with crewai/rag/embeddings/providers/custom/embedding_callable.py and compare CustomEmbeddingFunction with the crewAI embedding functions that define name() for ChromaDB compatibility. Reproduce with the supplied script and ChromaDB 1.5.9; done means knowledge.add_sources() succeeds with the custom embedder on ChromaDB. A linked pull request (#9842) is already open.

由索引模型根据 Issue 内容生成。

描述

bug
Description

Knowledge with a custom embedder (provider: "custom") fails on the ChromaDB backend with AttributeError: '<cls>' object has no attribute 'name' when sources are added. ChromaDB 1.x calls embedding_function.name() in get_or_create_collection. crewAI's own embedding functions define it (OpenAIEmbeddingFunction.name() is documented "for ChromaDB compatibility"; voyageai, ibm and oracle do too), but CustomEmbeddingFunction does not, and because crewAI's EmbeddingFunction is its own Protocol it does not inherit ChromaDB's fallback either. The same embedder works on the default Qdrant backend, so this hits anyone who opts in to ChromaDB with set_rag_config(ChromaDBConfig(...)), as the Knowledge docs describe for sharing a store across processes.

Steps to Reproduce
  1. uv sync --all-groups --all-extras (chromadb 1.5.9 from uv.lock).
  2. Save the script under "Screenshots/Code snippets" as repro.py.
  3. uv run python repro.py
  4. See AttributeError: 'MyEmbedding' object has no attribute 'name'.
  5. Comment out the set_rag_config(...) line (default Qdrant backend) and run again: it prints ok.
Expected behavior

knowledge.add_sources() succeeds on ChromaDB with a CustomEmbeddingFunction subclass, the same as it does on Qdrant.

Screenshots/Code snippets
import os
import tempfile

os.environ["CREWAI_STORAGE_DIR"] = tempfile.mkdtemp()  # fresh store

from crewai.knowledge.knowledge import Knowledge
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource
from crewai.rag.chromadb.config import ChromaDBConfig
from crewai.rag.config.utils import set_rag_config
from crewai.rag.embeddings.providers.custom.embedding_callable import (
    CustomEmbeddingFunction,
)


class MyEmbedding(CustomEmbeddingFunction):
    def __call__(self, input: list[str]) -> list[list[float]]:
        return [[float(len(doc)), 1.0, 0.0] for doc in input]


# Opt in to ChromaDB as docs/edge/en/concepts/knowledge.mdx describes.
# Comment this line out (default Qdrant backend) and the script succeeds.
set_rag_config(ChromaDBConfig(embedding_function=MyEmbedding()))

knowledge = Knowledge(
    collection_name="demo",
    sources=[StringKnowledgeSource(content="Chroma stores embeddings.")],
    embedder={"provider": "custom", "config": {"embedding_callable": MyEmbedding}},
)
knowledge.add_sources()
print("ok")
Operating System

Other (specify in additional context)

Python Version

3.12

crewAI Version

1.15.45 (main @ 77237aec)

crewAI Tools Version

1.15.45

Virtual Environment

Venv

Evidence

Traceback (paths shortened):

Traceback (most recent call last):
  File "repro.py", line 29, in <module>
  File ".../crewai/knowledge/knowledge.py", line 158, in add_sources
  File ".../crewai/knowledge/source/string_knowledge_source.py", line 28, in add
  File ".../crewai/knowledge/source/base_knowledge_source.py", line 69, in _save_documents
  File ".../crewai/knowledge/storage/knowledge_storage.py", line 174, in save
  File ".../crewai/rag/chromadb/client.py", line 247, in get_or_create_collection
  File ".../chromadb/api/client.py", line 372, in get_or_create_collection
  File ".../chromadb/api/collection_configuration.py", line 791, in validate_embedding_function_conflict_on_get
AttributeError: 'MyEmbedding' object has no attribute 'name'

Same result on Python 3.13.15. With the default Qdrant backend the script prints ok.

Possible Solution

Define name() on CustomEmbeddingFunction, as the other crewAI embedding functions do. This is the same class of bug as #3597 (WatsonEmbeddingFunction), which was fixed in 73e932bfe; CustomEmbeddingFunction was not part of that change. I'd like to open a PR for this.

Additional context
  • OS: macOS 26.6. Python 3.12.14 and 3.13.15, chromadb 1.5.9, environment from the repo's uv.lock (uv-managed venv).
  • Related, separate issue (not part of this report): the custom-embedder example in docs/edge/en/tools/ai-ml/ragtool.mdx subclasses crewai.rag.core.base_embeddings_callable.EmbeddingFunction and documents embedding_callable (type[EmbeddingFunction]), but CustomProvider.embedding_callable is typed type[CustomEmbeddingFunction], so that class is rejected with Input should be a subclass of CustomEmbeddingFunction (in both RagTool and Knowledge).

Prepared with Claude Code assistance. Could a maintainer please add the llm-generated label?

主要语言
Python
星标
61.2k
派生
9.2k
平均合并
1 天 14 小时
30 天内合并 PR
180

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

crewAIInc/crewAI 的其他 Issue

查看 crewAIInc/crewAI 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。