Skip to content

[BUG] Mem0 (local config) - Memory.search() got an unexpected keyword argument 'metadata' #2599

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

Closed
Jainish-S opened this issue Apr 14, 2025 · 13 comments · Fixed by #2604
Closed
Assignees
Labels
bug Something isn't working

Comments

@Jainish-S
Copy link

Description

I am currently using local mem0 with the following config

local_mem0_config = {
        "vector_store": {
            "provider": "qdrant",
            "config": {
                "collection_name": "user_memory",
                "host": "192.168.0.222",
                "port": 6333,
                "embedding_model_dims": "1536",
            },
        },
        "llm": {
            "provider": "openai",
            "config": {"api_key": os.getenv("OPENAI_API_KEY"), "model": "gpt-4o-mini"},
        },
        "embedder": {
            "provider": "openai",
            "config": {
                "api_key": os.getenv("OPENAI_API_KEY"),
                "model": "text-embedding-3-small",
            },
        },
    }

My crew is defined as this

Crew(
            agents=self.agents,
            tasks=self.tasks,
            process=Process.sequential,
            verbose=True,
            memory=True,
            external_memory=ExternalMemory(
                embedder_config={
                    "provider": "mem0",
                    "config": {
                        "user_id": "jainish",
                        "local_mem0_config": self.local_mem0_config,
                    },
                }
            ),
            output_log_file="logs.json",
        )

The full traceback

Traceback (most recent call last):
  File "/Users/JainishSavalia/work/playground/crewAI/examples/main.py", line 27, in run_crew
    result = crew.kickoff(inputs=inputs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/crew.py", line 646, in kickoff
    result = self._run_sequential_process()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/crew.py", line 758, in _run_sequential_process
    return self._execute_tasks(self.tasks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/crew.py", line 861, in _execute_tasks
    task_output = task.execute_sync(
                  ^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/.venv/lib/python3.11/site-packages/opentelemetry/instrumentation/crewai/instrumentation.py", line 61, in wrapper
    return func(tracer, duration_histogram, token_histogram, wrapped, instance, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/.venv/lib/python3.11/site-packages/opentelemetry/instrumentation/crewai/instrumentation.py", line 149, in wrap_task_execute
    result = wrapped(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/task.py", line 328, in execute_sync
    return self._execute_core(agent, context, tools)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/task.py", line 472, in _execute_core
    raise e  # Re-raise the exception after emitting the event
    ^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/task.py", line 392, in _execute_core
    result = agent.execute_task(
             ^^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/.venv/lib/python3.11/site-packages/opentelemetry/instrumentation/crewai/instrumentation.py", line 61, in wrapper
    return func(tracer, duration_histogram, token_histogram, wrapped, instance, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/.venv/lib/python3.11/site-packages/opentelemetry/instrumentation/crewai/instrumentation.py", line 108, in wrap_agent_execute_task
    result = wrapped(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/agent.py", line 212, in execute_task
    memory = contextual_memory.build_context_for_task(task, context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/memory/contextual/contextual_memory.py", line 46, in build_context_for_task
    context.append(self._fetch_external_context(query))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/memory/contextual/contextual_memory.py", line 130, in _fetch_external_context
    external_memories = self.exm.search(query)
                        ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/memory/memory.py", line 37, in search
    return self.storage.search(
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/memory/storage/mem0_storage.py", line 119, in search
    results = self.memory.search(**params)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Memory.search() got an unexpected keyword argument 'metadata'

The payload of mem0 has changed in v2 compared to v1 but can't find out any major difference as the older version should work as it is ("version": "v1.1" added in config).

Steps to Reproduce

  1. Create any crew which uses external memory with mem0 provider as shown above.
  2. Run the crew.

Expected behavior

The local mem0 search functionality should work as it does with the cloud one.
I am using qdrant for my vector store.

Screenshots/Code snippets

None

Operating System

macOS Sonoma

Python Version

3.11

crewAI Version

0.114.0

crewAI Tools Version

0.40.1

Virtual Environment

Venv

Evidence

Traceback (most recent call last):
File "/Users/JainishSavalia/work/playground/crewAI/examples/main.py", line 27, in run_crew
result = crew.kickoff(inputs=inputs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/crew.py", line 646, in kickoff
result = self._run_sequential_process()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/crew.py", line 758, in _run_sequential_process
return self._execute_tasks(self.tasks)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/crew.py", line 861, in _execute_tasks
task_output = task.execute_sync(
^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/.venv/lib/python3.11/site-packages/opentelemetry/instrumentation/crewai/instrumentation.py", line 61, in wrapper
return func(tracer, duration_histogram, token_histogram, wrapped, instance, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/.venv/lib/python3.11/site-packages/opentelemetry/instrumentation/crewai/instrumentation.py", line 149, in wrap_task_execute
result = wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/task.py", line 328, in execute_sync
return self._execute_core(agent, context, tools)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/task.py", line 472, in _execute_core
raise e # Re-raise the exception after emitting the event
^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/task.py", line 392, in _execute_core
result = agent.execute_task(
^^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/.venv/lib/python3.11/site-packages/opentelemetry/instrumentation/crewai/instrumentation.py", line 61, in wrapper
return func(tracer, duration_histogram, token_histogram, wrapped, instance, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/.venv/lib/python3.11/site-packages/opentelemetry/instrumentation/crewai/instrumentation.py", line 108, in wrap_agent_execute_task
result = wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/agent.py", line 212, in execute_task
memory = contextual_memory.build_context_for_task(task, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/memory/contextual/contextual_memory.py", line 46, in build_context_for_task
context.append(self._fetch_external_context(query))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/memory/contextual/contextual_memory.py", line 130, in _fetch_external_context
external_memories = self.exm.search(query)
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/memory/memory.py", line 37, in search
return self.storage.search(
^^^^^^^^^^^^^^^^^^^^
File "/Users/JainishSavalia/work/playground/crewAI/src/crewai/memory/storage/mem0_storage.py", line 119, in search
results = self.memory.search(**params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Memory.search() got an unexpected keyword argument 'metadata'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/JainishSavalia/work/playground/crewAI/examples/main.py", line 40, in
run_crew()
File "/Users/JainishSavalia/work/playground/crewAI/examples/main.py", line 34, in run_crew
print(f"\nAn error occurred: {e.with_traceback()}")

Possible Solution

None

Additional context

None

@Jainish-S Jainish-S added the bug Something isn't working label Apr 14, 2025
@Vidit-Ostwal
Copy link
Contributor

Hi @Jainish-S,
I think there is one bug associated with the use of local_mem0_config,

This is the issue, #2587. the local config parameter is not being passed currently to the Mem0 class.

@Jainish-S
Copy link
Author

@Vidit-Ostwal Yes I had found it earlier and have fixed it locally.

@Vidit-Ostwal
Copy link
Contributor

@Vidit-Ostwal Yes I had found it earlier and have fixed it locally.

@Jainish-S still the issue is there?

@Jainish-S
Copy link
Author

@Vidit-Ostwal Yes the issue is still persistent when using local mem0, this doesn't arise when using the mem0 cloud provider config

@lucasgomide
Copy link
Contributor

@Jainish-S It happens when you don't set the api_key - I'll work in a solution for it this week

@lucasgomide lucasgomide self-assigned this Apr 14, 2025
@Vidit-Ostwal
Copy link
Contributor

@lucasgomide, is this because MemoryClient and Memory have a different input parameter?

@Vidit-Ostwal
Copy link
Contributor

@lucasgomide If you don't mind, can I pick this up?
I think the solution is quite simple, just took a look at the search method for both Memory and MemoryClient.
and check on the type of object self.memory is?

@lucasgomide
Copy link
Contributor

@lucasgomide If you don't mind, can I pick this up?
I think the solution is quite simple, just took a look at the search method for both Memory and MemoryClient.
and check on the type of object self.memory is?

Sure man, thank u so much..

@lucasgomide
Copy link
Contributor

@Vidit-Ostwal I think this PR handles that, right? #2604

@Vidit-Ostwal
Copy link
Contributor

@Vidit-Ostwal I think this PR handles that, right? #2604

I think so. The author @Dev-Khant, is the maintainer of mem0 itself. I think he pretty much knows what actually the issue is and the best way to resolve that as well.
Thanks for collaborating on this issue.

@Vidit-Ostwal
Copy link
Contributor

@Dev-Khant, can you confirm wether with the changes you have provided the search function will be compatible?

Memory Client has this particular defination of search functionality.
async def search(self, query: str, version: str = "v1", **kwargs) -> List[Dict[str, Any]]:

and Memory has this particular defination of search functionality.
def search(self, query, user_id=None, agent_id=None, run_id=None, limit=100, filters=None):

I think because Memory does not have a **kwargs parameter, that's why it's causing issue with the local mem0 and does not cause any isse with the MemoryClient.

@Dev-Khant
Copy link
Contributor

@Dev-Khant, can you confirm wether with the changes you have provided the search function will be compatible?

Memory Client has this particular defination of search functionality. async def search(self, query: str, version: str = "v1", **kwargs) -> List[Dict[str, Any]]:

and Memory has this particular defination of search functionality. def search(self, query, user_id=None, agent_id=None, run_id=None, limit=100, filters=None):

I think because Memory does not have a **kwargs parameter, that's why it's causing issue with the local mem0 and does not cause any isse with the MemoryClient.

Hey that is correct. The issue was MemoryClient can accept and metadata but the same is not true for OSS Memory. So that PR fixes this issue along with other small problems.

@Vidit-Ostwal
Copy link
Contributor

@Dev-Khant, thanks for the clarification
cc @lucasgomide

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

Successfully merging a pull request may close this issue.

4 participants