Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ai Click House Store Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony AI Integration: The package provides a native bridge to Symfony AI’s 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.
  • ClickHouse as Vector Store: Leverages ClickHouse’s columnar storage, vector distance functions (L2, cosine, dot product), and Approximate Nearest Neighbor (ANN) indexes (HNSW, SCANN, QuantizedFlat). This is optimal for:
    • High-dimensional embeddings (e.g., 768D for LLMs, 384D for sentence transformers).
    • Hybrid search (vector similarity + SQL filtering on metadata).
    • Batch processing (e.g., ingesting millions of vectors daily via INSERT or COPY).
  • Cost Efficiency: Eliminates per-query fees (unlike Pinecone/Weaviate) and reduces infrastructure costs by consolidating vector storage with existing ClickHouse clusters (common in analytics-heavy applications).
  • Scalability: ClickHouse’s MergeTree engine handles write-heavy workloads (e.g., daily ingestion of 10M+ vectors) with sub-second latency for reads, making it suitable for real-time recommendation systems or semantic search.

Potential Misalignments:

  • OLAP vs. OLTP: ClickHouse is optimized for analytics (OLAP), not transactions (OLTP). Avoid if your use case requires ACID compliance or frequent small updates.
  • No Native Async: Symfony AI’s store interface is synchronous; ClickHouse’s async query capabilities (e.g., ASYNC keyword) are not exposed, which may limit throughput for high-QPS applications.
  • Schema Rigidity: Requires manual schema management (e.g., defining Array(Float32) columns and ANN indexes), which may not suit teams preferring schema-less or auto-scaling solutions.

Integration Feasibility

  • Stack Compatibility:
    • Laravel/Symfony: Works natively with Symfony AI’s StoreInterface. For Laravel, use Symfony’s DI container or bind the store manually in Laravel’s service container.
    • ClickHouse: Requires v22.8+ with vector/ANN support. Verify via:
      SELECT version(); -- Should return >= 22.8
      SHOW CREATE TABLE system.tables; -- Check for ANN index support
      
    • PHP: No additional extensions required (uses clickhouse/client or HTTP driver).
  • Migration Path:
    1. Schema Setup:
      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;
      
    2. Data Migration:
      • Export from existing store (e.g., DoctrineStore):
        $vectors = $currentStore->findAll();
        
      • Import to ClickHouse:
        INSERT INTO vector_store (id, embedding, metadata)
        VALUES (1, [0.1, 0.2, ...], '{"category": "tech"}');
        
    3. Laravel Configuration:
      // config/ai.php
      'stores' => [
        'clickhouse' => [
            'dsn' => 'http://clickhouse:8123',
            'table' => 'vector_store',
            'embedding_column' => 'embedding',
        ],
      ],
      
  • Sequencing:
    • Phase 1: Benchmark a subset of data (e.g., 10K vectors) against the current store to validate latency/cost.
    • Phase 2: Migrate non-critical workloads (e.g., staging environment) and monitor performance.
    • Phase 3: Full cutover with rollback plan (e.g., retain old store temporarily).

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.

Technical Risk

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., Float32Float16) 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).

Integration Approach

Stack Fit

  • Laravel/Symfony Alignment:

    • The package is designed for Symfony AI’s StoreInterface, making it a drop-in replacement for existing stores (e.g., DoctrineStore, RedisStore). For Laravel, integrate via:
      • Symfony’s DI Container: If using Symfony components in Laravel.
      • Manual Binding: Register the store in Laravel’s service container:
        $app->bind('ai.store', function ($app) {
            return new \Symfony\Component\AI\Store\ClickHouseStore(
                $app['config']['ai.stores.clickhouse']
            );
        });
        
    • Configuration: Use Laravel’s config system to define ClickHouse DSN, table name, and embedding column:
      // config/ai.php
      'stores' => [
          'clickhouse' => [
              'dsn' => 'http://clickhouse:8123',
              'table' => 'vector_store',
              'embedding_column' => 'embedding',
              'timeout' => 5.0, // seconds
          ],
      ],
      
  • ClickHouse Compatibility:

    • Driver Options:
      • Native Driver: clickhouse/client (recommended for performance).
      • HTTP Driver: Fallback if native driver is unavailable.
    • Schema Requirements:
      • Vectors must be stored as Array(Float32) (e.g., embedding Array(Float32)).
      • ANN indexes must be explicitly defined (e.g., TYPE ann(768) GRANULARITY=3).
    • Query Support:
      • Vector Search: SELECT * FROM vectors ORDER BY vector_distance(embedding, [0.1, 0.2, ...]) LIMIT 10.
      • Hybrid Search: SELECT * FROM vectors WHERE metadata LIKE '%tech%' ORDER BY vector_distance(...) LIMIT 10.
  • Laravel-Specific Considerations:

    • Queue Jobs: Use Laravel’s queues for batch operations (e.g., bulk inserts) to avoid timeouts.
    • Caching: Cache frequent queries (e.g., top-K recommendations) using Laravel’s cache system.
    • Logging: Integrate ClickHouse query logs with Laravel’s logging (e.g., monolog).

Migration Path

  1. Pre-Migration:
    • **
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky