Skip to content

Valkey vector store: memory field should use TEXT index type instead of TAG #5006

@cnuthalapati

Description

@cnuthalapati

Summary

The Valkey vector store defines the memory field as a TAG type in the index schema, but it should be TEXT to enable full-text search over memory content.

Current behavior:

# In DEFAULT_FIELDS and _build_index_schema
{"name": "memory", "type": "tag"},  # Using TAG instead of TEXT for Valkey compatibility

The FT.CREATE command uses:

"memory", "TAG"

Problem:

TAG fields are designed for exact-match filtering on categorical values (e.g., user IDs, labels). They tokenize only on comma separators and match whole tokens. This means:

  1. Users cannot do full-text search over stored memories (e.g., searching for memories containing "python" or "meeting notes")
  2. TAG fields with long text content waste memory on oversized inverted index entries since the entire string becomes one token
  3. The filter syntax @memory:{value} only matches exact comma-separated values, not partial text

Proposed fix:

Change the memory field from TAG to TEXT in both DEFAULT_FIELDS and _build_index_schema:

# DEFAULT_FIELDS
{"name": "memory", "type": "text"},

# _build_index_schema cmd
"memory", "TEXT",

Valkey Search (valkey-search module) fully supports TEXT field types with stemming, tokenization, and full-text query syntax. The existing comment "Using TAG instead of TEXT for Valkey compatibility" appears to be outdated since TEXT has been supported since the initial valkey-search release.

This would enable hybrid search patterns combining vector similarity with text filters:

@memory:(meeting notes) =>[KNN 5 @embedding $vec_param AS vector_score]

Note: This is a schema change that requires re-indexing existing data. Consider adding a migration path or documenting that users should drop and recreate their index after upgrading.

Environment

  • valkey.py: mem0/vector_stores/valkey.py
  • Affects: DEFAULT_FIELDS, _build_index_schema()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions