ElasticSearch in Python #17 - The kNN search algorithm

Опубликовано: 15 Май 2026
на канале: 3CodeCamp
446
19

In this video, I'll show you how to use kNN search to retrieve documents after embedding them. This search method is applicable only if your index contains a dense_vector field.

In video 16, we learned how to convert text into dense vectors using an embedding model. But how do we search within these embedded documents?

Watch that video here:
   • ElasticSearch in Python #16 - Embedding do...  

The solution is kNN search, which is specifically designed for fields mapped as dense vectors. It's crucial to remember that you cannot use the query parameter for this type of search.

Now, I'll give a brief overview of the kNN algorithm. This algorithm is widely used for both classification and regression tasks. To classify a new data point, kNN identifies the k closest points to determine its classification.

If you're interested in diving deeper into the kNN algorithm, I highly recommend watching this video—you're going to enjoy it!

StatQuest's video that explains the kNN algorithm:
   • StatQuest: K-nearest neighbors, Clearly Ex...  

In this series, we focus on using the Python client to interact with Elasticsearch.

Here is the link to the GitHub repository:
https://github.com/ImadSaddik/Elastic...

Useful links:
https://www.elastic.co/guide/en/elast...

Don't forget to like, subscribe, and leave a comment if you have any questions or feedback!

Support us at:
  / 3codecamp  

⭐️ Contents ⭐️
(00:00) Intro + slides
(03:10) Code time
(09:30) The end

#3_code_campers #ElasticSearch #ElasticSearchPython