Redis Vector Storage Adapter

Note

(December, 2025): The RedisVectorStorageAdapter is new and experimental functionality introduced as a “beta” feature. Its functionality might not yet be fully stable and is subject to change in future releases.

Redis Logo

The RedisVectorStorageAdapter enables advanced semantic similarity search for ChatterBot using Redis® as a vector database. Unlike traditional keyword-based storage adapters, this adapter uses vector embeddings and cosine similarity to understand conversational context and find semantically related responses.

Key Features:

  • Semantic Understanding: Matches responses based on meaning, not just keywords

  • Vector Embeddings: Uses HuggingFace sentence-transformers/all-mpnet-base-v2 model for state-of-the-art text encoding

  • Confidence Scoring: Returns similarity scores (0.0-1.0) based on vector distance for intelligent response ranking

  • Performance Optimized: Automatic NoOpTagger eliminates unnecessary spaCy processing overhead

  • Context-Aware Responses: Finds conversationally appropriate responses even when exact words differ

Vectors are mathematical representations of text (multi-dimensional embeddings) that capture semantic meaning. The adapter calculates similarity between text by measuring the cosine distance between their vector representations, allowing ChatterBot to understand that “How are you?” is similar to “How’s it going?” even with different words.

For example, consider the following words:

        (Speaking)
            ●
           / \
          /   \
(Poetry) ●-----● (Rhyming)
          \   /
           \ /
            ●
        (Writing)

The acts of “speaking” and “writing” are both forms of communication, so they are included in the same cluster, but they are somewhat opposite to each other. Both “poetry” and “rhyming” closely related, and in some cases might possibly be used as synonyms within the context of either types of speech or types of writing.

Redis Setup

Before you use the RedisVectorStorageAdapter you will need to install the dependencies required for Redis and generating vectors. This can be done using the chatterbot[redis] extra when installing ChatterBot. For example:

pip install chatterbot[redis]

You will also need to have a Redis server running, with the additional modules installed that enable searching using vectors. And easy way to run one locally is to use Docker:

docker-compose.yml
services:
  redis:
    # Use the latest version of the redis-stack image
    image: redis/redis-stack-server:latest
    # Expose the default Redis port
    ports:
      - "6379:6379"
    # Persist the Redis data
    volumes:
      - ./.database/redis/:/data

To start the Redis container, run:

docker compose up -d

Likewise, you can run docker compose ps to review the status of your container, and docker compose down to stop it. For more information on Docker and docker compose, see the Docker Compose documentation.

Redis Configuration

To use the RedisVectorStorageAdapter you will need to provide the following argument when configuring your ChatterBot instance:

from chatterbot import ChatBot

chatbot = ChatBot(
      'Redis Bot',
      storage_adapter='chatterbot.storage.RedisVectorStorageAdapter',
      # Optional: Override the default Redis URI
      # database_uri='redis://localhost:6379/0'
)

Storage-Aware Architecture

The Redis adapter automatically configures ChatterBot for optimal performance with vector-based search:

  • Automatic Tagger Selection: Uses NoOpTagger instead of PosLemmaTagger to eliminate spaCy model loading overhead

  • Semantic Vector Search: Automatically selects SemanticVectorSearch algorithm instead of text-based comparison

  • No Manual Configuration: These optimizations are applied automatically when using the Redis adapter

This “storage-aware” design means ChatterBot adapts its processing pipeline based on the storage adapter’s capabilities, ensuring maximum performance and accuracy for vector-based semantic search.

# No need to specify tagger or search algorithm - Redis adapter handles it!
chatbot = ChatBot(
    'Semantic Bot',
    storage_adapter='chatterbot.storage.RedisVectorStorageAdapter'
)
# Automatically uses:
# - NoOpTagger (no spaCy overhead)
# - SemanticVectorSearch (vector similarity)
# - Confidence scores from cosine similarity

Class Attributes

class chatterbot.storage.RedisVectorStorageAdapter(**kwargs)[source]

Warning

BETA feature (Released March, 2025): this storage adapter is new and experimental. Its functionality and default parameters might change in the future and its behavior has not yet been finalized.

The RedisVectorStorageAdapter allows ChatterBot to store conversation data in a redis instance using vector embeddings for semantic similarity search.

All parameters are optional, by default a redis instance on localhost is assumed.

Parameters:

database_uri (str) – eg: redis://localhost:6379/0’, The database_uri can be specified to choose a redis instance.

NOTES: * Unlike other database based storage adapters, the RedisVectorStorageAdapter

does not leverage search_text and search_in_response_to fields for indexing. Instead, it uses vector embeddings to find similar statements based on semantic similarity. This allows for more flexible and context-aware matching.

class RedisMetaDataType[source]

Subclass for redis config metadata type enumerator.

close()[source]

Close the Redis client connection.

count() int[source]

Return the number of entries in the database.

create(text, in_response_to=None, tags=None, **kwargs)[source]

Creates a new statement matching the keyword arguments specified. Returns the created statement.

create_many(statements)[source]

Creates multiple statement entries.

drop()[source]

Remove all existing documents from the database.

filter(page_size=4, **kwargs)[source]

Returns a list of objects from the database. The kwargs parameter can contain any number of attributes. Only objects which contain all listed attributes and in which all values match for all listed attributes will be returned.

kwargs:
  • conversation

  • persona

  • tags

  • in_response_to

  • text

  • exclude_text

  • exclude_text_words

  • persona_not_startswith

  • search_text_contains

  • search_in_response_to_contains

  • order_by

get_preferred_search_algorithm()[source]

Redis uses semantic vector search instead of text-based matching. Returns the name of the SemanticVectorSearch algorithm.

get_preferred_tagger()[source]

Redis uses vector embeddings and doesn’t need POS-lemma indexing. Returns NoOpTagger to avoid unnecessary spaCy processing.

get_random()[source]

Returns a random statement from the database.

get_statement_model()[source]

Return the statement model.

remove(statement)[source]

Removes the statement that matches the input text. Removes any responses from statements where the response text matches the input text.

update(statement)[source]

Modifies an entry in the database. Creates an entry if one does not exist.

Performance Considerations

Vector Embedding Model: By default, the Redis adapter uses sentence-transformers/all-mpnet-base-v2 from HuggingFace:

  • Dimensions: 768-dimensional embeddings

  • Model Size: ~420MB (downloaded once, cached locally)

  • Performance: ~2000 sentences/second on CPU

  • Quality: State-of-the-art semantic similarity (as of 2025)

First-Time Setup: The embedding model downloads automatically on first use:

# First initialization downloads model (~420MB)
chatbot = ChatBot('Bot', storage_adapter='chatterbot.storage.RedisVectorStorageAdapter')
# Subsequent uses load from cache (fast startup)

Memory Usage: Redis vector storage requires more memory than SQL due to embedding storage:

  • Each statement: ~3KB (768 floats × 4 bytes)

  • 10,000 statements: ~30MB vector data

  • Trade-off: Higher memory for better semantic understanding