codewithkyrian/chromadb-php
PHP client for ChromaDB, making it easy to create collections, add and query embeddings, and manage documents/metadata from your Laravel or PHP apps. Lightweight API wrapper to integrate vector search and retrieval workflows without leaving PHP.
Record/ScoredRecord objects. This aligns perfectly with modern AI/ML workflows (e.g., RAG, semantic search) and hybrid search architectures.symfony/http-client).Where query builders).Record::make() and ScoredRecord classes simplify Eloquent-like interactions (e.g., Model::toRecord()).null/non-null embeddings, useful for incremental data pipelines.ChromaDB::local()/cloud()) allow pre-warming strategies.Record validation prevents malformed data ingestion.HttpClient (v6+) auto-discovery eliminates Guzzle conflicts.Where::field()->eq() integrates with Laravel’s query builder patterns.collection->add([Record1, Record2])).Record::make()->dispatch()).| Risk Area | Mitigation Strategy |
|---|---|
| Breaking Changes | Use the Migration Checklist to update imports/exceptions. |
| PSR-18 Dependency | Ensure Laravel’s symfony/http-client is installed (auto-discovered). Fallback to Guzzle if needed. |
| Chroma Cloud Costs | Monitor usage via Chroma’s API (e.g., collection->usage()) and set Laravel rate limits. |
| Partial Embeddings | Validate data before ingestion (e.g., Record::validate()). |
| Exception Handling | Update error handlers for renamed exceptions (e.g., NotFoundException instead of ChromaNotFoundException). |
| Local vs. Cloud Sync | Use Laravel’s config() to toggle environments (e.g., config('chromadb.env')). |
Record::make() interact with Laravel Eloquent? (e.g., Model::toRecord() trait?)Laravel Debugbar) will track ChromaDB API calls/usage?$this->app->singleton(ChromaDB::class, function () {
return config('chromadb.env') === 'cloud'
? ChromaDB::cloud()->withHeader('X-Chroma-Token', config('chromadb.token'))
: ChromaDB::local()->connect();
});
Chroma facade with cloud-specific methods (e.g., Chroma::forkCollection()).RecordInterface to the SDK’s Record class for testability.php-ai/php-ai for embedding generation (e.g., HuggingFaceEmbeddings::toRecord()).Nova::tools([new ChromaSearchTool()])).Schema::create('chromadb_collections', function (Blueprint $table) {
$table->string('name')->unique();
$table->integer('embedding_dimensions');
$table->json('metadata_schema');
$table->timestamps();
});
composer.json to ^1.0 and run composer update.ChromaDB::client() → ChromaDB::local()->connect()).use Exceptions\NotFoundException).ChromaDB::cloud().Record::make() for new embeddings.WHERE clauses to the type-safe Where builder.class ChromaScoutEngine extends Engine {
public function search($query) {
return ChromaDB::collection('products')
->query($query)
->asRecords()
->pluck('document');
}
}
Record::make($model->id)
->withDocument($model->content)
->dispatch(new GenerateEmbeddingJob($model));
^1.0 to avoid v2 API changes.composer require symfony/http-client.HttpClient facade for consistency:
ChromaDB::factory()->withHttpClient(app(HttpClient::class));
config/chromadb.php.ChromaService to handle retries/fallbacks:
public function search(string $query): array {
try {
return ChromaDB::collection('products')
->query($query)
->asRecords()
->toArray();
} catch (ConnectionException $e) {
return Cache::remember("fallback_$query", now()->addHour(), fn() => $this->fallbackSearch($query));
}
}
toRecord() methods to Eloquent models.Record validation (e.g., Record::validateEmbeddings()).Record objects in unit tests.Record batch operations (e.g., 1000 embeddings/second).composer why-not-update to track dependency risks.db/chromadb_migrations/ (e.g., 2025_01_01_create_user_embeddings.php).ChromaMigrator to sync Laravel migrations with ChromaDB:
public function migrateCollection(string $name, array $schema) {
ChromaDB::collection($name)->updateSchema($schema);
DB::table('chromadb_collections
How can I help you explore Laravel packages today?