From Unstructured Recall to Schema-Grounded Memory: Reliable AI Memory via Iterative, Schema-Aware Extraction
TL;DR Highlight
RAG 스타일 텍스트 검색 대신 Schema로 정의된 구조화 레코드에 메모리를 저장하면, 정확한 사실 조회·상태 추적·집계 쿼리에서 압도적으로 높은 정확도를 얻을 수 있다.
Who Should Read
AI 에이전트나 챗봇에 장기 메모리를 붙이려는 백엔드/ML 엔지니어. 특히 RAG 기반 메모리에서 오래된 상태가 리턴되거나 집계 쿼리가 틀리는 문제를 겪고 있는 개발자.
Core Mechanics
- RAG 스타일 메모리(텍스트 저장 + 임베딩 검색)는 주제 기반 탐색엔 괜찮지만, 정확한 값 조회·상태 추적·집계·관계형 쿼리·부재(absence) 확인엔 구조적으로 한계가 있다.
- Schema를 '무엇을 기억해야 하는가'에 대한 명시적 계약으로 정의하면, 누락된 필드가 '조용한 실패'가 아니라 '감지 가능한 오류'가 된다.
- 단일 패스(one-shot) 구조화 출력은 필드 정확도가 97%라도, 필드가 20개면 전체 레코드 정확도는 0.97^20 ≈ 54%로 폭락한다 — 복합 오류 때문.
- xmemory는 추출을 Object Detection → Field Detection → Field Value Extraction 세 단계로 나누고, 각 단계에 검증 게이트(validation gate)와 로컬 재시도를 붙여서 이 문제를 해결한다.
- 메모리 컨텍스트를 Request(단일 요청) / Session(세션 전체) / Main(영구 저장소) 세 층으로 분리해서, 각 층이 담당하는 결정의 범위를 좁힌다.
- 쓰기 경로(write path)가 복잡해지는 대신, 읽기는 검증된 레코드에 대한 단순 쿼리가 되어 토큰 소비가 약 3배 줄고 결정 레이턴시도 낮아진다.
Evidence
- end-to-end 메모리 벤치마크에서 xmemory F1 97.10% vs 비교 대상(Cognee, Mem0, Supermemory, Zep) 80.16%~87.24% — 최고 경쟁자 대비 약 10%p 차이.
- 구조화 추출(보험 청구 데이터셋) Object-level accuracy: xmemory + LLM judge 90.42% vs GPT-5.5 high reasoning 83.98%, Gemini 3.1 Pro 89.24% — 프론티어 모델 단독 사용보다 높음.
- Output-level accuracy(전체 클레임의 모든 객체가 완벽히 맞는 비율): xmemory + judge 62.67% vs 최고 경쟁 모델 Gemini 3.1 Pro 61.67%, GPT-5.5 high reasoning 44%.
- Splitwise 애플리케이션 태스크(자연어 식사 이벤트 → 집계 질의): xmemory 95.2% vs Supermemory 73.75%, Cognee 68%, Mem0(graph) 59.1%, Zep 25.7%.
How to Apply
- 현재 RAG 메모리에서 '지금 DB는 뭐야?', '현재 상태는?', '총 몇 번 실패했어?' 같은 쿼리가 틀릴 때: 대화 로그를 그대로 임베딩하는 대신 Schema(YAML/JSON Schema)를 먼저 정의하고, 그 Schema에 맞춰 구조화된 레코드로 변환하는 write pipeline을 추가하면 된다.
- 단일 LLM 호출로 복잡한 JSON을 뽑으려다 레코드 전체가 틀리는 문제가 있다면: 추출을 '객체 존재 여부 판단 → 어떤 필드가 있는지 판단 → 각 필드 값 추출' 3단계로 쪼개고, 각 단계에 타입/포맷 검증 + 실패 시 해당 필드만 재시도하는 로직을 넣으면 레코드 정확도가 크게 올라간다.
- 에이전트가 세션 간 상태를 유지해야 하는 경우: 단일 컨텍스트 대신 Request/Session/Main 세 레이어로 나눠서, 현재 요청의 임시 추출 결과는 Request에, 세션 중 부분 완성 객체는 Session에, 최종 확정된 사실은 Main에 버전 관리와 함께 저장하는 아키텍처를 적용할 수 있다.
Code Example
# Schema 정의 예시 (YAML)
# 'ServiceConfig'라는 엔티티: 어떤 컴포넌트가 어떤 DB를 쓰는지 기억
ServiceConfig:
required:
- component # string: 'session store', 'cache' 등
- database # string: 'Redis', 'Postgres' 등
- status # enum: active | rejected | unknown
optional:
- reason # string: 상태 변경 이유
- changed_at # datetime
# Write path: 대화에서 구조화 레코드 추출 (3단계 분해)
def extract_memory(text: str, schema: dict) -> dict:
# 1단계: 객체가 존재하는지 판단
obj_detected = llm_call(
f"Does this text mention a ServiceConfig entity? Answer yes/no.\n{text}"
)
if obj_detected != 'yes':
return None
# 2단계: 어떤 필드가 언급됐는지 판단
fields_present = llm_call(
f"Which fields from {list(schema['required'] + schema['optional'])} "
f"are mentioned in the text? Return JSON list.\n{text}"
)
# 3단계: 각 필드 값 추출 + 검증 + 재시도
record = {}
for field in fields_present:
for attempt in range(3): # 최대 3번 재시도
value = llm_call(
f"Extract '{field}' from the text. "
f"If not mentioned, return null. Do NOT infer or approximate.\n{text}"
)
if validate_field(field, value, schema):
record[field] = value
break
else:
record[field] = None # 명시적 unknown
return record
# Read path: 구조화 쿼리 (추론 없이 직접 조회)
# SELECT database FROM ServiceConfig WHERE component = 'session store' AND status = 'active'Terminology
Related Papers
Show HN: Atomic – Local-first, AI-augmented personal knowledge base
Atomic builds a self-hosted, open-source personal knowledge graph app that automatically embeds, tags, and links notes, web clips, and RSS feeds—supporting semantic search, LLM-powered wiki synthesis, and MCP integration.
We replaced RAG with a virtual filesystem for our AI documentation assistant
Explains how Mintlify overcame RAG chunking limitations by building a virtual filesystem (ChromaFs) on top of Chroma DB that mimics UNIX commands, reducing session boot time from 46 seconds to 100ms.
Chroma Context-1: Training a Self-Editing Search Agent
Chroma's newly released 20B parameter agentic search model claims frontier-LLM-level retrieval performance at 1/10 the cost and 10x the speed — though a significant controversy over failure to cite prior work has emerged in the community.
Show HN: Gemini can now natively embed video, so I built sub-second video search
Google's Gemini Embedding model can now embed video directly into vectors without text transcription, enabling natural language search over dashcam footage — describe 'red truck running a stop sign' and get the clip back.
From zero to a RAG system: successes and failures
A hands-on account of building a local LLM-based RAG system from scratch on 1TB of internal technical documentation, honestly sharing the trial and error encountered from data preprocessing to vector indexing.
Related Resources
Original Abstract (Expand)
Persistent AI memory is often reduced to a retrieval problem: store prior interactions as text, embed them, and ask the model to recover relevant context later. This design is useful for thematic recall, but it is mismatched to the kinds of memory that agents need in production: exact facts, current state, updates and deletions, aggregation, relations, negative queries, and explicit unknowns. These operations require memory to behave less like search and more like a system of record. This paper argues that reliable external AI memory must be schema-grounded. Schemas define what must be remembered, what may be ignored, and which values must never be inferred. We present an iterative, schema-aware write path that decomposes memory ingestion into object detection, field detection, and field-value extraction, with validation gates, local retries, and stateful prompt control. The result shifts interpretation from the read path to the write path: reads become constrained queries over verified records rather than repeated inference over retrieved prose. We evaluate this design on structured extraction and end-to-end memory benchmarks. On the extraction benchmark, the judge-in-the-loop configuration reaches 90.42% object-level accuracy and 62.67% output accuracy, above all tested frontier structured-output baselines. On our end-to-end memory benchmark, xmemory reaches 97.10% F1, compared with 80.16%-87.24% across the third-party baselines. On the application-level task, xmemory reaches 95.2% accuracy, outperforming specialised memory systems, code-generated Markdown harnesses, and customer-facing frontier-model application harnesses. The results show that, for memory workloads requiring stable facts and stateful computation, architecture matters more than retrieval scale or model strength alone.