strands.storage.search.types
Pluggable search strategy protocol for storage backends.
SearchStrategy
Section titled “SearchStrategy”class SearchStrategy(Protocol[S])Defined in: src/strands/storage/search/types.py:14
A pluggable search strategy for storage backends.
Strategies encapsulate a single approach to searching stored content —
keyword/lexical scan, vector similarity, full-text index, etc. Storage
backends delegate their search() to a strategy, and consumers (memory
stores, context offloaders) can override the default.
The S type parameter controls which storage backends the strategy is
compatible with. Defaults to :class:Storage (any backend). Strategies
that require specific backend features (e.g. base_dir) can narrow
this to a concrete type like :class:LocalFileStorage.
async def index(storage: S, key: str, data: bytes, **kwargs: Any) -> NoneDefined in: src/strands/storage/search/types.py:28
Index a single entry for future searches.
Consumers should call this on each write so strategies that maintain an index (FTS5, vector, etc.) can update incrementally. Strategies that search on the fly (keyword) may no-op.
Arguments:
storage- The storage backend the entry belongs to.key- The storage key being written.data- The raw bytes being stored.**kwargs- Strategy-specific options for forward compatibility.
search
Section titled “search”async def search(storage: S, query: str, **kwargs: Any) -> list[StorageSearchResult]Defined in: src/strands/storage/search/types.py:43
Search content in storage matching query.
Arguments:
storage- The storage to search over.query- A natural-language string query.**kwargs- Strategy-specific options for forward compatibility.
Returns:
Matched keys with relevance scores, ranked best-first.
SandboxSafeSearchStrategy
Section titled “SandboxSafeSearchStrategy”class SandboxSafeSearchStrategy(Protocol[S])Defined in: src/strands/storage/search/types.py:57
A search strategy that works inside a sandbox.
Strategies that operate purely through the :class:Storage API (e.g.
keyword scan) are sandbox-safe. Strategies that persist state on the
host filesystem (e.g. BM25 with a SQLite index) are not.
Declare requires_host_fs: Literal[False] = False on a strategy
class to mark it as sandbox-safe.
async def index(storage: S, key: str, data: bytes, **kwargs: Any) -> NoneDefined in: src/strands/storage/search/types.py:70
Index a single entry for future searches.
search
Section titled “search”async def search(storage: S, query: str, **kwargs: Any) -> list[StorageSearchResult]Defined in: src/strands/storage/search/types.py:74
Search content in storage matching query.