Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knn Search Support #27

Open
hkulekci opened this issue Sep 11, 2023 · 3 comments
Open

Knn Search Support #27

hkulekci opened this issue Sep 11, 2023 · 3 comments

Comments

@hkulekci
Copy link

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

@alexander-schranz
Copy link
Member

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.

@hkulekci
Copy link
Author

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. 🤗

@hkulekci
Copy link
Author

hkulekci commented Oct 6, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants