PgVector Knowledge Base
Overview
Store embedding vectors, use cosine similarity (nearest neighbor analysis) and leverage knowledge bases in your (gen-AI enriched) app. This module contains operations to interact with a PostgreSQL database that has the pgvector extension installed. It allows you to easily store vectors and perform cosine similarity calculations directly from your Mendix app. This way you can leverage knowledge bases to make your apps smarter by performing operations based on (embedding) vectors and vector similarity. In the context of generative AI, Large Language Models (LLM) and embeddings, this is a key component in natural language processing (NLP) patterns such as Retrieval Augmented Generation (RAG), recommendation algorithms and similarity search operations.
Getting Started
- Have access to your own PostgreSQL database with the pgvector extension installed.
- Download the Encryption, Community Commons, GenAI Commons and Database Connector modules from the Marketplace and follow the setup instructions.
- Add the module role 'PgVectorKnowledgeBase.Administrator' to your Administrator user role in the security settings of your app.
- Add the 'DatabaseConfiguration_Overview' page (USE_ME > Configuration) to your Navigation or add the 'Snippet_DatabaseConfigurations' to a page that is already part of your Navigation. Now you can setup your database configuration(s) at runtime.
After following the general setup above, you are all set to use the microflows and java actions from the Toolbox, or the USE_ME > Operations folder in your logic.
GenAI Showcase application
For more inspiration or guidance on how to use the operations in your logic and how to combine it with use cases in the context of generative AI, download the GenAI showcase app from the Marketplace. This application contains various examples in the context of generative AI, some of which use the PgVector Knowledge Base module for storing embedding vectors.
You can find technical documentation about the PgVector Knowledge Base module on Mendix Docs.
Documentation
Operations
(Re)populate
- (Re)populate Knowledge Base: use this operation to fill a knowledge base with the list of chunks. Any already existing records are removed.
- Insert: use this action to add a list of chunks to a knowledge base.
- Replace: use this action to replace all chunks that are related to a certain Mendix object
Retrieve
- Retrieve: use this operation to get a list of chunks from the knowledge base, optionally filtered by metadata.
- Retrieve & Associate: use this operation to get a list of chunks from the knowledge base, optionally filtered by metadata, where the association between your chunk entity and the Mendix object(s) for which the chunks were created (if applicable) is set.
- Retrieve Nearest Neighbors: use this operation to perform a similarity search on the vector across the chunks in the knowledge base and hence get only the most similar one(s).
- Retrieve Nearest Neighbor & Associate: use this operation to perform a similarity search on the vector across the chunks in the knowledge base and hence get only the most similar one(s). The association between your chunk entity and the Mendix object(s) for which the chunks were created (if applicable) is set.
Delete
- Delete Knowledge Base: Use this operation to delete a complete knowledge base at once.
- Delete for Object: Use this operation to delete chunks that are related to a Mendix object.
- Delete for List: Use this operation to delete chunks that are related to a list of Mendix objects.
Dependencies
- GenAI Commons
- Community Commons v10.0.6 or higher
- Encryption
- Database Connector
Reference documentation
Technical documentation is available on docs.mendix.com