Knowledge Layer (v0.3 foundation)
Knowledge Layer (v0.3 foundation) Purpose The knowledge layer retrieves relevant site content for prompt augmentation (RAG). It follows the Clean Architecture contracts in 02-system-architecture-prompt.md while reusing the existing embeddings stack through a…
Knowledge Layer (v0.3 foundation)#
Purpose#
The knowledge layer retrieves relevant site content for prompt augmentation (RAG).
It follows the Clean Architecture contracts in 02-system-architecture-prompt.md
while reusing the existing embeddings stack through a legacy adapter.
Current Scope#
- Domain contract:
KnowledgeRetrieverInterface - Value object:
KnowledgeChunkwith optional source URL for citations - Application use case:
RetrieveKnowledgeContext - Public widget grounding:
PublicKnowledgeGroundingPolicy(sources-only when RAG enabled) - Legacy adapter:
LegacyRagKnowledgeRetriever->RagService - Used by legacy
ChatServicefor public widget + agentSendChatMessagefor admin (both returnsources) - Indexed content types: posts, pages, extra public CPT (
rag_indexable_post_types/teddy_indexable_post_types), WooCommerce products, PDF/CSV media uploads - Large catalogs: cursor option
teddy_rag_ingest_cursorbatches 25 items per cron tick; phases includeuploads; filtersteddy_indexable_products,teddy_indexable_posts,teddy_indexable_upload_mimes - Enrichment:
KnowledgeContentEnricher(ACF + Elementor) +UploadDocumentExtractor(PDF/CSV) - Admin: Settings knowledge panel + REST
GET/POST /knowledge/status|reindex|ingest; Settings UI upload for PDF/CSV - SEO domain tools:
seo.meta.generate,seo.article.write,seo.article.audit
Feature Flag#
- Setting key:
enable_rag - Default:
false
When RAG is first enabled, a background reindex is scheduled (~15s). Admins can also click Rebuild knowledge index now on Settings.
Main Classes#
src/Domain/Knowledge/KnowledgeChunk.phpsrc/Domain/Knowledge/KnowledgeRetrieverInterface.phpsrc/Application/Knowledge/KnowledgePromptComposer.phpsrc/Application/Knowledge/PublicKnowledgeGroundingPolicy.phpsrc/Application/UseCase/RetrieveKnowledgeContext.phpsrc/Infrastructure/Knowledge/LegacyRagKnowledgeRetriever.phpsrc/Services/RagService.php(search()+augment())src/REST/KnowledgeController.php
Verification#
- Unit tests:
tests/Unit/KnowledgePromptComposerTest.php,tests/Unit/PublicKnowledgeGroundingPolicyTest.php,tests/Unit/MarkdownToHtmlTest.php - Integration:
tests/Integration/RagServiceCursorTest.php(1000-product cursor simulation) - E2E:
tests/e2e-rag.php,tests/e2e-rag-scale.php - Playwright admin smoke:
TEDDY_E2E_PASS=*** npm run test:e2e:playwright(optionalTEDDY_E2E_USER, defaultvinhnx) - Static analysis:
composer phpstan