Icon

01. GenAI Learnathon_​Exercise

GenAI Learnathon: Enrich Data Analytics with GenAI

During this hands-on learnathon, you will get familiar with the free low-code tool KNIME Analytics Platform, techniques for fraud detection, and the use of GenAI via the KNIME AI Extension (Labs).

Without any coding experience you will learn to:

* Detect frauds in investment contracts visually and using statistical techniques

* Prompt engineer an LLM via the OpenAI integration

* Create a vector store from a corpus of different types of investment contracts (the knowledge base)

* Build and deploy a data app to display email alerts and make it available to authenticated users on a web browser

Other KNIME AI integrations we will discuss include GPT4All, Hugging Face, Chroma, FAISS and more.

URL: KNIME AI Extension (Labs) https://hub.knime.com/knime/extensions/org.knime.python.features.llm/latest/
URL: KNIME for Generative AI https://hub.knime.com/knime/collections/KNIME%20for%20Generative%20AI~D4ckx2q_J5FPBQXu

C) Enriching Analytics with GenAI: Prompting for Email Alerts

Step 1: Get API key

If you are solving this exercise in a KNIME learnathon event, provide the username and password in the "Get API Key" component to access the OpenAI API keys. Seek guidance from the organizers on how to get the credentials.

If you're solving this exercise at home, drag and drop the Credentials Configuration. Paste in the settings 'password' your own OpenAI API key. Pass the credential flow variable to the downstream Authenticator.

Execute the OpenAI Authenticator to check if the API key is working.

Step 2: Select an LLM model

Search, drag and drop an OpenAI LLM Connector. You can use default settings initially and come back to this later. Recommended: 'gpt-3.5-turbo-instruct'.

Step 3: Engineer a prompt for email alerts and feed it to the LLM

Search, drag and drop a String Manipulation, and connect it to the output of Part B.
Structure a prompt to create an email alert for each of the contracts.

Next, prompt the LLM with an LLM Prompter.
Experiment with different prompts and model settings.
What happens if you change the temperature in the OpenAI LLM Connector and re-execute?

Step 4: Visualize the LLM output

Visualize the alert message produced by the LLM Prompter with a String Format Manager (set 'between words') and Table View (set 'Row Height > Custom > 500').


E) Deploy Fraud Detection with GenAI Alert on KNIME Business Hub (OPTIONAL)

See workflow 02. GenAI Learnathon_Deployment_Exercise in learnathon folder.

B) Analytics Workflow:
Outlier Detection for Frauds

Step 1: Perform outlier detection

Search, drag and drop a Numeric Outliers to perform an automated detection of extreme values for the column 'payments' using the interquartile range.

Step 2: Inspect the detected outliers

Search, drag and drop a Tile View to visualize the first output of the Numeric Outliers.

Are those the same contracts you visually detected in Part A?

What happens if you change k in the Numeric Outliers settings?

Step 3: Save outlier detection model for Part E

Search, drag and drop a Model Writer to save to disk the last output of the Numeric Outlier node (blue port). This will save the model for later when we want to apply the same technique on a new contract.

A) Analytics Workflow:
Visual Detection for Frauds

Step 1: Blend extracted contracts data with a database

Search, drag and drop a Value Lookup to create a single table with all the available information you have on contracts.

Step 2: Prepare data for visualization

Search, drag and drop a Sorter to sort the rows by date.

Step 3: Visualize contract data

Visually inspect the 'payment' column to spot frauds via at least two view nodes. We recommend: Bar Chart, Scatter Plot, Histogram and Box Plot.

Step 4: Create a dashboard data app with multiple charts

To display all your chart in the same view, you need to create a Component. Select all the view nodes (Ctrl + Left Click) then Right Click > Create Component.

Next, go inside the component (Right Click > Component > Open component) and customize the layout (Open layout editor in top toolbar).

Step 5: Visually detect frauds in the data app

Open the component composite view.

Can you visually detect frauds by investigating odd values in the payment column?

You can optionally add: a title via a Text View, and interactivity by adding a Table View inside the component and configure it to 'Show only selected rows'.

D) Enriching Analytics with GenAI: Providing Context for Email Alerts

Step 1: Segment knowledge base PDF in sections

Search, drag and drop a Sentence Extractor and apply it to the PDF Parser output, that is the document describing different types of investments. This will segment the document into rows, each containing a different sentence from the PDF.

Step 2: Create a vector store from the segmented knowledge base

Search, drag and drop a FAISS Vector Store Creator to convert the text sections in vectors and store them in a FAISS vector store. Connect the input embeddings model from the OpenAI Embeddings Connector. Save the Vector Store for Part E by adding a Model Writer node.

Step 3: Retrieve text describing the contract type of detected frauds

Search, drag and drop a Vector Store Retriever to search in the vector store the relevant sentences describing the contract types for the detected frauds in Part B. Connect as first input the vector store, and as second input the Tile View output from Part B. Select 'type' in the settings.

Step 4: Engineer a prompt for email alerts with contract type context

Similarly to Step 3 of Part C, search, drag and drop a String Manipulation
to engineer the prompt generating the alert emails.
This time add the context from the vector store to explain the contract type.

Step 5: Perform retrieval augmented generation (RAG)

Like in Part C, search, drag and drop an LLM Prompter, and feed it with the output of the String Manipulation.

Finally, visualize the generated emails via the provided component.

Data Wrangling: Access, Blending, Manipulation

Simple GenAI Adoption for generating an alert email

Advanced GenAI Adoption for generating an alert email

Fraud Detection via Analytics

PDF Parser
double-click to open
Hint for prompt engineering
visualize & downloademail alerts
Email Preview
PDF Parser
double-click to open
Hint for prompt engineering
Extract Contract Data
OpenAI Embeddings Connector
Double-click to configure
Get API Key
OpenAI Authenticator
DB Table Selector
SQLite Connector
DB Reader

Nodes

Extensions

Links