PgVector Knowledge Base

Content Type: Module
Categories: Connectors,Data,Artificial Intelligence

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

  1. Have access to your own PostgreSQL database with the pgvector extension installed.
  2. Download the Encryption, CommunityCommons and DatabaseConnector modules from the Marketplace and follow the setup instructions.
  3. Add the module role 'PgVectorKnowledgeBase.Administrator' to your Administrator user role in the security settings of your app.
  4. 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

  • (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.

 

Reference documentation

Technical documentation is available on docs.mendix.com

Releases

Version: 2.0.0
Framework Version: 9.24.2
Release Notes: We have updated the module to be compatible with GenAI Commons. This facilitates the combination of embeddings and knowledge base interactions for similarity search and RAG using the shared domain model of GenAI Commons. Please update the OpenAI connector or the Amazon Bedrock connector to use the combined setup. Please note that the database schema has changed compared to previous releases. This means that if you upgrade, you will need to “repopulate” your knowledge base. Finally, the retrieve operation now has an optional input parameter for a Mendix object.
Version: 1.2.1
Framework Version: 9.24.2
Release Notes: We removed unused styling and updated the Toolbox in Studio Pro.
Version: 1.2.0
Framework Version: 9.24.0
Release Notes: We added a new operation that replaces existing chunks in the knowledge base for chunks based on a Mendix Object. This allows to keep the keep the knowledge base in sync with the application database. Similar to the Repopulate Knowledge Base operation, you can use Chunk_Create to create the input for the Replace operation. Additionally, we added an operation that inserts a list of Chunks into an existing knowledge base. Lastly, two new operations have been added that can be used to delete chunks and their corresponding labels from the knowledge base by either providing a Mendix object or a list of Mendix objects.
Version: 1.1.0
Framework Version: 9.24.0
Release Notes: We added two new operation to retrieve chunks from the knowledge base and automatically associate them to the Mendix object for which the chunks were created (if applicable). This can be done as a nearest neighbor search or as a regular retrieve with offset and limit. Additionally, we added an operation to delete a knowledge base.
Version: 1.0.0
Framework Version: 9.24.0
Release Notes: Initial release. We included the necessary operations to populate knowledge bases and to retrieve data (with and without vector similarity calculation).