crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] LanceDB scoped record counts stop at 50,000 memories

Open remote-controlled-man opened this issue 2 weeks ago • 2 comments

Description

LanceDBStorage.count(scope_prefix) and get_scope_info(scope).record_count stop at 50,000 records even when the scope contains more memories. The unscoped count returns the real total, so the two views disagree. Memory.info() and Memory.tree() use the same scope-info count.

Steps to Reproduce

Run the following against main at 7e4efa91c57a02646c9e7b7b7355d149f0783126. It uses a temporary local LanceDB database, without an LLM, API key, or external service.

from tempfile import TemporaryDirectory
from crewai.memory.storage.lancedb_storage import LanceDBStorage
from crewai.memory.types import MemoryRecord

with TemporaryDirectory() as directory:
    storage = LanceDBStorage(path=directory, vector_dim=2, compact_every=0)
    storage.save([
        MemoryRecord(content="memory", scope="/team", embedding=[1.0, 0.0])
        for _ in range(50_001)
    ])
    print("Global count:", storage.count())
    print("Scoped count:", storage.count("/team"))
    print("Scope info count:", storage.get_scope_info("/team").record_count)

Expected behavior

All three counts are 50,001.

Screenshots/Code snippets

Actual output:

Global count: 50001
Scoped count: 50000
Scope info count: 50000

Operating System

Other: macOS 26.6 arm64

Python Version

3.12.14

crewAI Version

1.15.40 (source main at the commit above)

crewAI Tools Version

Not used by the reproduction.

Virtual Environment

Venv, managed by uv.

Evidence

LanceDB 0.40.0. The standalone script above was run with the pristine baseline storage implementation. A regression with 50,001 records in one scope, split across parent and child scopes, also fails with (50000, 50000) for the two scoped count APIs. Global counting still succeeds.

Possible Solution

Use LanceDB's native filtered count_rows() for scoped counts, and use the same count for ScopeInfo.record_count. Keep the metadata scan cap rather than raising it or loading all matching records into Python.

Additional context

Codex prepared this investigation and the proposed fix. The failure and regression checks ran against a real local LanceDB table. This report concerns numeric record counts; the existing capped metadata summaries and scope-prefix matching semantics are separate behavior.

remote-controlled-man avatar Nov 12 '26 06:11 remote-controlled-man

Hi, I can take this one. I reproduced it on main at 7e4efa91c: with 50,001 records in /team, count() returns 50001, count("/team") returns 50000, and get_scope_info("/team").record_count returns 50000. The scoped path goes through get_scope_info, which counts rows from a scan capped at _SCAN_ROWS_LIMIT, while the global path uses the native count_rows(). I will fix the scoped count to use the native filtered count_rows() with the same scope-prefix predicate, keeping the capped metadata scan for categories and oldest/newest, and add regression tests. If that approach looks right, please assign the issue to me.

Varshith-Kali avatar Nov 12 '26 07:11 Varshith-Kali

Thanks @Varshith-Kali — that matches this report's diagnosis and proposed fix. Native filtered count_rows() should supply both scoped count() and ScopeInfo.record_count, preserving the existing scope normalization and prefix predicate while keeping the metadata scan capped. A regression above 50,000 records split across parent and child scopes, with both scoped APIs and an unscoped control, would pin the discrepancy.

I don't have triage/write permissions in this repository, so I can't assign issues. Could a maintainer assign #9390 to @Varshith-Kali? This report was prepared with Codex; please also apply the required llm-generated label.

remote-controlled-man avatar Nov 12 '26 07:11 remote-controlled-man