|
| 1 | +# RAG Vector Search with AI - Presentation Demo |
| 2 | + |
| 3 | +This is a comprehensive demonstration of a modern RAG (Retrieval-Augmented Generation) system built with PHP, showcasing intelligent product search using vector embeddings and local AI models. |
| 4 | + |
| 5 | +## System Overview |
| 6 | + |
| 7 | +**Technologies:** |
| 8 | +- PHP 8.3 + Symfony 7.3 (MicroKernelTrait) |
| 9 | +- Qdrant Vector Database |
| 10 | +- Transformers PHP (local embeddings) |
| 11 | +- Ollama + Llama 3.2 (local AI model) |
| 12 | +- Docker for services |
| 13 | + |
| 14 | +**Key Features:** |
| 15 | +- 🔍 **Semantic Search** - Vector similarity search in Russian/English |
| 16 | +- 🤖 **AI Query Analysis** - Natural language understanding with Llama 3.2 |
| 17 | +- 💬 **Interactive Chat** - Conversational product discovery |
| 18 | +- 🚀 **Memory Optimized** - Generator-based processing for large datasets |
| 19 | +- 💰 **Cost Efficient** - 100% local, no API costs |
| 20 | + |
| 21 | +## Demo Commands |
| 22 | + |
| 23 | +### Basic Setup |
| 24 | +```bash |
| 25 | +docker-compose up -d # Start Qdrant |
| 26 | +ollama pull llama3.2:1b # Download AI model |
| 27 | +php bin/console products:vectorize # Index products (one time) |
| 28 | +``` |
| 29 | + |
| 30 | +### Search Demonstrations |
| 31 | +```bash |
| 32 | +# Traditional search (English only) |
| 33 | +php bin/console products:search "AMD processor" |
| 34 | + |
| 35 | +# Russian search with translation |
| 36 | +php bin/console products:search-ru "процессор AMD" |
| 37 | + |
| 38 | +# AI-powered natural language search |
| 39 | +php bin/console products:search-ai "ищу мощный процессор для игр" |
| 40 | + |
| 41 | +# Interactive AI chat (main demo!) |
| 42 | +php bin/console products:chat |
| 43 | + |
| 44 | +# 🆕 NEW! Improved RAG Architecture Demo |
| 45 | +php bin/console rag:demo --query "процессор AMD для игр" # Single query with detailed steps |
| 46 | +php bin/console rag:demo --interactive # Interactive RAG chat |
| 47 | +``` |
| 48 | + |
| 49 | +## Architecture Highlights |
| 50 | + |
| 51 | +### Traditional Pipeline |
| 52 | +1. **Vector Embeddings**: Product descriptions → 384-dim vectors via all-MiniLM-L6-v2 |
| 53 | +2. **AI Query Processing**: Russian queries → optimized English search terms via Llama 3.2 |
| 54 | +3. **Semantic Retrieval**: Cosine similarity search in Qdrant with configurable thresholds |
| 55 | +4. **AI Response Generation**: Personalized recommendations based on search results |
| 56 | + |
| 57 | +### 🆕 Improved RAG Architecture (Recommended by Curator) |
| 58 | +**Three Clear Stages:** |
| 59 | + |
| 60 | +1. **📝 Query Processing (Авторизация запроса)** |
| 61 | + - Natural language analysis with Llama 3.2 |
| 62 | + - Query optimization for better search results |
| 63 | + - Vector embedding generation (384-dimensional) |
| 64 | + |
| 65 | +2. **🔍 Retrieval (Поиск в векторной БД)** |
| 66 | + - Semantic search in Qdrant vector database |
| 67 | + - Cosine similarity matching with relevance threshold |
| 68 | + - Context preparation for LLM |
| 69 | + |
| 70 | +3. **✨ Generation (Ограниченная генерация)** |
| 71 | + - LLM works ONLY with retrieved documents |
| 72 | + - No "hallucination" - strictly based on found products |
| 73 | + - Constrained response generation with improved prompts |
| 74 | + |
| 75 | +**Key Improvements**: |
| 76 | +- LLM never invents products or adds information "from itself" - it only works with the actual search results from the vector database |
| 77 | +- **Critical**: All vectorization (both indexing and search) uses identical `Task::Embeddings` with `all-MiniLM-L6-v2` model for perfect semantic consistency |
| 78 | +- Proper embedding consistency ensures accurate similarity matching between queries and stored products |
| 79 | + |
| 80 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 81 | + |
| 82 | +## Development Commands |
| 83 | + |
| 84 | +### Dependency Management |
| 85 | +- `composer install` - Install PHP dependencies |
| 86 | +- `composer update` - Update dependencies |
| 87 | + |
| 88 | +### Symfony Console |
| 89 | +- `php bin/console` - Access Symfony console commands |
| 90 | +- `php bin/console cache:clear` - Clear application cache |
| 91 | +- `php bin/console debug:router` - Show all routes |
| 92 | +- `php bin/console debug:container` - Debug service container |
| 93 | + |
| 94 | +### Development Server |
| 95 | +- `symfony serve` or `php -S localhost:8000 -t public/` - Start development server |
| 96 | + |
| 97 | +### Docker Services |
| 98 | +- `docker-compose up -d` - Start Qdrant vector database |
| 99 | +- `docker-compose down` - Stop all services |
| 100 | +- `docker-compose logs qdrant` - View Qdrant logs |
| 101 | + |
| 102 | +### Qdrant Vector Database |
| 103 | +- HTTP API: `http://localhost:6333` |
| 104 | +- gRPC API: `localhost:6334` |
| 105 | +- Web UI: `http://localhost:6333/dashboard` |
| 106 | + |
| 107 | +## Architecture Overview |
| 108 | + |
| 109 | +This is a Symfony 7.3 application using the MicroKernelTrait for minimal setup. |
| 110 | + |
| 111 | +### Key Components |
| 112 | +- **Kernel**: Uses `MicroKernelTrait` for streamlined configuration |
| 113 | +- **Controllers**: Located in `src/Controller/` with attribute-based routing |
| 114 | +- **Services**: Auto-configured in `config/services.yaml` with autowiring enabled |
| 115 | +- **Configuration**: YAML-based configuration in `config/` directory |
| 116 | + |
| 117 | +### Directory Structure |
| 118 | +- `src/` - Application source code (PSR-4 autoloaded as `App\` namespace) |
| 119 | +- `config/` - Application configuration files |
| 120 | +- `public/` - Web root with front controller (`index.php`) |
| 121 | +- `bin/console` - Symfony console entry point |
| 122 | +- `var/cache/` - Application cache files |
| 123 | +- `vendor/` - Composer dependencies |
| 124 | + |
| 125 | +### Configuration Notes |
| 126 | +- Services use autowiring and autoconfiguration by default |
| 127 | +- Controllers are automatically registered via attribute routing |
| 128 | +- Framework configuration is split across files in `config/packages/` |
| 129 | +- Routes are configured in `config/routes.yaml` and via controller attributes |
0 commit comments