symfony/ai-open-search-store
OpenSearch vector store integration for Symfony AI Store. Index and query embeddings using OpenSearch knn_vector fields and k‑NN/approximate k‑NN search. Links to OpenSearch docs and contribution resources in the main Symfony AI repo.
StoreInterface, which is a clean abstraction for vector stores. While Laravel lacks native Symfony integration, this abstraction allows for minimal coupling if wrapped properly (e.g., via facade or service container). The core value—OpenSearch’s knn_vector—is stack-agnostic and aligns with Laravel’s need for scalable vector search.StoreInterface can be adapted to Laravel with a custom wrapper (e.g., facade or service), hiding Symfony dependencies.knn_vector field, dimensionality) and performance tuning (e.g., engine for ANN).knn_vector is stable, but approximate NN trade-offs (speed vs. accuracy) must be benchmarked.knn_vector fields may require index reindexing.StoreInterface without exposing Symfony to the rest of Laravel, or is a custom OpenSearch client (e.g., opensearchphp/opensearch) a better fit?knn_vector for the target embedding dimensionality (e.g., 768D) and query latency?knn_vector format?symfony/process) or willing to isolate Symfony dependencies.Assess and Plan:
pgvector, Weaviate) for Laravel’s stack.Symfony Integration Strategy:
composer require symfony/ai symfony/ai-open-search-store
StoreInterface:
// app/Services/OpenSearchVectorStore.php
namespace App\Services;
use Symfony\Component\AI\Store\OpenSearchStore;
use OpenSearch\Client;
class OpenSearchVectorStore {
public function __construct(private Client $client) {}
public function nearest(array $vector, int $limit = 5) {
$store = new OpenSearchStore($this->client, 'vector_index');
return $store->nearest($vector, $limit);
}
}
AppServiceProvider:
public function register() {
$this->app->singleton(\App\Services\OpenSearchVectorStore::class, function ($app) {
return new \App\Services\OpenSearchVectorStore(
new \OpenSearch\Client([...])
);
});
}
opensearchphp/opensearch directly to avoid Symfony:
// app/Services/OpenSearchVectorStore.php
namespace App\Services;
use OpenSearch\Client;
class OpenSearchVectorStore {
public function __construct(private Client $client) {}
public function nearest(array $vector, int $limit = 5) {
$params = [
'index' => 'vector_index',
'body' => [
'query' => [
'knn' => [
'embedding' => [
'vector' => $vector,
'k' => $limit,
],
],
],
],
];
return $this->client->search($params);
}
}
OpenSearch Setup:
knn_vector field:
curl -X PUT "localhost:9200/vector_index" -H 'Content-Type: application/json' -d'
{
"settings": {
"index": {
"knn": true,
"knn.algo_param.ef_search": 100
}
},
"mappings": {
"properties": {
"embedding": {
"type": "knn_vector",
"dimension": 768
},
"metadata": {
"type": "object"
}
}
}
}'
knn.algo_param for approximate NN trade-offs (e.g., ef_search for speed vs. brute_force for accuracy).Laravel Service Integration:
use App\Services\OpenSearchVectorStore;
public function semanticSearch(Request $request) {
$embedding = $request->input('embedding');
$results = app(OpenSearchVectorStore::class)->nearest($embedding, 3);
return response()->json($results);
}
How can I help you explore Laravel packages today?