Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

[Store][Azure] Make vector field name configurable #43

Merged
merged 2 commits into from
Sep 25, 2024
Merged
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
14 changes: 9 additions & 5 deletions src/Store/Azure/SearchStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@

final readonly class SearchStore implements VectorStoreInterface
{
/**
* @param string $vectorFieldName The name of the field int the index that contains the vector
*/
public function __construct(
private HttpClientInterface $httpClient,
private string $endpointUrl,
private string $apiKey,
private string $indexName,
private string $apiVersion,
private string $vectorFieldName = 'vector',
) {
}

Expand Down Expand Up @@ -73,7 +77,7 @@ private function convertDocumentToIndexableArray(Document $document): array
{
return array_merge([
'id' => $document->id,
'vector' => $document->vector->getData(),
$this->vectorFieldName => $document->vector->getData(),
], $document->metadata->getArrayCopy());
}

Expand All @@ -92,10 +96,10 @@ private function convertArrayToDocument(array $data): Document

/**
* @return array{
* kind: string,
* kind: 'vector',
* vector: float[],
* exhaustive: bool,
* fields: string,
* exhaustive: true,
* fields: non-empty-string,
* weight: float,
* k: int,
* }
Expand All @@ -106,7 +110,7 @@ private function buildVectorQuery(Vector $vector): array
'kind' => 'vector',
'vector' => $vector->getData(),
'exhaustive' => true,
'fields' => 'vector',
'fields' => $this->vectorFieldName,
'weight' => 0.5,
'k' => 5,
];
Expand Down