Skip to content

API Reference parrot.stores.kb.redis

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.stores.kb.redis

View source

Redis-backed knowledge base primitives.

Alias AbstractKnowledgeBase

Re-exported from parrot.stores.kb.abstract.AbstractKnowledgeBase.

Alias REDIS_HISTORY_URL

Re-exported from parrot.conf.REDIS_HISTORY_URL.

Class RedisKnowledgeBase

Generic Redis-based Knowledge Base with CRUD operations.

Supports both hash storage (HSET/HGET) and simple key-value storage (SET/GET). Provides flexible search, filtering, and data management capabilities.

Parameter Type Default Description
name str Name of the knowledge base
category str Category identifier
namespace str Prefix for Redis keys (e.g., 'user_prefs', 'bot_settings')
redis_url str | None None Redis connection URL
decode_responses bool True
encoding str 'utf-8'
ttl Optional[int] None Default TTL in seconds for keys (None = no expiration)
use_hash_storage bool True Use Redis hashes vs simple key-value
activation_patterns Optional[List[str]] None Patterns that activate this KB
**kwargs Any {} Additional arguments passed to parent

Method RedisKnowledgeBase.should_activate

Default activation strategy based on configured patterns.

should_activate(query: str, context: Dict[str, Any]) -> Tuple[bool, float]

Parameter Type Default Description
query str
context Dict[str, Any]

Returns: Tuple[bool, float]

Method RedisKnowledgeBase.search

Search for entries matching the query.

search(query: str, *, identifier: Optional[str] = None, field_filter: Optional[List[str]] = None, match_fn: Optional[Callable] = None, limit: int = 100, **kwargs: Any) -> List[Dict[str, Any]]

Parameter Type Default Description
query str Search query string
identifier Optional[str] None Specific identifier to search in (optional)
field_filter Optional[List[str]] None Only search in these fields
match_fn Optional[Callable] None Custom matching function(data, query) -> bool
limit int 100 Maximum results to return
**kwargs Any {} Additional filters

Returns: List[Dict[str, Any]] — List of matching entries with metadata

Method RedisKnowledgeBase.list_all

List all entries matching a pattern.

list_all(pattern: Optional[str] = None, limit: int = 1000) -> List[Dict[str, Any]]

Parameter Type Default Description
pattern Optional[str] None Key pattern (uses wildcard if None)
limit int 1000 Maximum results

Returns: List[Dict[str, Any]] — List of all matching entries

Method RedisKnowledgeBase.count

Count entries matching a pattern.

count(pattern: Optional[str] = None) -> int

Parameter Type Default Description
pattern Optional[str] None Key pattern (uses wildcard if None)

Returns: int — Number of matching keys

Method RedisKnowledgeBase.clear_all

Delete all entries matching a pattern.

clear_all(pattern: Optional[str] = None) -> int

Parameter Type Default Description
pattern Optional[str] None Key pattern (uses prefix if None)

Returns: int — Number of keys deleted

Method RedisKnowledgeBase.set_ttl

Set TTL for a key.

set_ttl(identifier: str, ttl: int, **kwargs) -> bool

Parameter Type Default Description
identifier str Primary identifier
ttl int TTL in seconds
**kwargs {} Additional key components

Returns: bool — True if successful

Method RedisKnowledgeBase.get_ttl

Get remaining TTL for a key.

get_ttl(identifier: str, **kwargs) -> Optional[int]

Parameter Type Default Description
identifier str Primary identifier
**kwargs {} Additional key components

Returns: Optional[int] — TTL in seconds or None

Method RedisKnowledgeBase.ping

Test Redis connection.

ping() -> bool

Returns: bool

Method RedisKnowledgeBase.close

Close Redis connection.

close()

Method RedisKnowledgeBase.insert

Insert or update data in Redis.

insert(identifier: str, data: Union[Dict[str, Any], str, Any], field: Optional[str] = None, ttl: Optional[int] = None, **kwargs) -> bool

Parameter Type Default Description
identifier str Primary identifier for the key
data Union[Dict[str, Any], str, Any] Data to store (dict for hash, any for simple storage)
field Optional[str] None Field name (for hash storage only)
ttl Optional[int] None TTL in seconds (overrides default)
**kwargs {} Additional key components

Returns: bool — True if successful

Method RedisKnowledgeBase.get

Retrieve data from Redis.

get(identifier: str, field: Optional[str] = None, default: Any = None, **kwargs) -> Any

Parameter Type Default Description
identifier str Primary identifier for the key
field Optional[str] None Field name (for hash storage only)
default Any None Default value if not found
**kwargs {} Additional key components

Returns: Any — Retrieved data or default

Method RedisKnowledgeBase.update

Update existing data (alias for insert with merge capability).

update(identifier: str, data: Union[Dict[str, Any], Any], field: Optional[str] = None, **kwargs) -> bool

Parameter Type Default Description
identifier str Primary identifier
data Union[Dict[str, Any], Any] Data to update
field Optional[str] None Field name (for hash storage)
**kwargs {} Additional key components

Returns: bool — True if successful

Method RedisKnowledgeBase.delete

Delete data from Redis.

delete(identifier: str, field: Optional[str] = None, **kwargs) -> bool

Parameter Type Default Description
identifier str Primary identifier
field Optional[str] None Field name to delete (for hash storage only)
**kwargs {} Additional key components

Returns: bool — True if successful

Method RedisKnowledgeBase.exists

Check if key or field exists.

exists(identifier: str, field: Optional[str] = None, **kwargs) -> bool

Parameter Type Default Description
identifier str Primary identifier
field Optional[str] None Field name (for hash storage)
**kwargs {} Additional key components

Returns: bool — True if exists

Method RedisKnowledgeBase.bulk_insert

Insert multiple items in bulk.

bulk_insert(items: List[Dict[str, Any]], identifier_key: str = 'id', ttl: Optional[int] = None) -> int

Parameter Type Default Description
items List[Dict[str, Any]] List of items to insert
identifier_key str 'id' Key name containing the identifier
ttl Optional[int] None TTL for all items

Returns: int — Number of items successfully inserted

Method RedisKnowledgeBase.bulk_get

Retrieve multiple items in bulk.

bulk_get(identifiers: List[str], **kwargs) -> Dict[str, Any]

Parameter Type Default Description
identifiers List[str] List of identifiers
**kwargs {} Additional key components

Returns: Dict[str, Any] — Dict mapping identifier to data

Method RedisKnowledgeBase.bulk_delete

Delete multiple items in bulk.

bulk_delete(identifiers: List[str], **kwargs) -> int

Parameter Type Default Description
identifiers List[str] List of identifiers to delete
**kwargs {} Additional key components

Returns: int — Number of items deleted

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally