How heruafandi06/laravel-sage works
Laravel Sage is a Laravel package for asking natural-language questions over ingested PDF and Markdown documents, using Gemini for embeddings and answer generation. The main workflow is document extraction and chunking, embedding and vector-store persistence, then question embedding, similarity search, and answer generation. The README also documents multi-turn chat with query rewriting and stored history, plus file, MySQL, and pgvector drivers. The sampled source shows these runtime paths; relationships for the unsampled driver internals are limited to the documented/provider-selected driver choices.
Main entry points: VectorStore.php Vector store contract · RagService.php RAG service · IngestCommand.php Ingest command · FileVectorStore.php File vector driver
Components 16
Document ingestion
- Ingest command
src/Commands/IngestCommand.php - Text splitter
src/Services/TextSplitter.php
Question answering
- RAG service
src/Services/RagService.php
Vector storage
- Vector store contract
src/Contracts/VectorStore.php - File vector driver
src/Drivers/FileVectorStore.php - MySQL vector driver
src/Drivers/MySqlVectorStore.php - Pgvector driver
src/Drivers/PgvectorStore.php - Cosine similarity
src/Support/VectorHelper.php
Laravel integration
- Sage facade
src/Facades/Sage.php - Service provider
src/SageServiceProvider.php - Package config
config/sage.php
Other components
- Application user
- PDF and Markdown
- Vector data
- Chat history
- Google Gemini
Connections 20
- Application user → Sage facade: asks via
README.md - Sage facade → RAG service: resolves service
src/SageServiceProvider.php - Service provider → RAG service: constructs
src/SageServiceProvider.php - Service provider → Vector store contract: binds implementation
src/SageServiceProvider.php - Package config → Service provider: configures
src/SageServiceProvider.php - PDF and Markdown → Ingest command: provides files
src/Commands/IngestCommand.php - Ingest command → Text splitter: splits text
src/Commands/IngestCommand.php - Ingest command → Google Gemini: requests embeddings
src/Commands/IngestCommand.php - Ingest command → Vector store contract: saves vectors
src/Commands/IngestCommand.php - RAG service → Chat history: reads and writes
src/Services/RagService.php - RAG service → Google Gemini: embeds and generates
src/Services/RagService.php - RAG service → Vector store contract: searches vectors
src/Services/RagService.php - Vector store contract → File vector driver: implemented by
src/Drivers/FileVectorStore.php - Vector store contract → MySQL vector driver: implemented by
src/Drivers/MySqlVectorStore.php - Vector store contract → Pgvector driver: implemented by
src/Drivers/PgvectorStore.php - File vector driver → Vector data: reads and writes
src/Drivers/FileVectorStore.php - MySQL vector driver → Vector data: reads and writes
src/Drivers/MySqlVectorStore.php - Pgvector driver → Vector data: reads and writes
src/Drivers/PgvectorStore.php - File vector driver → Cosine similarity: scores vectors
src/Drivers/FileVectorStore.php - MySQL vector driver → Cosine similarity: scores vectors
src/Drivers/MySqlVectorStore.php