@dawn-ai/memory

Use this when

Use this package when your application needs a standalone long-term-memory store or lower-level browse, namespace, ranking, and reconciliation utilities. Most Dawn routes should declare memory with defineMemory() and follow Long-term Memory.

Install and import

bash
pnpm add @dawn-ai/memory
ts
import { sqliteMemoryStore } from "@dawn-ai/memory"
import { validateBrowseQuery } from "@dawn-ai/memory/browse"
import { serializeNamespace } from "@dawn-ai/memory/namespace"
import { approveWithReconcile } from "@dawn-ai/memory/reconcile"

Compatibility and audience

SurfaceRuntimePurityAudienceStability
@dawn-ai/memorynode-onlynot-claimedapplicationsupported
@dawn-ai/memory/browseedge-safedependency-freeintegrationsupported
@dawn-ai/memory/namespaceedge-safenot-claimedintegrationsupported
@dawn-ai/memory/reconcileedge-safenot-claimedintegrationsupported

The root includes the SQLite store. Import /browse, /namespace, or /reconcile directly when an edge integration needs only that contract.

Public exports

@dawn-ai/memory

ExportResponsibility
BrowseCursorPayloadDescribe decoded browse cursor metadata.
BrowseCursorValueDescribe one cursor sort value.
BROWSE_CURSOR_VERSIONIdentify the cursor format.
browseCursorKeyBuild a cursor comparison key.
browseQueryFingerprintFingerprint cursor-bound query inputs.
decodeBrowseCursorDecode and validate cursor structure.
encodeBrowseCursorEncode a browse cursor.
normalizeSetFilterNormalize a set-valued browse filter.
ResolvedBrowseSortDescribe normalized browse ordering.
DEFAULT_BROWSE_ORDERExpose default browse ordering.
resolveBrowseOrderNormalize requested browse ordering.
namespacePrefixUpperBoundCompute a half-open namespace-prefix bound.
utcDayAfterCompute the next UTC day.
utcDayStartNormalize a UTC day start.
BROWSE_DEFAULT_LIMITExpose the default page size.
BROWSE_MAX_LIMITExpose the recommended untrusted-boundary ceiling.
BROWSE_SORT_FIELDSList supported sort fields.
BrowseQueryErrorReport invalid browse input.
validateBrowseQueryValidate or reject browse input.
buildConsolidationPromptBuild a consolidation prompt.
buildReflectionPromptBuild a reflection prompt.
buildReflectionRecordsMaterialize reflection records.
buildReflectionWatermarkRecordMaterialize a reflection watermark.
buildSummaryRecordMaterialize a summary record.
ConsolidationBatchDescribe one consolidation batch.
eventTimeOfResolve a record's event time.
isoWeekKeyGroup an instant by ISO week.
parseConsolidationOutputParse consolidation model output.
parseReflectionOutputParse reflection model output.
ReflectionInputDescribe reflection input.
ReflectionInsightDescribe a parsed insight.
selectConsolidationBatchesSelect deterministic consolidation work.
selectReflectionInputSelect deterministic reflection input.
fuseHybridFuse keyword and vector candidates.
rankKeywordCandidatesRank keyword candidates.
MemoryScopeTupleDescribe ordered namespace dimensions.
parseNamespaceParse a serialized namespace.
routeNamespaceKeyNormalize a route path for namespacing.
serializeNamespaceSerialize namespace dimensions.
ApproveResultDescribe reconciliation approval.
approveWithReconcileApprove a candidate with reconciliation.
classifyWriteClassify an add, update, or supersede.
WriteOpName a classified write operation.
WritePolicyDescribe per-kind write discipline.
writePolicyForResolve per-kind write discipline.
DEFAULT_CANDIDATE_POOLExpose default ranking candidate count.
DEFAULT_RECALL_WEIGHTSExpose default recall weights.
DEFAULT_RECENCY_HALF_LIFE_MSExpose default recency decay.
idfCompute inverse document frequency.
RecallRankingOptionsConfigure recall ranking.
RecallWeightsConfigure ranking weights.
recencyDecayCompute recency contribution.
scoreMemoryScore one memory candidate.
sqliteMemoryStoreCreate a SQLite memory store.
tokenizeTokenize text for keyword recall.
BrowseFilterDescribe one browse filter.
BrowsePageDescribe a browse page.
BrowseQueryDescribe browse input.
BrowseSortEntryDescribe one sort entry.
BrowseSortFieldName a sortable field.
MemoryKindName a memory kind.
MemoryQueryDescribe recall input.
MemoryRecordDescribe a stored memory.
MemorySourceDescribe record provenance.
MemoryStatsDescribe store statistics.
MemoryStatusName a record status.
MemoryStoreDefine the memory-store contract.
VectorRankingOptionsConfigure vector recall.
cosineSimilarityCompare vector direction.
DEFAULT_RRF_KExpose the reciprocal-rank constant.
DEFAULT_VECTOR_KExpose the default vector candidate count.
fuseRRFFuse ranked lists by reciprocal rank.
RankedListDescribe a ranked list.

@dawn-ai/memory/browse

ExportResponsibility
BrowseCursorPayloadDescribe decoded cursor metadata.
BrowseCursorValueDescribe one cursor sort value.
BROWSE_CURSOR_VERSIONIdentify the cursor format.
browseCursorKeyBuild a cursor comparison key.
browseQueryFingerprintBind a cursor to query inputs.
decodeBrowseCursorDecode a cursor.
encodeBrowseCursorEncode a cursor.
normalizeSetFilterNormalize a set filter.
ResolvedBrowseSortDescribe normalized ordering.
DEFAULT_BROWSE_ORDERExpose default ordering.
resolveBrowseOrderNormalize ordering.
namespacePrefixUpperBoundCompute a namespace-prefix bound.
utcDayAfterCompute the next UTC day.
utcDayStartNormalize a UTC day start.
BROWSE_DEFAULT_LIMITExpose the default limit.
BROWSE_MAX_LIMITExpose the recommended untrusted-boundary ceiling.
BROWSE_SORT_FIELDSList sortable fields.
BrowseQueryErrorReport invalid input.
validateBrowseQueryValidate or reject browse input.
BrowseFilterDescribe one filter.
BrowsePageDescribe a page.
BrowseQueryDescribe browse input.
BrowseSortEntryDescribe one sort entry.
BrowseSortFieldName a sortable field.
MemoryKindName a memory kind.
MemoryRecordDescribe a memory row.
MemorySourceDescribe provenance.
MemoryStatusName record status.

@dawn-ai/memory/namespace

ExportResponsibility
MemoryScopeTupleDescribe ordered namespace dimensions.
parseNamespaceParse a serialized namespace.
routeNamespaceKeyNormalize a route path.
serializeNamespaceSerialize dimensions.

@dawn-ai/memory/reconcile

ExportResponsibility
ApproveResultDescribe approval output.
approveWithReconcileApprove with deterministic reconciliation.
classifyWriteClassify a write.
WriteOpName a write operation.
WritePolicyDescribe write discipline.
writePolicyForResolve write discipline.

Key contracts

MemoryScopeTuple

ts
export interface MemoryScopeTuple {
  readonly workspace?: string
  readonly route?: string
  readonly tenant?: string
  readonly user?: string
  readonly agent?: string
}

Fields: @dawn-ai/memory#./namespace:MemoryScopeTuple

FieldTypeRequiredDescription
readonly workspacestringnoScope by application workspace.
readonly routestringnoScope by route.
readonly tenantstringnoScope by tenant.
readonly userstringnoScope by user.
readonly agentstringnoScope by agent.

Store and query shapes

ts
export interface MemoryRecord {
  readonly id: string
  readonly kind: MemoryKind
  readonly namespace: string
  readonly content: string
  readonly data: Record<string, unknown>
  readonly source: MemorySource
  readonly confidence: number
  readonly tags: readonly string[]
  readonly status: MemoryStatus
  readonly supersedes?: readonly string[]
  readonly createdAt: string
  readonly updatedAt: string
  readonly effectiveAt?: string
  readonly expiresAt?: string
}
ts
export interface MemoryQuery {
  readonly namespace: string
  readonly query?: string
  readonly kind?: MemoryKind
  readonly tags?: readonly string[]
  readonly status?: MemoryStatus
  readonly limit?: number
  readonly now?: string
  readonly since?: string
  readonly until?: string
  readonly queryEmbedding?: Float32Array
  readonly embedderId?: string
  readonly vector?: VectorRankingOptions
}
ts
export interface BrowsePage {
  readonly records: readonly MemoryRecord[]
  readonly total: number
  readonly continuation: string | null
}
ts
export interface BrowseQuery {
  readonly namespacePrefix?: string
  readonly namespace?: string
  readonly status?: MemoryStatus | readonly MemoryStatus[]
  readonly kind?: MemoryKind | readonly MemoryKind[]
  readonly sourceType?: MemorySource["type"]
  readonly limit?: number
  readonly offset?: number
  readonly since?: string
  readonly until?: string
  readonly now?: string
  readonly filters?: readonly BrowseFilter[]
  readonly orderBy?: readonly BrowseSortEntry[]
  readonly cursor?: string
}
ts
export interface MemoryStore {
  put(
    rec: MemoryRecord,
    opts?: { readonly embedding?: Float32Array; readonly embeddingModel?: string },
  ): Promise<void>
  get(id: string): Promise<MemoryRecord | null>
  search(q: MemoryQuery): Promise<readonly MemoryRecord[]>
  update(id: string, patch: Partial<MemoryRecord>): Promise<void>
  supersede(id: string, bySupersedingId: string): Promise<void>
  delete(id: string): Promise<void>
  listCandidates(namespacePrefix: string): Promise<readonly MemoryRecord[]>
  browse(q?: BrowseQuery): Promise<BrowsePage>
  stats(opts?: { readonly namespacePrefix?: string }): Promise<MemoryStats>
  prune(opts: {
    readonly now: string
    readonly namespacePrefix?: string
    readonly cap?: number
  }): Promise<{ readonly deletedExpired: number; readonly deletedOverCap: number }>
}
ts
export declare function serializeNamespace(tuple: MemoryScopeTuple): string
ts
export declare function approveWithReconcile(
  store: MemoryStore,
  id: string,
  opts: { readonly identityKeys: readonly string[]; readonly now: string },
): Promise<ApproveResult>

Behavior contract memory.namespace.stable-encoding

serializeNamespace emits dimensions in a stable order, escapes reserved delimiters reversibly, and rejects an empty scope.

Trust boundaries

parseNamespace() is a parser, not an authorization check: it ignores unknown and malformed parts. Browse cursors detect query mismatches but are not authenticated tokens. At an untrusted boundary, the server must own the namespace and enforce an application limit no larger than BROWSE_MAX_LIMIT.

Call validateBrowseQuery(query, { maxLimit: BROWSE_MAX_LIMIT }) at that boundary. Stores do not enforce the 1,000-row ceiling automatically.

SQLite stores memory rows—including content, data, source, and tags—as plaintext. A namespace organizes records; it is not a security boundary. Protect the database file and its path with application and infrastructure access controls.

Behavior contract memory.browse.pure-subpath

The /browse entry reaches only the pure browse modules and no external package, so it does not pull node:sqlite into edge or browser bundles.

Behavior contract memory.write-policy

writePolicyFor() selects reconciliation for semantic memory and append behavior for episodic and reflection memory; it throws for procedural memory because that reconciliation policy is not implemented. Low-level MemoryStore implementations can store typed procedural records, while the generated remember tool returns a not-yet-wired rejection without throwing or writing.

Approval caveats

approveWithReconcile() uses a non-transactional read-classify-write sequence and scans at most 10,000 active rows. Semantic memory reconciles; episodic and reflection memory append.

ts
import { sqliteMemoryStore } from "@dawn-ai/memory"
 
const store = sqliteMemoryStore({ path: ".dawn/memory.sqlite" })
const records = await store.search({ namespace: "workspace=acme", query: "shipping" })

Continue with Long-term Memory, Recall and Retrieval, Browse and Manage Memory, and Persistence and Tenancy.