Skip to main content
JW

Building a RAG chatbot with Laravel and OpenAI - my approach

James Wilson AI & Machine Learning 406 views
I just finished building a RAG (Retrieval-Augmented Generation) chatbot using Laravel as the backend and wanted to share my architecture. Stack: - Laravel 11 for the API and admin panel - OpenAI GPT-4 for generation - Pinecone for vector storage - Laravel Horizon for async embedding jobs How it works: 1. Admin uploads documents via Filament panel 2. A queued job chunks the document and generates embeddings via OpenAI 3. Embeddings stored in Pinecone with metadata 4. User asks a question, relevant chunks retrieved, sent as context to GPT-4 Key learnings: - Chunk size of 500 tokens with 50-token overlap works best for my use case - Always include source attribution in responses for trust - Cache frequent queries in Redis to save API costs Happy to answer questions about the implementation.

3 Replies

Best Answer
AK
Aisha Khan 4 months ago
Nice architecture James! A few suggestions from my experience: 1. Chunk overlap is critical. 50 tokens is good, I have found 10-15% overlap works well in general. 2. Hybrid search. Combine vector similarity with keyword matching (BM25) for better retrieval results. 3. Re-ranking. After retrieval, re-rank chunks by relevance before sending to the LLM. Also, have you considered using pgvector instead of Pinecone? It keeps everything in PostgreSQL and avoids another external SaaS dependency.
SM
Sofia Martinez 4 months ago
This is exactly what I want to build! Quick question: how do you handle document updates? If a document changes, do you re-embed the entire thing or just the modified chunks?
JW
James Wilson 4 months ago
Good question Sofia! I delete all chunks for that document and re-embed entirely. Trying to diff individual chunks gets complicated fast because chunk boundaries might shift when content changes. The re-embedding cost is minimal with batched API calls, about $0.01 per 100 pages of text.

Post a Reply

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support