Download the PHP package strtob/yii2-ollama without Composer
On this page you can find all versions of the php package strtob/yii2-ollama. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download strtob/yii2-ollama
More information about strtob/yii2-ollama
Files in strtob/yii2-ollama
Package yii2-ollama
Short Description Yii2 component for Ollama API with optional vector DB support (Qdrant)
License MIT
Informations about the package yii2-ollama
Yii2 Ollama Component
Yii2 component for Ollama API with optional vector database support (e.g., Qdrant) for Retrieval-Augmented Generation (RAG).
Features
- Connect to Ollama API (
llama2,mistral,gemma) - Optional vector DB integration for context injection
- Supports Yii2 HTTP Client
- Easy configuration via Yii2 components
- Multilingual exception messages (
Yii::t()) - Events support:
beforeGenerate,afterGenerate,generateError - Request and User automatically included in events for easy logging and auditing
Installation
Install via Composer:
Ensure you have yiisoft/yii2-httpclient and a Qdrant PHP client installed if you want vector DB support.
Migration:
Configuration
Example config/web.php using a Qdrant adapter:
Usage in Controller
Stream Modus
See example:
Yii2 Ollama Component – Events
OllamaComponent supports three main events during generation:
| Event | When Triggered | Data Included |
|---|---|---|
beforeGenerate |
Before sending a request to the Ollama API | prompt, options, request, user |
afterGenerate |
After receiving a successful response | prompt, options, request, user, response |
generateError |
When an exception occurs during generation | prompt, options, request, user, exception |
Event Data Details
- Connect to Ollama API (
llama2,mistral,gemma) - Optional vector DB integration for context injection
- Supports Yii2 HTTP Client
- Embedding generation (
embedText) - Easy configuration via Yii2 components
- Multilingual exception messages (
Yii::t()) - Events support:
beforeGenerate,afterGenerate,generateError - Request and User automatically included in events for easy logging and auditing
Example Usage
Embedding Generation Usage
Document Model (ActiveRecord with Vector DB)
You can use an ActiveRecord model to handle documents and automatically generate embeddings for them in your vector database. Supports PDF, TXT, DOCX uploads.
How It Works
- beforeSave() – Converts PDFs to text or reads uploaded TXT/DOCX.
- afterSave() – Generates embeddings using VectorizerHelper and stores them in the vector database.
- afterDelete() – Removes corresponding vectors from the vector database.
This makes your document storage fully RAG-ready, automatically connecting your database records with vector embeddings.
Vector DB Support
Implement the VectorDbInterface to use any vector database. Example Qdrant adapter:
OllamaComponent will automatically prepend top-K context from the vector DB to the prompt.
Supported LLM Models so far
llama2mistralgemma
License
MIT License – see LICENSE
All versions of yii2-ollama with dependencies
yiisoft/yii2 Version ^2.1
yiisoft/yii2-httpclient Version ^2.0
qdrant/qdrant-php Version ^1.0