# Semantic search and text expansion query with self-deployed model

**URL:** <https://discuss.elastic.co/t/semantic-search-and-text-expansion-query-with-self-deployed-model/339708>\
**Category:** Elasticsearch\
**Tags:** docker, vector-search\
**Created:** [July 31, 2023, 3:15pm UTC](https://discuss.elastic.co/t/semantic-search-and-text-expansion-query-with-self-deployed-model/339708 "2023-07-31T15:15:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![camoneme](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/camoneme/32/123813_2.png) [@camoneme](https://discuss.elastic.co/u/camoneme)\
**Post date:** [July 31, 2023, 3:15pm UTC](https://discuss.elastic.co/t/semantic-search-and-text-expansion-query-with-self-deployed-model/339708/1 "2023-07-31T15:15:01Z")

</div>

I'm trying to use the text expansion query to implement semantic search on a rank features field. I've read the ELSER documentation and understand the process. I'm using a local/downloaded elasticsearch on docker (not connected to elastic cloud).

In this example they reference the ELSER model ID to query a rank features field:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/8/38f9c0ed3364de7bdb945ccbab28da125f1ae46c.png)  
I'm curious if there's a way to use this query but use a self deployed model (not on elastic cloud) rather than the ELSER model.

---

<div class="post-metadata">

**Author:** ![xeraa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xeraa/32/48181_2.png) [@xeraa](https://discuss.elastic.co/u/xeraa)\
**Post date:** [August 7, 2023, 9:01pm UTC](https://discuss.elastic.co/t/semantic-search-and-text-expansion-query-with-self-deployed-model/339708/2 "2023-08-07T21:01:32Z")

</div>

Welcome!

I'd start with [Import the trained model and vocabulary | Machine Learning in the Elastic Stack [8.9] | Elastic](https://www.elastic.co/guide/en/machine-learning/current/ml-nlp-import-model.html) on how to import custom NLP models (with `--url` instead of `--cloud-id`).

PS: Out of interest, which model do you have in mind?

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [August 8, 2023, 7:17am UTC](https://discuss.elastic.co/t/semantic-search-and-text-expansion-query-with-self-deployed-model/339708/3 "2023-08-08T07:17:42Z")

</div>

Hey Camoneme,

You can import your own text embedding model into elasticsearch with eland and use [query\_vector\_builder](https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html#knn-semantic-search) to embed your query.

This notebook is also an end to end example of how you would do this with a hugging face model [https://github.com/elastic/elasticsearch-labs/blob/main/notebooks/integrations/hugging-face/loading-model-from-hugging-face.ipynb](https://github.com/elastic/elasticsearch-labs/blob/main/notebooks/integrations/hugging-face/loading-model-from-hugging-face.ipynb)

Hope this helps!  
Joe

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 5, 2023, 7:18am UTC](https://discuss.elastic.co/t/semantic-search-and-text-expansion-query-with-self-deployed-model/339708/4 "2023-09-05T07:18:42Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
