symfony/ai-click-house-store
ClickHouse vector store integration for Symfony AI Store. Store and query embeddings in ClickHouse using distance functions and ANN/vector indexes for fast similarity search. Links to ClickHouse docs plus Symfony AI contributing and issue tracker.
StoreInterface, enabling seamless integration with Laravel applications using Symfony components. This reduces coupling with proprietary vector stores (e.g., Pinecone) and aligns with Laravel’s ecosystem for AI/ML workloads.INSERT or COPY).Potential Misalignments:
ASYNC keyword) are not exposed, which may limit throughput for high-QPS applications.Array(Float32) columns and ANN indexes), which may not suit teams preferring schema-less or auto-scaling solutions.StoreInterface. For Laravel, use Symfony’s DI container or bind the store manually in Laravel’s service container.SELECT version(); -- Should return >= 22.8
SHOW CREATE TABLE system.tables; -- Check for ANN index support
clickhouse/client or HTTP driver).CREATE TABLE vector_store (
id UInt64,
embedding Array(Float32), -- Must match embedding dimensionality (e.g., 768)
metadata String,
INDEX ann_index embedding TYPE ann(768) GRANULARITY=3
) ENGINE = MergeTree() ORDER BY id;
DoctrineStore):
$vectors = $currentStore->findAll();
INSERT INTO vector_store (id, embedding, metadata)
VALUES (1, [0.1, 0.2, ...], '{"category": "tech"}');
// config/ai.php
'stores' => [
'clickhouse' => [
'dsn' => 'http://clickhouse:8123',
'table' => 'vector_store',
'embedding_column' => 'embedding',
],
],
Key Dependencies:
| Dependency | Version | Risk | Notes |
|---|---|---|---|
symfony/ai |
^0.8.0 | High | Pin to avoid breaking changes. |
clickhouse/client |
^1.0 | Low | Fallback to HTTP driver if needed. |
| ClickHouse | v22.8+ | Critical | ANN indexes require this version. |
| PHP | 8.1+ | Medium | Symfony AI’s minimum requirement. |
| Risk Area | Description | Mitigation Strategy |
|---|---|---|
| Schema Errors | Incorrect Array(Float32) definition or ANN index misconfiguration → queries fail silently. |
Validate schema with a test dataset and use DESCRIBE TABLE to verify structure. |
| Performance Bottlenecks | Poor ANN index settings (e.g., GRANULARITY=1000 for 768D vectors) → degraded recall. |
Benchmark with system.asynchronous_metrics; adjust GRANULARITY/GRAPH_SIZE based on query patterns. |
| Symfony AI Updates | Breaking changes in StoreInterface or Symfony AI’s DI integration. |
Pin to a stable version (e.g., symfony/ai:0.8.0) and test against minor updates in CI. |
| ClickHouse Failures | Network issues or server downtime → no built-in retry logic. | Implement exponential backoff in Laravel’s HTTP client or use a circuit breaker (e.g., Spatie’s). |
| Vector Size Limits | ClickHouse’s Array(Float32) has a 65K-element limit (may fail for >65K-dimensional embeddings). |
Use compression (e.g., Float32 → Float16) or split embeddings into multiple columns if needed. |
| Cold Starts | First query after idle may be slow due to ANN index warmup. | Pre-warm indexes with a background job or use ClickHouse’s SYSTEM RESTART for critical workloads. |
| Cost Overruns | Unexpected ClickHouse resource usage (CPU/memory) for large-scale ANN searches. | Monitor system.metrics and set query timeouts (e.g., max_execution_time=5). |
Laravel/Symfony Alignment:
StoreInterface, making it a drop-in replacement for existing stores (e.g., DoctrineStore, RedisStore). For Laravel, integrate via:
$app->bind('ai.store', function ($app) {
return new \Symfony\Component\AI\Store\ClickHouseStore(
$app['config']['ai.stores.clickhouse']
);
});
// config/ai.php
'stores' => [
'clickhouse' => [
'dsn' => 'http://clickhouse:8123',
'table' => 'vector_store',
'embedding_column' => 'embedding',
'timeout' => 5.0, // seconds
],
],
ClickHouse Compatibility:
clickhouse/client (recommended for performance).Array(Float32) (e.g., embedding Array(Float32)).TYPE ann(768) GRANULARITY=3).SELECT * FROM vectors ORDER BY vector_distance(embedding, [0.1, 0.2, ...]) LIMIT 10.SELECT * FROM vectors WHERE metadata LIKE '%tech%' ORDER BY vector_distance(...) LIMIT 10.Laravel-Specific Considerations:
monolog).How can I help you explore Laravel packages today?