Skip to content

Commit 35c7d6d

Browse files
committed
ref
1 parent c4503f6 commit 35c7d6d

File tree

3 files changed

+232
-4
lines changed

3 files changed

+232
-4
lines changed

examples/.env

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ SURREALDB_USER=symfony
9292
SURREALDB_PASS=symfony
9393

9494
# Neo4J
95-
NEO4J_HOST='http://localhost:7474'
96-
NEO4J_USERNAME='neo4j'
97-
NEO4J_PASSWORD='symfonyai'
95+
NEO4J_HOST=http://localhost:7474
96+
NEO4J_USERNAME=neo4j
97+
NEO4J_PASSWORD=symfonyai

src/store/src/Bridge/Neo4j/Store.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private function request(string $method, string $endpoint, array $payload = []):
8787
$url = \sprintf('%s/%s', $this->endpointUrl, $endpoint);
8888

8989
$response = $this->httpClient->request($method, $url, [
90-
'auth_basic' => base64_encode(\sprintf('%s:%s', $this->username, $this->password)),
90+
'auth_basic' => \sprintf('%s:%s', $this->username, $this->password),
9191
'headers' => [
9292
'Accept' => 'application/json',
9393
],

src/store/tests/Bridge/Neo4j/StoreTest.php

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313

1414
use PHPUnit\Framework\Attributes\CoversClass;
1515
use PHPUnit\Framework\TestCase;
16+
use Symfony\AI\Platform\Vector\Vector;
1617
use Symfony\AI\Store\Bridge\Neo4j\Store;
18+
use Symfony\AI\Store\Document\VectorDocument;
1719
use Symfony\Component\HttpClient\Exception\ClientException;
1820
use Symfony\Component\HttpClient\MockHttpClient;
1921
use Symfony\Component\HttpClient\Response\JsonMockResponse;
22+
use Symfony\Component\Uid\Uuid;
2023

2124
#[CoversClass(Store::class)]
2225
final class StoreTest extends TestCase
@@ -36,4 +39,229 @@ public function testStoreCannotInitializeOnInvalidResponse(): void
3639
self::expectExceptionCode(400);
3740
$store->initialize();
3841
}
42+
43+
public function testStoreCanInitialize(): void
44+
{
45+
$httpClient = new MockHttpClient([
46+
new JsonMockResponse([
47+
'data' => [
48+
'fields' => [],
49+
'values' => [],
50+
],
51+
'bookmarks' => [
52+
'FB:kcwQ5zbxUD1ESXmS6UjG2xKCZMkAoJB=',
53+
],
54+
], [
55+
'http_code' => 200,
56+
]),
57+
new JsonMockResponse([
58+
'data' => [
59+
'fields' => [],
60+
'values' => [],
61+
],
62+
'notifications' => [
63+
[
64+
'code' => 'Neo.ClientNotification.Schema.IndexOrConstraintAlreadyExists',
65+
'description' => '`VECTOR INDEX movies FOR (e:symfony) ON (e.symfony)` already exists.',
66+
'severity' => 'INFORMATION',
67+
'title' => '"`CREATE VECTOR INDEX movies IF NOT EXISTS FOR (symfony:symfony) ON (symfony.symfony) OPTIONS {indexConfig: {`vector.dimensions`: 1536, `vector.similarity_function`: "cosine", `vector.quantization.enabled`: false}}` has no effect.',
68+
'position' => null,
69+
'category' => 'SCHEMA',
70+
],
71+
],
72+
'bookmarks' => [
73+
'FB:kcwQ5zbxUD1ESXmS6UjG2xKCZMkAoJA=',
74+
],
75+
], [
76+
'http_code' => 202,
77+
]),
78+
], 'http://localhost:7474');
79+
80+
$store = new Store($httpClient, 'http://localhost:7474', 'symfony', 'symfony', 'symfony', 'symfony', 'symfony');
81+
82+
$store->initialize();
83+
$store->initialize();
84+
85+
self::assertSame(2, $httpClient->getRequestsCount());
86+
}
87+
88+
public function testStoreCanAdd(): void
89+
{
90+
$httpClient = new MockHttpClient([
91+
new JsonMockResponse([
92+
'data' => [
93+
'fields' => [],
94+
'values' => [],
95+
],
96+
'bookmarks' => [
97+
'FB:kcwQ5zbxUD1ESXmS6UjG2xKCZMkAoJB=',
98+
],
99+
], [
100+
'http_code' => 200,
101+
]),
102+
new JsonMockResponse([
103+
'data' => [
104+
'fields' => [
105+
'n',
106+
],
107+
'values' => [
108+
[
109+
[
110+
'elementId' => '4:'.Uuid::v4()->toRfc4122(),
111+
'labels' => [
112+
'symfony',
113+
],
114+
'properties' => [
115+
'embeddings' => [0.1, 0.2, 0.3],
116+
'metadata' => [],
117+
'id' => Uuid::v4()->toRfc4122(),
118+
],
119+
],
120+
],
121+
],
122+
],
123+
'bookmarks' => [
124+
'FB:kcwQdJAosIhGT0yRm+Na1gMjaQqQ',
125+
],
126+
], [
127+
'http_code' => 200,
128+
]),
129+
new JsonMockResponse([
130+
'data' => [
131+
'fields' => [
132+
'n',
133+
],
134+
'values' => [
135+
[
136+
[
137+
'elementId' => '4:'.Uuid::v4()->toRfc4122(),
138+
'labels' => [
139+
'symfony',
140+
],
141+
'properties' => [
142+
'embeddings' => [0.1, 0.2, 0.3],
143+
'metadata' => [],
144+
'id' => Uuid::v4()->toRfc4122(),
145+
],
146+
],
147+
],
148+
],
149+
],
150+
'bookmarks' => [
151+
'FB:kcwQdJAosIhGT0yRm+Na1gMjaQqS',
152+
],
153+
], [
154+
'http_code' => 200,
155+
]),
156+
], 'http://localhost:7474');
157+
158+
$store = new Store($httpClient, 'http://localhost:7474', 'symfony', 'symfony', 'symfony', 'symfony', 'symfony');
159+
160+
$store->initialize();
161+
$store->add(new VectorDocument(Uuid::v4(), new Vector([0.1, 0.2, 0.3])));
162+
$store->add(new VectorDocument(Uuid::v4(), new Vector([0.1, 0.2, 0.3])));
163+
164+
self::assertSame(3, $httpClient->getRequestsCount());
165+
}
166+
167+
public function testStoreCanQuery(): void
168+
{
169+
$httpClient = new MockHttpClient([
170+
new JsonMockResponse([
171+
'data' => [
172+
'fields' => [],
173+
'values' => [],
174+
],
175+
'bookmarks' => [
176+
'FB:kcwQ5zbxUD1ESXmS6UjG2xKCZMkAoJB=',
177+
],
178+
], [
179+
'http_code' => 200,
180+
]),
181+
new JsonMockResponse([
182+
'data' => [
183+
'fields' => [
184+
'n',
185+
],
186+
'values' => [
187+
[
188+
[
189+
'elementId' => '4:'.Uuid::v4()->toRfc4122(),
190+
'labels' => [
191+
'symfony',
192+
],
193+
'properties' => [
194+
'embeddings' => [0.1, 0.2, 0.3],
195+
'metadata' => [],
196+
'id' => Uuid::v4()->toRfc4122(),
197+
],
198+
],
199+
],
200+
],
201+
],
202+
'bookmarks' => [
203+
'FB:kcwQdJAosIhGT0yRm+Na1gMjaQqR',
204+
],
205+
], [
206+
'http_code' => 200,
207+
]),
208+
new JsonMockResponse([
209+
'data' => [
210+
'fields' => [
211+
'node',
212+
'score',
213+
],
214+
'values' => [
215+
[
216+
[
217+
'elementId' => '4:'.Uuid::v4()->toRfc4122(),
218+
'labels' => [
219+
'symfony',
220+
],
221+
'properties' => [
222+
'embeddings' => [0.1, 0.2, 0.3],
223+
'metadata' => json_encode([
224+
'foo' => 'bar',
225+
]),
226+
'id' => Uuid::v4()->toRfc4122(),
227+
],
228+
],
229+
0.1,
230+
],
231+
[
232+
[
233+
'elementId' => '4:'.Uuid::v4()->toRfc4122(),
234+
'labels' => [
235+
'symfony',
236+
],
237+
'properties' => [
238+
'embeddings' => [0.1, 0.2, 0.3],
239+
'metadata' => json_encode([
240+
'foo' => 'bar',
241+
]),
242+
'id' => Uuid::v4()->toRfc4122(),
243+
],
244+
],
245+
0.1,
246+
],
247+
],
248+
],
249+
'bookmarks' => [
250+
'FB:kcwQdJAosIhGT0yRm+Na1gMjaQqT',
251+
],
252+
], [
253+
'http_code' => 200,
254+
]),
255+
], 'http://localhost:7474');
256+
257+
$store = new Store($httpClient, 'http://localhost:7474', 'symfony', 'symfony', 'symfony', 'symfony', 'symfony');
258+
259+
$store->initialize();
260+
$store->add(new VectorDocument(Uuid::v4(), new Vector([0.1, 0.2, 0.3])));
261+
262+
$results = $store->query(new Vector([0.1, 0.2, 0.3]));
263+
264+
self::assertCount(2, $results);
265+
self::assertSame(3, $httpClient->getRequestsCount());
266+
}
39267
}

0 commit comments

Comments
 (0)