crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] VertexAI Embeddings used as memory embeddings errors

Open anifort opened this issue 1 year ago • 4 comments

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 validate_model 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 avatar Aug 19 '24 16:08 anifort

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

anifort avatar Aug 19 '24 16:08 anifort

monitoring the PR for now

theCyberTech avatar Aug 20 '24 04:08 theCyberTech

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] avatar Sep 19 '24 12:09 github-actions[bot]

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

anifort avatar Sep 19 '24 15:09 anifort

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] avatar Oct 21 '24 12:10 github-actions[bot]

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

anifort avatar Oct 22 '24 16:10 anifort

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] avatar Nov 22 '24 12:11 github-actions[bot]

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

github-actions[bot] avatar Nov 27 '24 12:11 github-actions[bot]