symfony/ai-surreal-db-store
SurrealDB vector store integration for Symfony AI Store, enabling similarity search over embeddings using SurrealQL vector functions and MTREE/HNSW indexes.
count capabilities, which makes it practical to meter usage (documents/embeddings stored per tenant, per feature, per environment) — the missing piece for cost attribution and quota enforcement in multi-tenant AI products.VectorDocumentInterface strengthens this case: documents are now modeled against a shared contract rather than a SurrealDB-specific shape, so the cost of switching or adding a second backend later drops materially.VectorDocumentInterface gives us a backend-agnostic document model. Combined with count(), we can run the same feature code against SurrealDB and a comparison backend (pgvector) and measure corpus size + retrieval quality side by side — de-risking the “nascent vector search” concern with data rather than opinion.count() now supports per-tenant quota enforcement and usage-based billing surfaces.WHERE metadata.field = 'X' AND vector_similarity > 0.8), which is less common in early-stage vector stores.count capability covers this without bespoke queries.VectorDocumentInterface (v0.14.0) standardizes how embeddings are represented, lowering the cost of a future swap.count() is a convenience capability, not a performance or index-maturity improvement — don’t treat v0.14.0 as closing the scale gap.*"This package enables us to leverage SurrealDB—a high-performance, open-source database—as a vector store for our AI features, directly within our Laravel stack. By integrating Symfony’s AI tools with SurrealDB, we can:
*"The symfony/ai-surreal-db-store package bridges SurrealDB into Symfony’s AI ecosystem, giving us:
WHERE metadata = 'X'), which is rare in early-stage vector databases.count support on stores (v0.14.0): query corpus size per index without pulling records — useful for pagination, tenant quotas, and ingestion sanity checks.VectorDocumentInterface (v0.14.0): a shared document contract, so retrieval code isn’t coupled to SurrealDB-specific record shapes. This makes A/B benchmarks against pgvector realistic and gives us a clean seam for a second backend.symfony/ai to our stack (or build a Laravel wrapper).VectorDocumentInterface so the comparison is apples-to-apples.// Configure in Laravel's service container
$this->app->bind(\Symfony\AI\Store\VectorStoreInterface::class, function ($app) {
$client = new \Surreal\Client($app['config']['surrealdb.dsn']);
return new \Symfony\AI\Store\SurrealDbStore($client, 'hnsw_index');
});
// Use in a Laravel service
$store = app(VectorStoreInterface::class);
$results = $store->find($queryEmbedding, limit: 5);
// v0.14.0: inventory / quota checks without fetching records
$indexed = $store->count();
Example integration:
// Configure in Laravel's service container
$this->app->bind(\Symfony\AI\Store\VectorStoreInterface::class, function ($app) {
$client = new \Surreal\Client($app['config']['surrealdb.dsn']);
return new \Symfony\AI\Store\SurrealDbStore($client, 'hnsw_index');
});
// Use in a Laravel service
$store = app(VectorStoreInterface::class);
$results = $store->find($queryEmbedding, limit: 5);
```"
---
### **For Data Scientists/ML Engineers:**
*"This package lets us **store and retrieve embeddings in SurrealDB**, enabling:
- **Real-time similarity search** for AI applications (e.g., recommendation systems, chatbots).
- **Hybrid data models**: Combine vector search with SurrealDB’s graph/document capabilities (e.g., link embeddings to user profiles).
- **Cost-effective scaling**: SurrealDB’s open-source model reduces reliance on expensive vector services.
- **Cheap corpus bookkeeping (v0.14.0)**: `count` lets us verify that an ingestion job wrote what we expect (e.g., 1M source docs → 1M embeddings) before running evals, and to size experiments without scanning the store.
- **Portable documents (v0.14.0)**: `VectorDocumentInterface` standardizes vectors + metadata, so the same eval harness can run against SurrealDB and pgvector for a fair latency/recall comparison.
*Considerations*:
- **Query flexibility**: SurrealQL supports filtering vectors by metadata (e.g., `SELECT * WHERE vector_similarity(embedding, ?) > 0.8 AND category = 'tech'`).
- **Performance**: Benchmark against your current solution (e.g., pgvector) for latency and throughput. Counting documents is not an index-quality signal — keep separate recall/latency benchmarks.
- **Schema design**: Work with the team to define how vectors and metadata will be structured in SurrealDB tables/records.
*Next steps*:
- Collaborate with engineers to **design the SurrealDB schema** for your embeddings.
- Test **vector indexing strategies** (e.g., HNSW vs. MTREE) for your use case.
- Validate **embedding update patterns** (e.g., batch inserts, real-time sync), using `count()` as an ingestion assertion."*
---
### **For Product Managers:**
*"This package supports our **AI-driven product roadmap** by enabling cost-effective, scalable vector search without vendor lock-in. Key benefits:
- **Unified Data Model**: Store vectors alongside relational data in SurrealDB, reducing infrastructure complexity.
- **Cost Savings**: Avoid recurring fees for managed vector databases (e.g., Pinecone) with self-hosted SurrealDB.
- **Metering & Quotas (v0.14.0)**: With store `count` support we can show customers how much content is indexed, enforce plan limits, and report AI usage — a prerequisite for pricing AI features.
- **Lower Switching Cost (v0.14.0)**: The new vector document interface means an eventual move to pgvector or another backend is a contained engineering task, not a rewrite.
- **Flexibility**: SurrealDB’s multi-model capabilities allow us to experiment with **graph + vector hybrids** (e.g., knowledge graphs for RAG).
*Recommendations*:
1. **Prioritize for high-impact AI features** (e.g., semantic search, recommendations) where cost and flexibility are critical.
2. **Pilot with a non-critical feature** to validate performance and integration effort.
3. **Compare with alternatives** (e.g., pgvector) to ensure SurrealDB meets our scale and latency requirements.
4. **Align with engineering** to assess tradeoffs (e.g., Symfony dependency, schema design effort).
5. **Scope metering early**: if AI features will be priced or quota-limited, design the `count`-based usage reporting in the first iteration rather than retrofitting it.
*Example use case*: If we’re building a **personalized content recommendation system**, this package lets us store user embeddings in SurrealDB and retrieve similar items in real time—while keeping costs low and infrastructure simple."*
How can I help you explore Laravel packages today?