Astro Intelligence

Storage API Reference

Storage API Reference

Complete API reference for all storage protocols and implementations in anchor.

For a usage guide, see Storage Guide.


Protocols

VectorStore

Protocol for vector similarity search backends (FAISS, Chroma, Qdrant, etc.).

class VectorStore(Protocol):
    def add_embedding(
        self, item_id: str, embedding: list[float], metadata: dict[str, Any] | None = None
    ) -> None: ...

    def search(
        self, query_embedding: list[float], top_k: int = 10
    ) -> list[tuple[str, float]]: ...

    def delete(self, item_id: str) -> bool: ...
MethodDescription
add_embedding(item_id, embedding, metadata)Store an embedding vector. Overwrites if item_id exists.
search(query_embedding, top_k)Return (item_id, score) tuples sorted by descending similarity.
delete(item_id)Remove an embedding. Returns True if found.

ContextStore

Protocol for storing and retrieving ContextItem objects.

class ContextStore(Protocol):
    def add(self, item: ContextItem) -> None: ...
    def get(self, item_id: str) -> ContextItem | None: ...
    def get_all(self) -> list[ContextItem]: ...
    def delete(self, item_id: str) -> bool: ...
    def clear(self) -> None: ...
MethodDescription
add(item)Persist a context item. Overwrites if same id exists.
get(item_id)Retrieve by ID. Returns None if not found.
get_all()Return all items. Order is implementation-defined.
delete(item_id)Remove by ID. Returns True if found.
clear()Remove all items.

DocumentStore

Protocol for raw document text storage (pre-chunking).

class DocumentStore(Protocol):
    def add_document(
        self, doc_id: str, content: str, metadata: dict[str, Any] | None = None
    ) -> None: ...
    def get_document(self, doc_id: str) -> str | None: ...
    def list_documents(self) -> list[str]: ...
    def delete_document(self, doc_id: str) -> bool: ...
MethodDescription
add_document(doc_id, content, metadata)Store a document.
get_document(doc_id)Retrieve text by ID. Returns None if not found.
list_documents()Return all document IDs.
delete_document(doc_id)Remove by ID. Returns True if found.

MemoryEntryStore

Protocol for persistent MemoryEntry storage.

class MemoryEntryStore(Protocol):
    def add(self, entry: MemoryEntry) -> None: ...
    def search(self, query: str, top_k: int = 5) -> list[MemoryEntry]: ...
    def list_all(self) -> list[MemoryEntry]: ...
    def delete(self, entry_id: str) -> bool: ...
    def clear(self) -> None: ...
MethodDescription
add(entry)Persist a memory entry. Overwrites if same id exists.
search(query, top_k)Search by query string. Matching semantics are implementation-defined.
list_all()Return all non-expired entries.
delete(entry_id)Remove by ID. Returns True if found.
clear()Remove all entries.

GarbageCollectableStore

Extended protocol for stores that support garbage collection of expired entries.

class GarbageCollectableStore(Protocol):
    def list_all_unfiltered(self) -> list[MemoryEntry]: ...
    def delete(self, entry_id: str) -> bool: ...
MethodDescription
list_all_unfiltered()Return all entries including expired ones.
delete(entry_id)Remove by ID. Returns True if found.

In-Memory Implementations

InMemoryVectorStore

Brute-force cosine similarity vector store for development and testing.

class InMemoryVectorStore:
    def __init__(self) -> None: ...

Implements VectorStore. Thread-safe via threading.Lock.

Methods:

MethodSignatureDescription
add_embedding(item_id: str, embedding: list[float], metadata: dict[str, Any] | None = None) -> NoneStore an embedding vector with optional metadata.
search(query_embedding: list[float], top_k: int = 10) -> list[tuple[str, float]]Brute-force cosine similarity search. Logs a warning above 5,000 embeddings.
delete(item_id: str) -> boolRemove an embedding. Returns True if found.

[!CAUTION] Linear scan complexity O(N) per query. Use a dedicated vector database for production workloads.


InMemoryContextStore

Dict-backed context store. Thread-safe.

class InMemoryContextStore:
    def __init__(self) -> None: ...

Implements ContextStore.

Methods:

MethodSignatureDescription
add(item: ContextItem) -> NoneStore a context item.
get(item_id: str) -> ContextItem | NoneRetrieve by ID.
get_all() -> list[ContextItem]Return all items.
delete(item_id: str) -> boolRemove by ID.
clear() -> NoneRemove all items.

InMemoryDocumentStore

Dict-backed document store. Thread-safe.

class InMemoryDocumentStore:
    def __init__(self) -> None: ...

Implements DocumentStore.

Methods:

MethodSignatureDescription
add_document(doc_id: str, content: str, metadata: dict[str, Any] | None = None) -> NoneStore a document.
get_document(doc_id: str) -> str | NoneRetrieve by ID.
list_documents() -> list[str]Return all document IDs.
delete_document(doc_id: str) -> boolRemove by ID.

InMemoryEntryStore

In-memory MemoryEntry store with filtering and search.

class InMemoryEntryStore:
    def __init__(self) -> None: ...

Implements MemoryEntryStore and GarbageCollectableStore. Thread-safe.

Methods:

MethodSignatureDescription
add(entry: MemoryEntry) -> NoneStore a memory entry.
delete(entry_id: str) -> boolRemove by ID.
clear() -> NoneRemove all entries.
search(query: str, top_k: int = 5) -> list[MemoryEntry]Substring search, excluding expired entries.
list_all() -> list[MemoryEntry]Return all non-expired entries.
list_all_unfiltered() -> list[MemoryEntry]Return all entries including expired.
get(entry_id: str) -> MemoryEntry | NoneRetrieve a single entry by ID.
search_filtered(query, top_k, *, user_id, session_id, memory_type, tags, created_after, created_before) -> list[MemoryEntry]Filtered search with multiple criteria.
delete_by_user(user_id: str) -> intDelete all entries for a user. Returns count deleted.

Persistent Implementations

JsonFileMemoryStore

JSON-file-backed persistent MemoryEntry store. Uses atomic writes (temp file + rename) to prevent corruption.

class JsonFileMemoryStore:
    def __init__(
        self,
        file_path: str | Path,
        *,
        auto_save: bool = True,
    ) -> None: ...
ParameterTypeDefaultDescription
file_pathstr | Path--Path to the JSON file. Created on first save. Loaded on init if exists.
auto_saveboolTruePersist after every mutation (add, delete, clear).

Implements MemoryEntryStore and GarbageCollectableStore. Thread-safe.

Methods:

MethodSignatureDescription
add(entry: MemoryEntry) -> NoneStore and optionally persist to disk.
delete(entry_id: str) -> boolRemove by ID and optionally persist.
clear() -> NoneRemove all entries and persist.
save() -> NoneExplicitly flush to disk (atomic write).
load() -> NoneReload entries from the JSON file.
search(query: str, top_k: int = 5) -> list[MemoryEntry]Substring search, excluding expired.
list_all() -> list[MemoryEntry]Return non-expired entries.
list_all_unfiltered() -> list[MemoryEntry]Return all entries including expired.
get(entry_id: str) -> MemoryEntry | NoneRetrieve a single entry.
search_filtered(query, top_k, *, user_id, session_id, memory_type, tags, created_after, created_before) -> list[MemoryEntry]Filtered search.
delete_by_user(user_id: str) -> intDelete all entries for a user.
export_user_entries(user_id: str) -> list[MemoryEntry]Export all entries for a user (GDPR data portability).

[!NOTE] Not suitable for concurrent multi-process access. For multi-worker deployments, implement MemoryEntryStore with a database backend.

On this page