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] Watsonx as embedder is not working - script errors and stops #1790

Open
mtcolman opened this issue Dec 20, 2024 · 1 comment
Open

[BUG] Watsonx as embedder is not working - script errors and stops #1790

mtcolman opened this issue Dec 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mtcolman
Copy link

mtcolman commented Dec 20, 2024

Description

I'm following https://docs.crewai.com/concepts/knowledge#embedder-configuration and it states:

Embedder Configuration
You can also configure the embedder for the knowledge store. This is useful if you want to use a different embedder for the knowledge store than the one used for the agents.

...
string_source = StringKnowledgeSource(
   content="Users name is John. He is 30 years old and lives in San Francisco.",
)
crew = Crew(
   ...
   knowledge_sources=[string_source],
   embedder={
       "provider": "openai",
       "config": {"model": "text-embedding-3-small"},
   },
)

I try running my crew with this configuration (as I want to use Watsonx for embedder):

	@crew
	def crew(self) -> Crew:
		"""Creates the ResearchReport crew"""
		return Crew(
			agents=self.agents,
			tasks=[self.determine_requirement_set()],
			knowledge_sources=[
				StringKnowledgeSource(
					content="User's name is John. He is 30 years old and lives in San Francisco."
				)
			],
			embedder={
				"provider": "watson",
				"config": {
					"model": "ibm/slate-125m-english-rtrvr",
					"api_url": WATSONX_URL,
					"api_key": WATSONX_APIKEY,
					"project_id": WATSONX_PROJECT_ID,
				}
			},
			process=Process.sequential,
			verbose=True,
		)

Which is inline with the guidance given here: https://docs.crewai.com/concepts/memory#using-watson-embeddings.

However it always errors and asks me for the OpenAI API key:

  File "/crewai/.venv/lib/python3.10/site-packages/crewai/project/annotations.py", line 112, in wrapper
    crew = func(self, *args, **kwargs)
  File "/crewai/src/research_report/crew.py", line 246, in crew
    StringKnowledgeSource(
  File "/crewai/.venv/lib/python3.10/site-packages/pydantic/main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
  File "/crewai/.venv/lib/python3.10/site-packages/crewai/knowledge/storage/knowledge_storage.py", line 40, in __init__
    self._initialize_app(embedder_config or {})
  File "/crewai/.venv/lib/python3.10/site-packages/crewai/knowledge/storage/knowledge_storage.py", line 74, in _initialize_app
    self._set_embedder_config(embedder_config)
  File "/crewai/.venv/lib/python3.10/site-packages/crewai/knowledge/storage/knowledge_storage.py", line 131, in _set_embedder_config
    else self._create_default_embedding_function()
  File "/crewai/.venv/lib/python3.10/site-packages/crewai/knowledge/storage/knowledge_storage.py", line 115, in _create_default_embedding_function
    return OpenAIEmbeddingFunction(
  File "/crewai/.venv/lib/python3.10/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

Steps to Reproduce

See previous detail

Expected behavior

I expect Watsonx embedding to be used, and not be asked for openAI API key.

Screenshots/Code snippets

Given in description

Operating System

Ubuntu 22.04

Python Version

3.10

crewAI Version

0.83.0

crewAI Tools Version

0.14.0

Virtual Environment

Venv

Evidence

Given in description

Possible Solution

Correctly use the watsonx embedding.

https://github.com/crewAIInc/crewAI/blob/v0.83.0/src/crewai/knowledge/storage/knowledge_storage.py#L131
https://github.com/crewAIInc/crewAI/blob/v0.83.0/src/crewai/utilities/embedding_configurator.py#L21

Additional context

Might be linked to #1770

If looks like the code tagged as 0.83.0 (https://github.com/crewAIInc/crewAI/blob/v0.83.0/src/crewai/crew.py#L283) is configured for crew to have the knowledge parameter, but not the knowledge_sources parameter

    @model_validator(mode="after")
    def create_crew_knowledge(self) -> "Crew":
        if self.knowledge:
            try:
                self.knowledge = Knowledge(**self.knowledge) if isinstance(self.knowledge, dict) else self.knowledge
            except (TypeError, ValueError) as e:
                raise ValueError(f"Invalid knowledge configuration: {str(e)}")
        return self

however, on the main branch (https://github.com/crewAIInc/crewAI/blob/main/src/crewai/crew.py#L201 and https://github.com/crewAIInc/crewAI/blob/main/src/crewai/crew.py#L282) I can see:

...
    knowledge_sources: Optional[List[BaseKnowledgeSource]] = Field(
        default=None,
        description="Knowledge sources for the crew. Add knowledge sources to the knowledge object.",
    )
...
...
    @model_validator(mode="after")
    def create_crew_knowledge(self) -> "Crew":
        """Create the knowledge for the crew."""
        if self.knowledge_sources:
            try:
                if isinstance(self.knowledge_sources, list) and all(
                    isinstance(k, BaseKnowledgeSource) for k in self.knowledge_sources
                ):
                    self._knowledge = Knowledge(
                        sources=self.knowledge_sources,
                        embedder_config=self.embedder,
                        collection_name="crew",
                    )

            except Exception as e:
                self._logger.log(
                    "warning", f"Failed to init knowledge: {e}", color="yellow"
                )
        return self
@mtcolman mtcolman added the bug Something isn't working label Dec 20, 2024
@mtcolman mtcolman changed the title [BUG] Watsonx as embedder is not working [BUG] Watsonx as embedder is not working - errors on loading Dec 20, 2024
@mtcolman mtcolman changed the title [BUG] Watsonx as embedder is not working - errors on loading [BUG] Watsonx as embedder is not working - script errors and stops Dec 20, 2024
@imrohankataria
Copy link

any solutions?

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