How to Use Custom Embedding Models for Semantic Search in Mendix?

0
I want to implement semantic search using my own data as a knowledge base. Is there any option to use custom or alternative embedding models (e.g., Sentence Transformers) for generating embeddings from text chunks and storing them in a pgVector database?Currently, I can’t find any configuration or options for using custom models instead of the default ones (like OpenAI or Mistral) on the frontend.   Could someone guide me on how to integrate custom embedding models for semantic search in Mendix?
asked
1 answers
0

Hi Praveen,


Yes, you can integrate a custom embedding model with Mendix for semantic search. The key is to implement the embedding-generation step and connect it to your vector database; you do not necessarily need to use the default OpenAI embedding model.


I would recommend the following approach:


1. Host your custom embedding model

If you are using a Sentence Transformers model such as all-MiniLM-L6-v2, expose it through a REST API (for example, using FastAPI). The API should accept text and return the generated embedding vector.


2. Integrate the model with Mendix

In Mendix, use a Call REST service activity in a microflow to send text to your embedding endpoint and parse the returned vector.

If you are using Mendix GenAI Commons, you can also implement a custom connector compatible with its model and embedding interfaces. The official documentation explains how to build your own GenAI connector or adapt an existing connector.


3. Store the embeddings in PostgreSQL with pgvector

Use the PgVector Knowledge Base module or your own SQL integration to store the text chunks and their embedding vectors.

Make sure the database vector column has the correct dimensionality for your model. For example, all-MiniLM-L6-v2 produces 384-dimensional embeddings.


4. Implement semantic search

When a user submits a search query:

  1. Send the query to the same embedding model.
  2. Generate its embedding vector.
  3. Run a pgvector nearest-neighbor query against the stored vectors.
  4. Return the most relevant text chunks or records.


5. Keep the embedding model consistent

This is essential: use the same embedding model and compatible configuration for indexing documents and generating search-query embeddings. If you change models, you will generally need to regenerate the stored embeddings and ensure the vector dimensions and similarity metric are compatible.


Official references:


My recommendation: If you already have a custom embedding model running in Python, start by exposing it through a REST API and calling it from Mendix. Use pgvector for storage and similarity search. If you also want the model to work with Mendix's GenAI Commons components, implement the appropriate custom connector rather than replacing the default model configuration blindly.


Hope this helps!

answered