crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[FEATURE] Add batch query recall (recall_many) to UnifiedMemory with single-call embedding

Open Rohitkanithi opened this issue 2 months ago • 3 comments

Feature Area

Performance optimization

Is your feature request related to a an existing bug? Please link it here.

NA

Describe the solution you'd like

Add a batch recall method Memory.recall_many(queries: list[str], ...) to crewai.memory.UnifiedMemory:

  • Single-Call Batch Embedding: Instead of sequential HTTP requests for each query, embed all query strings simultaneously in a single API call using the embedder's batch API (e.g. _encode_batch(queries)). Every major provider (OpenAI, Gemini, Cohere, Voyage AI, Ollama) natively accepts a list of strings in one request.
  • Concurrent Vector Search: Query the vector storage backend for each embedding in parallel.
  • Unified Cross-Query Deduplication & Ranking: Combine candidate matches across queries, deduplicate by record.id, compute composite scores (semantic, recency, importance), and return the top-ranked list[MemoryMatch].
  • Update RecallMemoryTool: Update RecallMemoryTool._run in crewai/tools/memory_tools.py to use self.memory.recall_many(queries) instead of looping sequentially.

Describe alternatives you've considered

Currently, RecallMemoryTool accepts a list of queries (queries: list[str]), but executes them in a sequential loop:

for query in queries:
    matches = self.memory.recall(query, limit=20)  # Sequential network round-trip each time

For N queries, this incurs N consecutive round-trips to the embedding API. With typical API latency of 250-400ms per request, searching 4 queries takes 1.2-1.6 seconds, during which the agent is blocked waiting for I/O.

Additional context

  • UnifiedMemory already has batch embedding on the write path (_encode_batch() used by remember_many()). Extending this pattern to the read path (recall_many()) brings parity and symmetry to the memory architecture.
  • In multi-query agent workflows, single-call batch embedding cuts memory retrieval latency by 60% to 80%.

Willingness to Contribute

Yes, I'd be happy to submit a pull request

Rohitkanithi avatar Sep 17 '26 05:09 Rohitkanithi

Hi Maintainers, I'd love to work on this feature. I can submit a PR implementing recall_many() on UnifiedMemory, integrating it into RecallMemoryTool, and adding comprehensive unit tests. Could you please assign this issue to me Thanks

Rohitkanithi avatar Sep 17 '26 05:09 Rohitkanithi

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 17 '26 12:10 github-actions[bot]

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

github-actions[bot] avatar Oct 22 '26 12:10 github-actions[bot]