feat(api): add conversation archive with vector search (MS22-DB-004, MS22-API-004)
All checks were successful
ci/woodpecker/push/orchestrator Pipeline was successful
ci/woodpecker/push/web Pipeline was successful
ci/woodpecker/push/api Pipeline was successful

- Add ConversationArchive Prisma model with pgvector(1536) embedding field
- Migration: 20260228000000_ms22_conversation_archive
- NestJS module at apps/api/src/conversation-archive/ with service, controller, DTOs, spec
- POST /api/conversations/ingest — ingest session logs, auto-embed via EmbeddingService
- POST /api/conversations/search — vector similarity search with agentId filter
- GET  /api/conversations — paginated list with agentId + date range filters
- GET  /api/conversations/:id — fetch full conversation including messages
- Register ConversationArchiveModule in app.module.ts
- 8 unit tests, all passing (vitest)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 19:42:29 -06:00
parent 7b390d8be2
commit de37e7be90
12 changed files with 763 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
# MS22 — Conversation Archive Module
## Objective
Implement ConversationArchive module: ingest OpenClaw session logs, store with vector embeddings for semantic search.
## Deliverables
1. ConversationArchive Prisma model
2. NestJS module at apps/api/src/conversation-archive/
3. Endpoints: ingest, search, list, get-by-id
4. Register in app.module.ts
5. Migrate, lint, build, commit
## Plan
- Add model to schema.prisma (end of file)
- Add relation to Workspace model
- Create module structure: dto/, service, controller, spec, module
- Use EmbeddingService from knowledge module (import KnowledgeModule or just PrismaModule + embed inline)
- Follow pattern: AuthGuard + WorkspaceGuard + PermissionGuard
- Endpoint prefix: conversations (maps to /api/conversations)
- Vector search: $queryRaw with <=> operator (cosine distance)
## Assumptions
- ASSUMPTION: Embedding is stored inline on ConversationArchive (not a separate table) — simpler and sufficient for this use case, matches MemoryEmbedding pattern
- ASSUMPTION: Import KnowledgeModule to reuse EmbeddingService (it exports it)
- ASSUMPTION: messageCount computed server-side from messages array length on ingest
- ASSUMPTION: Permission level WORKSPACE_MEMBER for ingest/search, WORKSPACE_ANY for list/get
## Progress
- [ ] Schema model
- [ ] Migration
- [ ] DTOs
- [ ] Service
- [ ] Controller
- [ ] Spec
- [ ] Module
- [ ] app.module.ts registration
- [ ] Lint + build
- [ ] Commit
## Risks
- EmbeddingService exports from knowledge.module — need to import KnowledgeModule
- Migration requires live DB (may need --skip-generate flag if no DB access)