crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
21.81k stars 3.02k forks source link

[BUG] VertexAI Embeddings used as memory embeddings errors #1213

Closed anifort closed 2 days ago

anifort commented 3 months ago

Description

Using the example from the official documentation (https://docs.crewai.com/core-concepts/Memory/#using-vertex-ai-embeddings) on how to use vertex ai embeddings with memory fails pydantic validation.

Steps to Reproduce

create a crew using the code snippet provided.

Expected behavior

complete a crew task without error

Screenshots/Code snippets

def crew(self) -> Crew:
    """Creates the CrewaiGcp crew"""
    return Crew(
        agents=self.agents,  # Automatically created by the @agent decorator
        tasks=self.tasks,  # Automatically created by the @task decorator
        process=Process.sequential,
        verbose=True,
        share_crew=False,
        memory=True,
        embedder={
            "provider": "vertexai",
            "config": {"model": "textembedding-gecko"},
        },
        # process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
    )

Operating System

macOS Big Sur

Python Version

3.11

crewAI Version

0.51.1

crewAI Tools Version

0.8.3

Virtual Environment

Venv

Evidence

Traceback (most recent call last): File "", line 1, in File "/Users/userx/Projects/my_crew_prj/src/my_crew_prj/main.py", line 24, in run res = CrewaiGcpCrew().crew().kickoff(inputs=inputs) ^^^^^^^^^^^^^^^^^^^^^^ File "/Users/userx/Projects/my_crew_prj/.venv/lib/python3.11/site-packages/crewai/project/annotations.py", line 116, in wrapper return func(self, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/userx/Projects/my_crew_prj/src/my_crew_prj/crew.py", line 54, in crew return Crew( ^^^^^ File "/Users/userx/Projects/my_crew_prj/.venv/lib/python3.11/site-packages/pydantic/main.py", line 193, in init self.pydantic_validator.validate_python(data, self_instance=self) File "/Users/userx/Projects/my_crew_prj/.venv/lib/python3.11/site-packages/crewai/crew.py", line 220, in create_crew_memory self._short_term_memory = ShortTermMemory( ^^^^^^^^^^^^^^^^ File "/Users/userx/Projects/my_crew_prj/.venv/lib/python3.11/site-packages/crewai/memory/short_term/short_term_memory.py", line 17, in init__ storage = RAGStorage( ^^^^^^^^^^^ File "/Users/userx/Projects/my_crew_prj/.venv/lib/python3.11/site-packages/crewai/memory/storage/rag_storage.py", line 76, in init__ self.app = App.from_config(config=config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/userx/Projects/my_crew_prj/.venv/lib/python3.11/site-packages/embedchain/app.py", line 394, in from_config embedding_model = EmbedderFactory.create( ^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/userx/Projects/my_crew_prj/.venv/lib/python3.11/site-packages/embedchain/factory.py", line 86, in create return embedder_class(config=embedder_config_class(config_data)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/userx/Projects/my_crew_prj/.venv/lib/python3.11/site-packages/embedchain/embedder/vertexai.py", line 14, in init embeddings = VertexAIEmbeddings(model_name=config.model) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/userx/Projects/my_crew_prj/.venv/lib/python3.11/site-packages/langchain_core/_api/deprecation.py", line 205, in warn_if_direct_instance return wrapped(self, args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/userx/Projects/my_crew_prj/.venv/lib/python3.11/site-packages/langchain_community/embeddings/vertexai.py", line 66, in init super().init( File "/Users/userx/Projects/my_crew_prj/.venv/lib/python3.11/site-packages/pydantic/v1/main.py", line 339, in init values, fields_set, validation_error = validate_model(__pydantic_self.class__, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/userx/Projects/my_crew_prj/.venv/lib/python3.11/site-packages/pydantic/v1/main.py", line 1074, in validatemodel v, errors = field.validate(value, values, loc=field.alias, cls=cls) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/userx/Projects/my_crew_prj/.venv/lib/python3.11/site-packages/pydantic/v1/fields.py", line 857, in validate raise ConfigError( pydantic.v1.errors.ConfigError: field "client" not yet prepared so type is still a ForwardRef, you might need to call VertexAIEmbeddings.update_forward_refs().

Possible Solution

The problem seems to be in the embedchain==0.1.120 package. this package uses a depricated feature from langchain that is the route of failure. in this package and file .venv/lib/python3.11/site-packages/embedchain/embedder/vertexai.py needs to replace from langchain_community.embeddings import VertexAIEmbeddings with from langchain_google_vertexai import VertexAIEmbeddings

This fixes the problem

(LangChainDeprecationWarning: The class VertexAIEmbeddings was deprecated in LangChain 0.0.12 and will be removed in 0.3.0. An updated version of the class exists in the langchain-google-vertexai package and should be used instead. To use it run pip install -U langchain-google-vertexai and import as from langchain_google_vertexai import VertexAIEmbeddings.)

Additional context

none

anifort commented 3 months ago

added a quick PR for a fix here https://github.com/mem0ai/mem0/pull/1717

theCyberTech commented 3 months ago

monitoring the PR for now

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

anifort commented 2 months ago

PR merge in main but there is no new release yet from mem0 - this is still active

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

anifort commented 1 month ago

this seems to be fixed in mem0 -> https://github.com/mem0ai/mem0/pull/1717

github-actions[bot] commented 1 week ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 2 days ago

This issue was closed because it has been stalled for 5 days with no activity.