The RAG (Retrieval-Augmented Generation) layer enriches every AI response with content from the knowledge base. Rather than relying on pure semantic similarity, the system uses a hybrid scoring algorithm that balances how relevant an article is to the query, how recently it was added, and a manually configurable importance weight — so that critical support articles consistently surface above older or lower-priority content.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/yocxy2/2a/llms.txt
Use this file to discover all available pages before exploring further.
Hybrid scoring formula
Every candidate article retrieved by pgvector is assigned a final hybrid score before the result set is ranked:Vector Similarity (80%)
Vector Similarity (80%)
Computed by pgvector using cosine distance between the query embedding and each article’s stored embedding:A value of
1.0 means identical vectors; 0.0 means orthogonal. The raw cosine similarity is multiplied by 0.8 in the hybrid formula, making semantic relevance the dominant factor.Recency Score (20%)
Recency Score (20%)
Newer articles score higher. The score decays linearly from The recency score is multiplied by 0.2, so it can only shift the final ranking for articles that are already semantically close to the query.
1.0 to 0.0 over 365 days and is floored at 0.0 for articles older than one year:Importance Weight
Importance Weight
A manual float multiplier stored per article in the database. It defaults to Set critical articles to a higher importance value (for example,
1.0. The importance weight is applied to the entire recency contribution:1.8) to ensure they rank above semantically similar but lower-priority articles, regardless of age.limit articles (default 3) are returned.
Knowledge base schema
Theknowledge_base table is defined in prisma/schema.prisma. The embedding column uses the vector(1536) type provided by the pgvector extension.
embedding IS NULL) are excluded from search results. Always use addKnowledgeArticle() rather than inserting rows directly — it generates and stores the embedding automatically.
KnowledgeArticle interface
The TypeScript interface used throughoutragService.ts to represent a retrieved article. The similarity and hybridScore fields are populated during search; importance is read from the database.
Default knowledge base
On first run,initializeKnowledgeBase() seeds the knowledge base with five articles covering the most common support categories. Each article is embedded and stored with the default importance of 1.0.
| Title | Category |
|---|---|
| How to request a refund | Returns |
| Payment methods accepted | Billing |
| Track your order | Shipping |
| Reset your password | Account |
| Website not loading | Technical |
Adding articles programmatically
UseaddKnowledgeArticle() from src/services/ragService.ts to insert new articles. The function generates the embedding from content automatically before writing to the database.