Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/store/src/Bridge/Vektor/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.git* export-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Please do not submit any Pull Requests here. They will be closed.
---

Please submit your PR here instead:
https://github.com/symfony/ai

This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Close Pull Request

on:
pull_request_target:
types: [opened]

jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: superbrothers/close-pull-request@v3
with:
comment: |
Thanks for your Pull Request! We love contributions.
However, you should instead open your PR on the main repository:
https://github.com/symfony/ai
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
4 changes: 4 additions & 0 deletions src/store/src/Bridge/Vektor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor/
composer.lock
phpunit.xml
.phpunit.result.cache
7 changes: 7 additions & 0 deletions src/store/src/Bridge/Vektor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CHANGELOG
=========

0.4
---

* Add the bridge
19 changes: 19 additions & 0 deletions src/store/src/Bridge/Vektor/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2026-present Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
12 changes: 12 additions & 0 deletions src/store/src/Bridge/Vektor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Vektor Store
============

Provides [Vektor](https://github.com/centamiv/vektor) vector store integration for Symfony AI Store.

Resources
---------

* [Contributing](https://symfony.com/doc/current/contributing/index.html)
* [Report issues](https://github.com/symfony/ai/issues) and
[send Pull Requests](https://github.com/symfony/ai/pulls)
in the [main Symfony AI repository](https://github.com/symfony/ai)
91 changes: 91 additions & 0 deletions src/store/src/Bridge/Vektor/Store.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\AI\Store\Bridge\Vektor;

use Symfony\AI\Platform\Vector\Vector;
use Symfony\AI\Store\Document\VectorDocument;
use Symfony\AI\Store\Exception\InvalidArgumentException;
use Symfony\AI\Store\ManagedStoreInterface;
use Symfony\AI\Store\StoreInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
* @author Guillaume Loulier <personal@guillaumeloulier.fr>
*/
final class Store implements ManagedStoreInterface, StoreInterface
{
public function __construct(
private readonly HttpClientInterface $httpClient,
#[\SensitiveParameter] private readonly string $apiKey,
private readonly string $endpoint,
) {
}

public function setup(array $options = []): void
{
if ([] !== $options) {
throw new InvalidArgumentException('No supported options.');
}
}

public function drop(array $options = []): void
{
// TODO: Implement drop() method.
}

public function add(VectorDocument|array $documents): void
{
if ($documents instanceof VectorDocument) {
$documents = [$documents];
}

foreach ($documents as $document) {
$this->request('POST', 'insert', [
'id' => '',
'vector' => $document->vector->getData(),
'metadata' => $document->metadata->getArrayCopy(),
]);
}
}

public function remove(array|string $ids, array $options = []): void
{
if (\is_string($ids)) {
$ids = [$ids];
}

foreach ($ids as $id) {
$this->request('DELETE', 'delete', [
'id' => $id,
]);
}
}

public function query(Vector $vector, array $options = []): iterable
{
$results = $this->request('GET', 'search', [
'vector' => $vector->getData(),
'k' => $options['k'] ?? 10,
]);

}

private function request(string $method, string $endpoint, array $payload): array
{
$response = $this->httpClient->request($method, \sprintf('%s/%s', $this->endpoint, $endpoint), [
'auth_bearer' => $this->apiKey,
'json' => $payload,
]);

return $response->toArray();
}
}
31 changes: 31 additions & 0 deletions src/store/src/Bridge/Vektor/Tests/StoreTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\AI\Store\Bridge\Vektor\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\AI\Store\Bridge\Vektor\Store;
use Symfony\Component\HttpClient\MockHttpClient;

final class StoreTest extends TestCase
{
public function testStoreCannotSetupWithOptions()
{
$store = new Store(new MockHttpClient(), 'foo', 'http://127.0.0.1:8080');

$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('No supported options.');
$this->expectExceptionCode(0);
$store->setup([
'foo' => 'bar',
]);
}
}
60 changes: 60 additions & 0 deletions src/store/src/Bridge/Vektor/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "symfony/ai-vektor-store",
"description": "Vektor vector store bridge for Symfony AI",
"license": "MIT",
"type": "symfony-ai-store",
"keywords": [
"ai",
"bridge",
"store",
"vektor",
"vector"
],
"authors": [
{
"name": "Guillaume Loulier",
"email": "personal@guillaumeloulier.fr"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"require": {
"php": ">=8.2",
"symfony/ai-platform": "^0.1",
"symfony/ai-store": "^0.2",
"symfony/http-client": "^7.3|^8.0",
"symfony/uid": "^7.3|^8.0"
},
"require-dev": {
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^11.5.46"
},
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"Symfony\\AI\\Store\\Bridge\\Vektor\\": ""
}
},
"autoload-dev": {
"psr-4": {
"Symfony\\AI\\PHPStan\\": "../../../../../.phpstan/",
"Symfony\\AI\\Store\\Bridge\\Vektor\\Tests\\": "Tests/"
}
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-main": "0.4.x-dev"
},
"thanks": {
"name": "symfony/ai",
"url": "https://github.com/symfony/ai"
}
}
}
28 changes: 28 additions & 0 deletions src/store/src/Bridge/Vektor/phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- ../../../../../.phpstan/extension.neon

parameters:
level: 6
paths:
- .
- Tests/
excludePaths:
- vendor/
treatPhpDocTypesAsCertain: false
ignoreErrors:
-
message: "#^Method .*::test.*\\(\\) has no return type specified\\.$#"
-
message: '#^Call to( static)? method PHPUnit\\Framework\\Assert::.* will always evaluate to true\.$#'
reportUnmatched: false
-
identifier: 'symfonyAi.forbidNativeException'
path: Tests/*
reportUnmatched: false

services:
- # Conditionally enabled by bleeding edge in phpstan/phpstan-phpunit 2.x
class: PHPStan\Type\PHPUnit\DataProviderReturnTypeIgnoreExtension
tags:
- phpstan.ignoreErrorExtension
33 changes: 33 additions & 0 deletions src/store/src/Bridge/Vektor/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
failOnDeprecation="true"
failOnRisky="true"
failOnWarning="true"
executionOrder="random"
>
<php>
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
<testsuite name="Symfony AI Vektor Store Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>

<source ignoreSuppressionOfDeprecations="true">
<include>
<directory>./</directory>
</include>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</source>
</phpunit>
Loading