# Beyond Basics: Enhancing Kotlin Ktor API With Vector Search

In this article, we will delve into advanced MongoDB techniques in conjunction with the Kotlin Ktor API, building upon the foundation established in our previous article, Mastering Kotlin: Creating an API With Ktor and MongoDB Atlas. Our focus will be on integrating robust features such as Hugging Face, Vector Search, and MongoDB Atlas triggers/functions to augment the functionality and performance of our API.

We will start by providing an overview of these advanced MongoDB techniques and their critical role in contemporary API development. Subsequently, we will delve into practical implementations, showcasing how you can seamlessly integrate Hugging Face for natural language processing, leverage Vector Search for rapid data retrieval, and automate database processes using triggers and functions.

## Prerequisites

- MongoDB Atlas account
    - Note: Get started with MongoDB Atlas for free! If you don’t already have an account, MongoDB offers a free-forever Atlas cluster.
- Hugging Face account
- Source code from the previous article
- MongoDB Tools

## Demonstration

We'll begin by importing a dataset of fitness exercises into MongoDB Atlas as documents. Then, we'll create a trigger that activates upon insertion. For each document in the dataset, a function will be invoked to request Hugging Face's API. This function will send the exercise description for conversion into an embedded array, which will be saved into the exercises collection as *descEmbedding*:

 to create your key:

 to import the exercises.json file via the command line. After installing MongoDB Tools, simply paste the "exercises.json" file into the "bin" folder and execute the command, as shown in the image below:

. Our objective is to create an endpoint **/processRequest** to send an input to HuggingFace, such as:

*"**I need an exercise for my shoulders and to lose my belly fat**."*

.

If you have any questions or want to discuss further implementations, feel free to reach out to the MongoDB Developer Community forum for support and guidance.

  [1]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt634af19fb7ed14c5/65fc4b9c73d0bc30f7f3de73/1.png
  [2]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltd30af9afe5366352/65fc4bb7f2a29205cfbf725b/2.png
  [3]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltdf42f1df193dbd24/65fc4bd6e55fcb1058237447/3.png
  [4]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blta874d80fcc78b8bd/65fc4bf5d467d22d530bd73a/4.png
  [5]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt7547c6fcc6e1f2d2/65fc4c0fd95760d277508123/5.png
  [6]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt96197cd32df66580/65fc4c38d4e0c0250b2947b4/6.png
  [7]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt38c3724da63f3c95/65fc4c56fc863105d7d732c1/7.png
  [8]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt49218ab4f7a3cb91/65fc4c8ca1e8152dccd5da77/8.png
  [9]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt9cae67683fad5f9c/65fc4ca3f2a2920d57bf7268/9.png
  [10]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt5fc6270e5e2f8665/65fc4cbb5fa1c6c4db4bfb01/10.png
  [11]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltf428bc700f44f2b5/65fc4cd6f4a4cf171d150bb2/11.png
  [12]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltad71144e071e11af/65fc4cf0d467d2595d0bd74a/12.png
  [13]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt9009a43a7cd07975/65fc4d6d039fddd047339cbe/13.png
  [14]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltd016d8390bd80397/65fc4d83d957609ea9508134/14.png
  [15]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltcb767717bc6af497/65fc4da49b2cda321e9404bd/15.png
  [16]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltc2e0005d6df9a273/65fc4db80780b933c761f14f/16.png
  [17]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt17850b744335f8f7/65fc4dce39973e99456eab16/17.png
  [18]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt6915b7c63ea2bf5d/65fc4de754369a8839696baf/18.png
  [19]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt75993bebed24f8ff/65fc4df9a93acb7b58313f7d/19.png
  [20]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltc68892874fb5cafc/65fc4e0f55464dd4470e2097/20.png
  [21]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltcdbd1c93b61b7535/65fc4e347a44b0822854bc61/21.png
  [22]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt01ebdac5cf78243d/65fc4e4a54369ac59e696bbe/22.png
  [23]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blte13c91279d8805ef/65fc4e5dfc8631011ed732e7/23.png
  [24]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltb17a754e566be42b/65fc4e7054369ac0c5696bc2/24.png
  [25]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt03f0581b399701e8/65fc4e8bd4e0c0e18c2947e2/25.png
  [26]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt56c5fae14d1a2b6a/65fc4ea0d95760693a508145/26.png