Do not collapse these into one embeddings table. Vectors are recall infrastructure, not the source of truth.
Current Tables To Build On
Raw Knowledge And Retrieval
Packet-First Project Intelligence
Compiler And Attribution Ledgers
These tables already exist and should remain first-class infrastructure:Existing Feedback And Memory
Additive Tables To Build First
The current tables are close, but feedback is fragmented. Add a thin normalized event layer instead of replacing existing feedback tables.ai_feedback_events
Purpose: one append-only event stream for every user/system learning signal. Existing feedback tables stay intact; this table points at them and normalizes cross-surface analysis.
Required columns:
retrievalattributionassistant_responsetool_actiontask_generationpacket_qualitydocument_reviewuser_preferenceworkflow_outcomeeval_failure
positivenegativecorrectedacceptedignoredcompletedfailedneeds_reviewstaleconflicting
(project_id, event_family, created_at desc)(target_id, event_family, created_at desc)(subject_type, subject_id, created_at desc)(source_table, source_record_id)(event_type, signal, created_at desc)
- service role writes all events
- users can insert events for their own interactions
- admins can read all
- project members can read project-scoped non-private events
- private preference/memory events require user ownership or admin access
ai_learning_promotions
Purpose: explicit review and promotion ledger. No feedback event should automatically become long-term behavior unless it passes a promotion rule.
Required columns:
agent_learningsfor prevention prompts and repeated failure patternsai_memoriesfor user/team facts, preferences, lessons, and commitmentsai_task_feedback.promoted = truefor approved positive task examplesdocument_attribution_candidates.status = approved|rejectedfor project-linking correctionsinsight_cards/insight_card_evidencefor packet-quality corrections- future retrieval scoring table for source/chunk ranking rules
ai_retrieval_feedback
Purpose: retrieval-specific learning that is too granular for agent_learnings.
Required columns:
helpfulunhelpfulwrong_projectstaleunsupportedunknown
Ingestion Flows
Microsoft Graph Teams, Outlook, And SharePoint
- Backend Graph service ingests messages, files, and attachments.
- Source row lands in
document_metadatawith source IDs, source URL/path, title/subject, participants, source timestamps, source_system, source_metadata, and raw_text or summary. - Text is chunked into
document_chunkswhen it has durable retrieval value. - Project attribution scores explicit IDs, project aliases, client names, addresses, participants, thread/channel/path/title context.
- High-confidence attribution updates
document_metadata.project_id. - Medium/low-confidence attribution creates
document_attribution_candidatesand anai_feedback_eventsreview signal. source_intelligence_jobsqueues signal extraction.- High-confidence signals promote to
insight_cardsandinsight_card_evidence. packet_refresh_jobsqueues packet regeneration.
Fireflies Meetings
- Transcript/summary lands in
document_metadata. - Transcript content chunks into
document_chunks. - Meeting participants and title drive project attribution.
- Extract decisions, commitments, open questions, schedule risk, financial exposure, and owner/action signals.
- Promote supported items to cards only when an evidence excerpt exists.
- Later user corrections write
ai_feedback_events,ai_retrieval_feedback, and candidate promotions when repeated or high-impact.
User Chat And AI Assistant
- User message enters
frontend/src/app/api/ai-assistant/chat/route.ts. - Intent chooses packet-first advisor path, source lookup path, action/tool path, or memory path.
- Assistant metadata records tool trace, retrieved sources, response quality, data parts/widgets, and selected learnings.
- Post-response jobs run conversation memory extraction, learning usage recording, and retrieval trace recording.
- User feedback, edit, regeneration, copied answer, accepted widget, or ignored action writes
ai_feedback_events. - Approved promotions write to
agent_learnings,ai_memories, or a domain table.
Task Generation
- Assistant proposes or creates a task through action tools.
- Task snapshot is captured in
ai_task_feedbackwhen user rates it. - Good feedback can become a promoted positive example after review.
- Bad feedback creates or updates an
agent_learningscandidate with a prevention prompt. - Future task creation pulls promoted positive examples, active agent learnings, and current project packet/source evidence.
Project Intelligence Pages
- User views a packet, opens a card, expands evidence, follows source links, or marks a card wrong/stale/useful.
- Each meaningful interaction writes
ai_feedback_events. - Card corrections update
intelligence_reviews. - Approved corrections update cards, evidence, or attribution candidates.
- Packet refresh regenerates the target packet and records why.
Feedback Events To Capture First
Promotion Rules
Feedback is evidence, not learning. A feedback event becomes durable behavior only after one of these paths:- Human review approves it.
- The same failure repeats at least twice with similar signatures.
- A high-confidence workflow outcome proves it worked.
- A deterministic eval fails and maps to a clear prevention rule.
Promote To agent_learnings
Promote repeatable AI behavior failures when feedback identifies a concrete failure pattern, includes tool trace and response evidence, and produces an actionable prevention prompt.
Do not promote when the root cause is missing data ingestion, schema/API/frontend code, or a one-off mood signal without example.
Promote To ai_memories
Promote stable facts, preferences, lessons, commitments, and context when they are useful across future sessions, user-stated or source-supported, and scoped to the correct visibility.
Do not promote transient requests, guesses from weak retrieval, private preferences as team memory, or source facts that belong in project records.
Promote Positive Task Examples
Useai_task_feedback.promoted = true only when the task was rated good, complete enough to reuse, not duplicate/noise, and either completed or admin-approved.
Inject no more than three positive examples into task generation.
Promote Retrieval Weight
Promote retrieval ranking changes only after aggregation. Down-rank wrong-project, stale, unsupported, or weakly aligned chunks, but never hide a source because one answer failed.Promote Attribution Rules
Promote project-linking rules only when the correction has clear evidence, the alias/path/participant pattern recurs, and no competing project has similar confidence. Do not globally lower confidence thresholds to increase coverage.Promote Packet Rules
Promote packet behavior when users repeatedly mark a card type useful/stale/wrong, owner-facing summaries are edited consistently, or packet source coverage misses available data. Examples:- Put financial exposure before schedule commentary for owner updates.
- Do not show Teams-only risk as high confidence without a confirming source.
- Move stale cards older than 14 days without new evidence below active blockers.
Fail-Loud Rules
Verification Gates To Build First
Gate 1: Schema And RLS
ai_feedback_events,ai_learning_promotions, andai_retrieval_feedbackexist in generated types.- FK types match actual tables:
projects.idis integer,document_metadata.idis text,document_chunks.chunk_idis text, packet/card IDs are uuid. - anon/authenticated cannot read private feedback from other users.
- service role can insert events and promotions.
Gate 2: Feedback Event Writer
- assistant thumbs down writes the existing chat feedback path if still used and always writes
ai_feedback_events - task feedback writes
ai_task_feedbackand a normalized event - packet/card feedback writes
intelligence_reviewsand a normalized event - failures return generic-free error messages with table and cause
Gate 3: Retrieval Trace
- every source lookup answer records tool name, query, source document IDs, chunk IDs, rank, cited flag, and answer usage
- downvoted source-grounded answers mark involved chunks as
unknownorunhelpful, not bad forever - source lookup questions do not answer from packet summary alone
Gate 4: Promotion Queue
- one-off thumbs-down creates candidate only
- repeated similar thumbs-down promotes to
agent_learnings.status = activeonly when threshold is met - approved positive task feedback becomes a future few-shot example
- rejected/expired/superseded promotions are not injected
Gate 5: Packet Improvement Loop
- correcting a card creates a review item and feedback event
- approving correction updates card/evidence and enqueues packet refresh
- refreshed packet includes changed card ranking/status
- stale/missing source coverage is visible in packet JSON
Gate 6: Assistant Prompt Injection Safety
agent_learningscontext is scoped by project/tool/tags- private
ai_memoriesare only injected for the owning user - team memories are not created from low-confidence private preferences
- max learning context stays bounded
- injected learning usage is recorded in
agent_learning_usages
First Implementation Order
Implemented Retrieval Learning Loop
The first completed loop is retrieval learning. It does not retrain a model. It captures which sources/chunks helped or hurt assistant answers, promotes repeated patterns into reviewable candidates, and applies bounded ranking hints only after admin approval.Implemented Data Model
Implemented Admin Surface
Route:/ai-learning-promotions
The page includes:
- status tabs for candidate, approved, applied, rejected, and superseded promotions
- metrics for candidates, approvals, applied learnings, active/paused weights, superseded promotions, and audit activity
- Generate action for retrieval promotion scans
- approve/reject controls
- impact preview for retrieval-weight promotions
- apply, pause, resume, and supersede controls
- learning activity feed backed by
ai_feedback_events
Implemented Flow
Current Safety Rules
- No ranking hint is active until admin approval and apply.
- Candidate generation requires repeated grouped signals.
- Boosts require repeated helpful/cited/used signals without problem signals.
- Problem candidates come from repeated unhelpful, wrong-project, stale, or unsupported outcomes.
- Multipliers are bounded between
0.65and1.5. - Paused and superseded weights are ignored by semantic search.
- Lifecycle actions are auditable in
ai_feedback_events.
Current Verification
- route conflict check
- focused ESLint
- focused TypeScript filtering for touched self-learning files
- unit guardrail for retrieval-weight scoring behavior
Remaining Gaps
- Browser-level smoke test for generate -> approve -> preview -> apply -> pause/resume.
- Live semantic-search replay preview.
- Destination writers for
agent_learnings,ai_memories, task examples, and attribution rules. - Packet/card feedback loop.
- Add
ai_feedback_events,ai_learning_promotions, andai_retrieval_feedback. - Add
frontend/src/lib/ai/services/feedback-event-service.ts. - Wire assistant thumbs, task feedback, and packet/card feedback into normalized events.
- Add central retrieval trace capture.
- Add promotion review and destination writers for
agent_learnings,ai_memories, task examples, and attribution candidates. - Extend task generation with approved positive examples and active prevention prompts.
- Add packet card feedback after the event and promotion infrastructure is proven.
Product Behavior Rules
- Feedback capture must be available in normal product surfaces, not only chat.
- The assistant must say when it is using memory versus source truth.
- Human-approved project facts should become project intelligence, not private memory.
- Personal preferences should not change team-visible outputs unless explicitly promoted.
- Financial, legal, contractual, and client-facing outputs require evidence and review before learning changes behavior.
- The system should prefer a missing-data warning over confident unsupported advice.
Open Questions
- Which admin surface should own promotion review: existing feedback inbox, Project Intelligence review queue, or a dedicated AI Training page?
- Should
ai_feedback_events.session_idusechat_history.session_idUUID only, or support text session IDs from older paths? - Which events should be visible to non-admin project members?
- What is the first owner-facing output to learn from edits: Project Status Report, owner update email, or packet executive summary?
- How long should low-confidence attribution candidates stay active before archiving?
Recommended First Build
Start with the smallest complete loop:- Add
ai_feedback_eventsand write to it from task feedback and assistant thumbs. - Add
ai_retrieval_feedbackand record source/chunk usage for source lookup answers. - Add
ai_learning_promotionsand promote only reviewed/repeated failures intoagent_learnings. - Extend task generation to use approved positive examples and active prevention prompts.
- Add packet card feedback after the event and promotion infrastructure is proven.