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

  • 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.
  • 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 labels.
  • Retrieve & Associate: use this operation to get a list of chunks from the knowledge base, optionally filtered by labels, 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: Use this operation to delete chunks that are related to a Mendix object.
  • Delete List: Use this operation to delete chunks that are related to a list of Mendix objects.

Misc

  • Create Label: use this to create labels (key/value pairs) to which chunks can be associated during the 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

Releases

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).