Memory Bank¶
The Memory Bank manages specification storage and retrieval using vector embeddings.
Import¶
Constructor¶
Parameters¶
| Parameter | Type | Description |
|---|---|---|
vectordb |
VectorStore |
Vector database backend |
embedding_provider |
EmbeddingProvider |
Embedding generator |
Example¶
from specmem.vectordb import LanceDBStore
from specmem.vectordb.embeddings import LocalEmbeddingProvider
vectordb = LanceDBStore(db_path=".specmem/vectordb")
embeddings = LocalEmbeddingProvider(model_name="all-MiniLM-L6-v2")
memory = MemoryBank(vector_store=vectordb, embedding_provider=embeddings)
Methods¶
add¶
Add a specification to the memory bank.
Returns¶
The ID of the added specification.
Example¶
spec = SpecBlock(
id="auth-001",
path="auth/requirements.md",
framework="kiro",
spec_type=SpecType.REQUIREMENT,
title="User Authentication",
content="...",
summary="JWT-based auth",
)
spec_id = memory.add(spec)
add_batch¶
Add multiple specifications efficiently.
Example¶
search¶
Search for similar specifications.
def search(
query: str,
top_k: int = 5,
filters: dict | None = None,
threshold: float = 0.0,
) -> list[SearchResult]
Parameters¶
| Parameter | Type | Description | Default |
|---|---|---|---|
query |
str |
Search query | required |
top_k |
int |
Number of results | 5 |
filters |
dict \| None |
Metadata filters | None |
threshold |
float |
Minimum score | 0.0 |
Example¶
results = memory.search(
query="authentication",
top_k=10,
filters={"spec_type": "requirement"},
threshold=0.5
)
for result in results:
print(f"{result.spec.path}: {result.score}")
get¶
Get a specification by ID.
Example¶
update¶
Update an existing specification.
Returns¶
True if updated, False if not found.
Example¶
delete¶
Delete a specification.
Example¶
pin¶
Pin a specification for guaranteed recall.
Pinned specifications are always included in context bundles.
Example¶
unpin¶
Unpin a specification.
get_pinned¶
Get all pinned specifications.
Example¶
get_all¶
Get all specifications.
Example¶
# All specs
all_specs = memory.get_all()
# Filtered
requirements = memory.get_all(filters={"spec_type": "requirement"})
count¶
Get the number of specifications.
Example¶
clear¶
Clear all specifications.
Warning
This permanently deletes all indexed specifications.
rebuild_index¶
Rebuild the vector index.
Use after bulk updates or when the index becomes corrupted.