JW
Building a RAG chatbot with Laravel and OpenAI - my approach
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.