UNPKG

@knowall-ai/reverie

Version:

Reverie — graph memory that dreams. Graph-based memory system for AI agents. Store people, places, organizations as nodes. Build semantic relationships (KNOWS, WORKS_AT, CREATED). Hybrid keyword + semantic search finds partial matches and close variants.

44 lines (43 loc) • 2.28 kB
import { EMBEDDING_FIELDS } from './embeddings.js'; /** Above this many real properties a node is "bloated": facts are being piled on instead of modelled. */ export const DEFAULT_MAX_PROPERTIES = 30; export const MAX_PROPERTIES_CAP = 500; const HOUSEKEEPING = new Set([...EMBEDDING_FIELDS, 'created_at', 'updated_at', 'status', 'archived_at']); const DATE_SUFFIX_RE = /(_|-)\d{4}(_|-)\d{2}(_|-)\d{2}$/; const LONG_TEXT = 120; /** REVERIE_MAX_PROPERTIES must be a whole number in 1..MAX_PROPERTIES_CAP; anything else falls back to the default. */ export function maxProperties(env = process.env) { const raw = (env.REVERIE_MAX_PROPERTIES ?? '').trim(); if (!/^\d+$/.test(raw)) { return DEFAULT_MAX_PROPERTIES; } const value = Number(raw); return value >= 1 && value <= MAX_PROPERTIES_CAP ? value : DEFAULT_MAX_PROPERTIES; } /** User-visible properties only: no `_id`-style metadata, timestamps, status or embedding fields. */ export function contentKeys(props) { return Object.keys(props).filter((key) => !key.startsWith('_') && !HOUSEKEEPING.has(key)); } /** Keys that look like facts or episodes rather than attributes: dated names, or long prose values. */ export function factLikeKeys(props) { return contentKeys(props).filter((key) => { const value = props[key]; return DATE_SUFFIX_RE.test(key) || (typeof value === 'string' && value.length > LONG_TEXT); }); } export const DEFAULT_LAZY_EMBED_BATCH = 100; export const MAX_LAZY_EMBED_BATCH = 1000; /** REVERIE_LAZY_EMBED_BATCH: stale candidates embedded per search; whole number 1..1000, else the default. */ export function lazyEmbedBatch(env = process.env) { const raw = (env.REVERIE_LAZY_EMBED_BATCH ?? '').trim(); if (!/^\d+$/.test(raw)) { return DEFAULT_LAZY_EMBED_BATCH; } const value = Number(raw); return value >= 1 && value <= MAX_LAZY_EMBED_BATCH ? value : DEFAULT_LAZY_EMBED_BATCH; } export function bloatHint(name, count, limit) { return `"${name}" now has ${count} properties (limit ${limit}). The graph maps entities and relationships; ` + 'keep only durable attributes here. Fold dated facts and episodes into a short attribute, a relationship, ' + 'or your notes. See get_guidance("best-practices").'; }