Feature ID: PF-61Documentation Index
Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
Use this file to discover all available pages before exploring further.
Status: 📝 Planned
Created: 2026-01-28
Version: v1.0.0
Spec Reference:
specs/pf/specs/PF-61-knowledge-base-system.md (v1.0.0)
Version History
| Version | Date | Changes |
|---|---|---|
| v1.0.0 | 2026-01-28 | Initial integration documentation |
docs/VERSIONS.md for complete version history.
File Naming
This document follows the naming convention:{FEATURE_ID}-{FEATURE_NAME}-INTEGRATION.md
Document Structure
This integration document follows the standard structure:- Overview
- Integration Patterns
- Event Contracts
- API Contracts
- Platform Integration Layer
- Error Handling
- Security Considerations
- Performance Considerations
- Testing Requirements
- Future Enhancements
- References
Cross-References
- Spec:
specs/pf/specs/PF-61-knowledge-base-system.md(v1.0.0) - PF-60 Spec:
specs/pf/specs/PF-60-rag-infrastructure.md(v1.0.0) - PF-11 Spec:
specs/pf/specs/PF-11-document-management.md(v1.0.0) - Event Contracts:
docs/architecture/integrations/EVENT_CONTRACTS.md(v1.0.0) - API Contracts:
docs/architecture/integrations/API_CONTRACTS.md(v1.0.0) - Integration Matrix:
docs/architecture/integrations/CROSS_CORE_INTEGRATIONS.md(v1.0.0)
Quick Reference
| Integration Type | Pattern | Location | Status |
|---|---|---|---|
| PF-60 (RAG) | Event-Based | domain_events channel | 📝 Planned |
| PF-11 (Documents) | Platform Integration Layer | /src/platform/documents/ | 📝 Planned |
| PF-30 (Permissions) | Direct Dependency | Permission keys | 📝 Planned |
Decision Trees
Should I use PF-61 Knowledge Base?
| Condition | Decision |
|---|---|
| Need to curate AI training content | ✅ Use PF-61 |
| Need document embeddings | ✅ Use PF-60 (RAG) |
| Need document storage | ✅ Use PF-11 (Documents) |
Pattern Library
Event Publishing Pattern
Common Mistakes
| Mistake | Fix |
|---|---|
| Including PII/PHI in event payloads | Use only IDs, fetch details under RLS |
| Missing organization_id validation | Always validate with pf_has_org_access() |
| Direct HTTP calls for embeddings | Use event-based approach |
Pre-Flight Checklist
Before implementing PF-61 integrations:- Verify PF-60 (RAG Infrastructure) is available
- Verify PF-11 (Document Management) is available
- Review event contracts for correct payload structure
- Ensure RLS policies are in place
- Test event publishing and consumption
Overview
PF-61 Knowledge Base System provides an admin UI for curating and managing AI training content. It integrates with PF-60 (RAG Infrastructure) for embedding generation and PF-11 (Document Management) for document import.Integration Patterns
Pattern 1: Platform Integration Layer
PF-11 (Document Management) Integration:- Location:
/src/platform/documents/ - Usage: Document import feature
- Public API: Document selection and text extraction
- Status: 📝 Planned
Pattern 2: Event-Based Integration
PF-60 (RAG Infrastructure) Integration:- Events Published:
knowledge_article_published,knowledge_article_unpublished - Channel:
domain_events - Status: 📝 Planned
Direct Dependency
PF-60 (RAG Infrastructure):- Usage: Stores embeddings in
pf_document_embeddingstable - Edge Function:
generate-embeddingsfor embedding generation - Status: 📝 Planned
- Usage: Permission keys
pf.knowledge.viewandpf.knowledge.manage - Status: 📝 Planned
Event Contracts
Event: knowledge_article_published
Event: knowledge_article_publishedChannel:
domain_eventsPublisher: PF (PF-61)
Subscribers: PF-60 (RAG Infrastructure)
Status: 📝 Planned
Purpose
Notifies RAG infrastructure that a knowledge article has been published and is ready for embedding generation.Trigger Conditions
- Article status changes from
draftorin_reviewtopublishedvia UPDATE - Note: Event only fires on UPDATE operations when status changes to
published. The trigger is defined asAFTER UPDATEonly. Consumers must fetch article details (title, tags, category) under RLS usingarticle_id.
Payload Schema
organization_id and user_id for tenant isolation and audit purposes. Consumers must still fetch article details (title, tags, category) from pf_knowledge_base table using article_id and filter by organization_id under RLS policies.
Implementation
Consumer Actions
| Consumer | Action | Status |
|---|---|---|
| PF-60 (RAG Infrastructure) | Generate embeddings for published article | 📝 Planned |
| Event Consumer | Log to pf_audit_logs | ✅ Implemented |
Testing Requirements
- Event payload structure validation
- Event fires on publish
- Correct organization_id included
- PF-60 handles event correctly
Event: knowledge_article_unpublished
Event: knowledge_article_unpublishedChannel:
domain_eventsPublisher: PF (PF-61)
Subscribers: PF-60 (RAG Infrastructure)
Status: 📝 Planned
Purpose
Notifies RAG infrastructure to remove embeddings for an unpublished article.Trigger Conditions
- Article status changes from
publishedtodraft,in_review, orarchivedvia UPDATE - Note: Event only fires on UPDATE operations when status changes from
published. The trigger is defined asAFTER UPDATEonly. Consumers must fetch article details under RLS usingarticle_id.
Payload Schema
organization_id and user_id for tenant isolation and audit purposes. Consumers must filter by organization_id when processing events to enforce tenant boundaries.
Implementation
Consumer Actions
| Consumer | Action | Status |
|---|---|---|
| PF-60 (RAG Infrastructure) | Delete embeddings for unpublished article | 📝 Planned |
| Event Consumer | Log to pf_audit_logs | ✅ Implemented |
Testing Requirements
- Event payload structure validation
- Event fires on unpublish
- Correct organization_id included
- PF-60 handles event correctly
API Contracts
Database Function: Embedding Generation
Function:pf_knowledge_base_embedding_trigger()Provider: PF-61
Consumer: PF-60 (via trigger)
Status: 📝 Planned
Function Signature
Purpose
Triggers embedding generation when article is published. Currently uses direct HTTP call vianet.http_post extension, but should be replaced with event-based approach for better reliability.
Request Schema
Trigger Context (No Request Body):- Trigger fires automatically on INSERT/UPDATE when article status changes to
published - Trigger context provides:
NEW.id,NEW.organization_id,NEW.title,NEW.content,NEW.published_at
generate-embeddings Edge Function:
Response Schema
Success Response (200 OK):Fallback Queue Message Schema
Ifnet.http_post extension is not available, message is queued:
Failure Contract
If embedding generation fails:- Article remains
publishedbutis_indexedis set tofalse - Error details stored in
pf_knowledge_base.indexing_error(if column exists) - Retry mechanism available (manual or automatic after 5 minutes)
Implementation Notes
- Uses
net.http_postextension to call/functions/v1/generate-embeddingsedge function - Falls back to queue-based approach if extension not available
- Sets
is_indexed: falseif embedding generation fails - All requests include
organization_idfor tenant isolation
Platform Integration Layer
PF-11 (Document Management) Integration
Location:/src/platform/documents/Public API:
useDocuments()- List documentsuseDocument(id)- Get document detailsextractDocumentText(documentId)- Extract text content
Error Handling
Embedding Generation Failures
Scenario: Embedding generation fails during publish Handling:- Article is marked as
publishedbutis_indexed: false - Warning shown to admin
- Retry mechanism available (manual or automatic after 5 minutes)
- Error logged for debugging
Document Import Failures
Scenario: Document has no extractable text Handling:- Show clear error message to user
- Allow manual text entry as fallback
- Log error for debugging
Security Considerations
Multi-Tenant Isolation
- All events include
organization_idfor tenant isolation - RLS policies enforce organization boundaries
- Event payloads validated for organization context
PHI/PII Handling
- No PHI/PII in event payloads (only IDs)
- Knowledge content may contain sensitive info, but events only include metadata
- Access controls same as source documents
Performance Considerations
Event Processing
- Events are asynchronous (non-blocking)
- Embedding generation happens in background
- No impact on article publish performance
API Calls
- Document import uses existing PF-11 APIs
- No additional API overhead
- Caching used where appropriate
Testing Requirements
Integration Tests
- Event publishing on article publish
- Event publishing on article unpublish
- PF-60 receives and processes events
- Document import flow
- Embedding generation flow
RLS Tests
- Events include correct organization_id
- Cross-organization event isolation
- Permission checks for event triggers
Future Enhancements
Queue-Based Embedding Generation
Replace direct HTTP calls with queue-based approach:- Create
pf_embedding_queuetable - Background job processes queue
- Better reliability and retry handling
Event Versioning
- Support event schema versioning
- Backward compatibility for event consumers
References
- Spec:
specs/pf/specs/PF-61-knowledge-base-system.md - PF-60 Spec:
specs/pf/specs/PF-60-rag-infrastructure.md - PF-11 Spec:
specs/pf/specs/PF-11-document-management.md - Event Contracts:
docs/architecture/integrations/EVENT_CONTRACTS.md - Integration Matrix:
docs/architecture/integrations/CROSS_CORE_INTEGRATIONS.md
Last Updated: 2026-01-28