Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] StringKnowledgeSource Embedding Function Fails with Ollama nomic-embed-text -- defaults to openai-- #1847

Open
Ricram2 opened this issue Jan 4, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@Ricram2
Copy link

Ricram2 commented Jan 4, 2025

Description

The application fails to initialize the embedding function when using Ollama with the nomic-embed-text model or defaults incorrectly to OpenAI, leading to a ValueError for a missing OpenAI API key. This behavior is unexpected, as the specified provider is Ollama, not OpenAI.

Steps to Reproduce

  1. Follow the tutorial here
  2. try it with Ollama embedding models

from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource

crew = Crew(
    agents=[agent],
    tasks=[task],
    verbose=True,
    process=Process.sequential,
    knowledge_sources=[string_source],
    embedder={
        "provider": "ollama",
        "config": {
            "model": "nomic-embed-text",
        }
    }
)

Expected behavior

The application should initialize the embedding function using the specified ollama provider with the nomic-embed-text model, or provide a meaningful error related to Ollama if something is misconfigured. It should not attempt to fall back to OpenAI.

Screenshots/Code snippets

    from tax_crew.main import run
File "/path/to/project/src/tax_crew/main.py", line 5, in <module>
    from tax_crew.crew import TaxCrew
File "/path/to/project/src/tax_crew/crew.py", line 6, in <module>
    string_source = StringKnowledgeSource(
                    ^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.11/site-packages/pydantic/main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.11/site-packages/crewai/knowledge/storage/knowledge_storage.py", line 51, in __init__
    self._set_embedder_config(embedder_config)
File "/path/to/venv/lib/python3.11/site-packages/crewai/knowledge/storage/knowledge_storage.py", line 174, in _set_embedder_config
    else self._create_default_embedding_function()
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.11/site-packages/crewai/knowledge/storage/knowledge_storage.py", line 158, in _create_default_embedding_function
    return OpenAIEmbeddingFunction(
           ^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.11/site-packages/chromadb/utils/embedding_functions/openai_embedding_function.py", line 56, in __init__
    raise ValueError(
ValueError: Please provide an OpenAI API key. You can get one at https://platform.openai.com/account/api-keys

Operating System

macOS Sonoma

Python Version

3.11

crewAI Version

0.86.0

crewAI Tools Version

0.25.8

Virtual Environment

Venv

Evidence

    from tax_crew.main import run
File "/path/to/project/src/tax_crew/main.py", line 5, in <module>
    from tax_crew.crew import TaxCrew
File "/path/to/project/src/tax_crew/crew.py", line 6, in <module>
    string_source = StringKnowledgeSource(
                    ^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.11/site-packages/pydantic/main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.11/site-packages/crewai/knowledge/storage/knowledge_storage.py", line 51, in __init__
    self._set_embedder_config(embedder_config)
File "/path/to/venv/lib/python3.11/site-packages/crewai/knowledge/storage/knowledge_storage.py", line 174, in _set_embedder_config
    else self._create_default_embedding_function()
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.11/site-packages/crewai/knowledge/storage/knowledge_storage.py", line 158, in _create_default_embedding_function
    return OpenAIEmbeddingFunction(
           ^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.11/site-packages/chromadb/utils/embedding_functions/openai_embedding_function.py", line 56, in __init__
    raise ValueError(
ValueError: Please provide an OpenAI API key. You can get one at https://platform.openai.com/account/api-keys

Possible Solution

• Ensure that the application respects the specified provider (ollama) and does not fall back to OpenAI unless explicitly configured.
• Validate the configuration early and provide meaningful error messages for unsupported providers or missing configurations.

Additional context

It can be happening with other providers that are not ollama

@Ricram2 Ricram2 added the bug Something isn't working label Jan 4, 2025
@Ricram2
Copy link
Author

Ricram2 commented Jan 4, 2025

There is a whole discussion about it here:

https://community.crewai.com/t/string-knowledge-sources-not-working-with-gemini/2057/35

@mtcolman
Copy link

mtcolman commented Jan 5, 2025

I think #1804 fixes this, I believe it's been merged to main, but not released yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants