UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

60 lines (59 loc) • 3.41 kB
import type { MemoryIdentity } from '../identity/index.js'; import type { MemoryEntry } from '../entry/index.js'; import type { ListOptions, ListResult, MemoryStore, PutIfVersionResult, ScoredEntry, SearchOptions } from './types.js'; import { type MemoryWriteOptions } from './writeOptions.js'; export declare class InMemoryStore implements MemoryStore { /** * Vectors in, ranked vectors out — the linear cosine scan below ranks the * embeddings it was handed. Declared (8.19.0) so a corpus builder can tell * this apart from a store whose `search()` ranks server-side over a * population it derived itself. */ readonly supportsVectorSearch = true; /** * Top-level namespace → slot. Using `Map` rather than a plain object * avoids prototype-pollution surface AND preserves insertion order * (needed for deterministic list pagination). */ private readonly namespaces; private slot; /** True if the entry's TTL has elapsed. Centralized so both `get` and `list` agree. */ private isExpired; get<T = unknown>(identity: MemoryIdentity, id: string): Promise<MemoryEntry<T> | null>; /** * Write options: none honoured — a `Map` derives nothing from what it holds, * so `extraction` and `namespaceScope` are refused by name, never ignored. */ put<T = unknown>(identity: MemoryIdentity, entry: MemoryEntry<T>, options?: MemoryWriteOptions): Promise<void>; /** * Batched write — resolves the slot once and writes each entry into the * same Map. Saves N-1 slot lookups vs. calling `put()` in a loop, and * gives network-backed adapters a place to pipeline round-trips. */ putMany<T = unknown>(identity: MemoryIdentity, entries: readonly MemoryEntry<T>[], options?: MemoryWriteOptions): Promise<void>; putIfVersion<T = unknown>(identity: MemoryIdentity, entry: MemoryEntry<T>, expectedVersion: number, options?: MemoryWriteOptions): Promise<PutIfVersionResult>; list<T = unknown>(identity: MemoryIdentity, options?: ListOptions): Promise<ListResult<T>>; delete(identity: MemoryIdentity, id: string): Promise<void>; seen(identity: MemoryIdentity, signature: string): Promise<boolean>; recordSignature(identity: MemoryIdentity, signature: string): Promise<void>; feedback(identity: MemoryIdentity, id: string, usefulness: number): Promise<void>; getFeedback(identity: MemoryIdentity, id: string): Promise<{ average: number; count: number; } | null>; forget(identity: MemoryIdentity): Promise<void>; /** * O(n) linear scan over identity-scoped entries. Fine for dev / tests * — for production, plug in a real vector backend (pgvector, Pinecone, * Qdrant) that implements the same interface. * * Semantics per the `MemoryStore.search?` contract: * - Entries without `embedding` are skipped (ignored, not errored). * - Entries with `embedding.length` mismatching the query are * skipped (cosine would throw — silent-skip avoids poisoning top-k). * - TTL-expired entries are omitted. * - Optional `tiers` / `minScore` / `embedderId` filters applied. * - Returns descending by score; ties broken by id for determinism. */ search<T = unknown>(identity: MemoryIdentity, query: readonly number[], options?: SearchOptions): Promise<readonly ScoredEntry<T>[]>; }