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, CommunityCommons and DatabaseConnector 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.
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 OpenAI 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
- Create Chunk: use this action to instantiate a chunk that needs to be added to the knowledge base.
- (Re)populate Knowledge Base: use this operation to fill a knowledge base with the list of Chunks. Any already existing records are removed.
Retrieve
- Retrieve: use this operation to get a list of chunks from the knowledge base, optionally filtered by labels.
- Retrieve & Associate: use this operation to get a list of chunks from the knowledge base, optionally filtered by labels, where the assocation 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 assocation 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.
Misc
- Create Label: use this to create labels (key/value pairs) to which chunks can be associated during population of the knowledge base. The same resulting entity can be used for custom filtering in the retrieve operations.
Reference documentation
Technical documentation is available on docs.mendix.com