Skip to content

Commit b6cae5c

Browse files
committed
feature #340 [Store][ChromaDB] Add query filtering (valx76)
This PR was squashed before being merged into the main branch. Discussion ---------- [Store][ChromaDB] Add query filtering | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | no | License | MIT Very simple update allowing to add ChromaDB filters using the `$options` array parameter (actually unused for ChromaDB). Before, we needed to create kind of a _fake_ decorator as I did [here](https://github.com/valx76/SymfonyAI-POC/blob/master/src/AI/StoreDecorator.php) (I didn't find any other way).. I noticed the `query` method doesn't have any test yet so I imagine it'll be done in the future, which is why there is no test update in this PR. Commits ------- fd6a200 [Store][ChromaDB] Add query filtering
2 parents 5580902 + fd6a200 commit b6cae5c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/store/src/Bridge/ChromaDb/Store.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,17 @@ public function add(VectorDocument ...$documents): void
5252
$collection->add($ids, $vectors, $metadata, $originalDocuments);
5353
}
5454

55+
/**
56+
* @param array{where?: array<string, string>, whereDocument?: array<string, mixed>} $options
57+
*/
5558
public function query(Vector $vector, array $options = []): array
5659
{
5760
$collection = $this->client->getOrCreateCollection($this->collectionName);
5861
$queryResponse = $collection->query(
5962
queryEmbeddings: [$vector->getData()],
6063
nResults: 4,
64+
where: $options['where'] ?? null,
65+
whereDocument: $options['whereDocument'] ?? null,
6166
);
6267

6368
$documents = [];

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ public static function addDocumentsProvider(): \Iterator
108108
new VectorDocument(
109109
Uuid::fromString('01234567-89ab-cdef-0123-456789abcdef'),
110110
new Vector([0.1, 0.2, 0.3]),
111-
new Metadata(['_text' => 'This is the content of document 1', 'title' => 'Document 1'])),
111+
new Metadata(['_text' => 'This is the content of document 1', 'title' => 'Document 1'])
112+
),
112113
new VectorDocument(
113114
Uuid::fromString('fedcba98-7654-3210-fedc-ba9876543210'),
114115
new Vector([0.4, 0.5, 0.6]),

0 commit comments

Comments
 (0)