Portfolio

Engineering notes

Keeping a RAG portfolio assistant in sync with Supabase

How this portfolio connects Supabase, Gemini embeddings, Pinecone, and Groq, including content updates, stale vectors, and cache limitations.

By Vincent Teo · Updated

Start with the same content source

This portfolio has two ways to explore the same background: a website and an AI assistant. Maintaining a separate copy of the content for each creates a freshness problem. A project can appear on the website while the assistant continues to answer from an older description.

The implementation reads the public portfolio tables in Supabase for both uses. Next.js renders the website from those records. A FastAPI service turns the records into question-and-answer entries for retrieval. The data includes the profile, education, work experience, projects, research, and final year project. Visitor messages and meeting requests are excluded from this knowledge base.

What happens after an edit

After a successful project save, a Next.js server action schedules a sync with after(). The visitor-facing save response does not have to wait for embedding requests. The backend webhook checks a shared secret before reading the content tables and generating new vectors.

Each knowledge entry has an ID derived from its category and question. Editing the answer updates the existing vector. Renaming a project can change its generated question and therefore its ID. The sync removes IDs absent from the new content set, so deleted or renamed entries do not remain indefinitely in retrieval results.

The route refuses to sync an empty content set, and a failed Supabase read aborts before cleanup. These checks matter because deleting every vector after a failed read would turn a temporary content error into an empty knowledge base.

Keep the retrieval units useful

Short portfolio entries are embedded as complete records using Gemini. Longer case studies are separated into their named sections, each carrying a link to the corresponding heading. That gives a question about limitations a more specific source than one vector representing the entire project.

At question time, the backend embeds the query, asks Pinecone for nearby entries, applies a similarity threshold, and sends the retrieved context to Groq. The widget streams the answer and displays supporting links. A source link helps a visitor inspect the evidence; it does not prove that every generated claim is supported.

Tradeoffs I would measure next

The current sync re-embeds the content on each run. This is easy to follow for a small portfolio, but a growing knowledge base would benefit from comparing content hashes and updating only changed entries. Concurrent sync jobs also deserve explicit coordination before scaling the service.

Answers use an in-memory cache, which is cleared by the process handling a successful sync. A deployment with multiple workers would need shared invalidation or versioned cache keys to keep every worker current. The update process is also not a transactional switch between complete index versions; an interrupted sync can require a retry.

The useful next measurements are sync duration, embedding requests per edit, retrieval quality after an update, and the time until changed content appears in an answer. These are proposed measurements, not published benchmark results.

Analytics cookies

I'd like to use Google Analytics to see which pages are useful. It sets cookies and is off unless you accept. Privacy policy