Open hkulekci opened 1 year ago
Nobody yet as I know did yet implement knn search or vector types. If somebody want to contribute it feel free, currently we have not yet planned it.
Thanks for the quick response! I'm interested in giving it a try and attempting to implement knn search support for the library. I hope I can implement it in short time. 🤗
Implemented a solution and here an example usage:
<?php
use Elastic\Elasticsearch\ClientBuilder;
use ONGR\ElasticsearchDSL\Knn\Knn;
use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
include __DIR__ . '/../vendor/autoload.php';
$builder = ClientBuilder::create();
$builder->setElasticCloudId("....");
$builder->setApiKey('....');
$client = $builder->build();
$knn = new Knn(
'my_vector',
[0.5, 10, 8],
10,
100,
);
$matchAll = new MatchAllQuery();
$knn->setFilter($matchAll);
$search = new ONGR\ElasticsearchDSL\Search();
$search->addKnn($knn);
$params = [
'index' => 'my-index',
'body' => $search->toArray(),
];
$response = $client->search($params);
var_dump($response->asArray());
@alexander-schranz what do you think?
Do we have a plan to add support for Knn Search, or is it possible with this library? I would like to hear your opinions.
ping @alexander-schranz