-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Description
Description
Trying to run the getting started code but using external memory with mem0 and valkey fails with
Exception: An error occurred while running the crew: Invalid filter expression: @AND:{[{'user_id': 'bob'}]} @user_id:{bob}. AND is not indexed as a tag field
Steps to Reproduce
follow the instructions in the getting started section: here
then replace crew.py with the following
`from crewai import Agent, Crew, Process, Task, LLM
from crewai.project import CrewBase, agent, crew, task
from crewai.agents.agent_builder.base_agent import BaseAgent
from crewai.tools import tool
from typing import List
from dotenv import load_dotenv
import os
from duckduckgo_search import DDGS
from crewai.memory.external.external_memory import ExternalMemory
@tool("DuckDuckGo Search")
def search_tool(query: str) -> str:
"""Search the web using DuckDuckGo for relevant information."""
ddgs = DDGS()
results = ddgs.text(query, max_results=5)
return str(results)
load_dotenv()
If you want to run a snippet of code before or after the crew starts,
you can use the @before_kickoff and @after_kickoff decorators
https://docs.crewai.com/concepts/crews#example-crew-class-with-decorators
@crewbase
class CrewaiValkeyDemo():
"""CrewaiValkeyDemo crew"""
agents: List[BaseAgent]
tasks: List[Task]
external_memory = ExternalMemory(
embedder_config={
"provider":"mem0",
"config":{
"user_id":"bob",
"local_mem0_config":{
"vector_store": {
"provider":"valkey",
"config": {
"collection_name":"mem0test1",
"valkey_url":"valkey://192.168.5.111:6380",
"embedding_model_dims":1024,
"index_type":"hnsw"
}
},
"llm": {
"provider":"aws_bedrock",
"config": {
"model":"us.anthropic.claude-sonnet-4-20250514-v1:0",
"temperature":0.2,
"max_tokens":2000,
}
},
"embedder": {
"provider":"ollama",
"config": {
"model":"mxbai-embed-large:latest",
"ollama_base_url":"http://192.168.5.111:11434"
}
}
}
}
}
)
llm = LLM(
model=os.getenv('MODEL'),# model in .env is "bedrock/us.anthropic.claude-sonnet-4-20250514-v1:0"
aws_region_name="us-east-2",
aws_profile_name=os.getenv('AWS_PROFILE', 'default') # Uses AWS CLI profile
)
# Learn more about YAML configuration files here:
# Agents: https://docs.crewai.com/concepts/agents#yaml-configuration-recommended
# Tasks: https://docs.crewai.com/concepts/tasks#yaml-configuration-recommended
# If you would like to add tools to your agents, you can learn more about it here:
# https://docs.crewai.com/concepts/agents#agent-tools
@agent
def researcher(self) -> Agent:
return Agent(
config=self.agents_config['researcher'], # type: ignore[index]
verbose=True,
tools=[search_tool],
llm=self.llm
)
@agent
def reporting_analyst(self) -> Agent:
return Agent(
config=self.agents_config['reporting_analyst'], # type: ignore[index]
verbose=True,
llm=self.llm
)
# To learn more about structured task outputs,
# task dependencies, and task callbacks, check out the documentation:
# https://docs.crewai.com/concepts/tasks#overview-of-a-task
@task
def research_task(self) -> Task:
return Task(
config=self.tasks_config['research_task'], # type: ignore[index]
)
@task
def reporting_task(self) -> Task:
return Task(
config=self.tasks_config['reporting_task'], # type: ignore[index]
output_file='report.md'
)
@crew
def crew(self) -> Crew:
"""Creates the CrewaiValkeyDemo crew"""
# To learn how to add knowledge sources to your crew, check out the documentation:
# https://docs.crewai.com/concepts/knowledge#what-is-knowledge
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,
llm=self.llm,
external_memory=self.external_memory
# process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
)
`
run crewai run
Expected behavior
This works if you comment out the external_memory in the crew at the bottom of crew.py - that is the expected behaviour.
Screenshots/Code snippets
see code above
Operating System
Other (specify in additional context)
Python Version
3.11
crewAI Version
1.5.0
crewAI Tools Version
1.5.0
Virtual Environment
Venv
Evidence
➜ crewai run
Running the Crew
Model us.anthropic.claude-sonnet-4-20250514-v1:0 may not be available in region us-west-2
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────── Crew Execution Started ─────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Crew Execution Started │
│ Name: crew │
│ ID: 4d78c68d-336a-4604-a6bf-c75fce88670d │
│ Tool Args: │
│ │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Search failed with query '@and:{[{'user_id': 'bob'}]} @user_id:{bob} =>[KNN 5 @Embedding $vec_param AS vector_score]': Invalid filter expression: @AND:{[{'user_id': 'bob'}]} @user_id:{bob}. AND is not indexed as a tag field
Traceback (most recent call last):
❌ Crew: crew
├── 🧠 Memory Retrieval Started
│ └── 🧠 Sources Used
│ └── ❌ External Memory - Error: Invalid filter expression: @AND:{[{'user_id': 'bob'}]} @user_id:{bob}. AND is not indexed as a tag field
└── 📋 Task: research_task (ID: 543fbd09-116f-4a44-ae7c-3a7efdff32ca)
Assigned to: AI LLMs Senior Data Researcher
Status: ❌ Failed
Possible Solution
None
Additional context
Mac OS Tahoe