Saturday, June 15, 2024
HomeArtificial IntelligencePrompt AI Mannequin Tuning: Leveraging HNSW Vector with Firebase Genkit for Retrieval-Augmented...

Prompt AI Mannequin Tuning: Leveraging HNSW Vector with Firebase Genkit for Retrieval-Augmented Era | by Surahutomo Aziz Pradana | Could, 2024

Now let’s apply to study extra how we are able to construct such an AI Answer!


Earlier than putting in the plugin, guarantee you may have the next put in:

  • Node.js (model 12 or greater)
  • npm (comes with Node.js)
  • TypeScript (set up globally by way of npm: npm set up -g typescript)
  • Genkit (set up globally by way of npm: npm set up -g genkit)

Very first thing first, provoke the Genkit mission with

genkit init

observe the directions right here.

After getting the Genkit mission put in, make certain the mission is effectively ready. You possibly can strive first by

genkit begin

If it runs effectively and open the Genkit UI in a browser, then you might be good to go!

Putting in the HNSW plugin

To put in the Genkit HNSW plugin, run the next command:

npm set up genkitx-hnsw

We can be utilizing 2 Genkit Plugins right here.

  1. HNSW Indexer plugin
  2. HNSW Retriever plugin

1. HNSW Indexer Plugin

The HNSW Indexer plugin helps create a vector index out of your knowledge, which can be utilized as a data reference for the HNSW Retriever.

Knowledge Preparation

Put together your knowledge or paperwork, as an example, restaurant knowledge, in a devoted folder.

Registering the HNSW Indexer Plugin

Import the plugin into your Genkit mission:

discover genkit.config.ts file in your mission, often /root/src/genkit.config.ts.

Then import the plugin into the file.

import { hnswIndexer } from "genkitx-hnsw";
export default configureGenkit({
plugins: [
hnswIndexer({ apiKey: "GOOGLE_API_KEY" })

Working the Indexer

  1. Open the Genkit UI and choose the registered HNSW Indexer plugin.
  2. Execute the circulate with the required parameters:
  • dataPath: Path to your knowledge and paperwork.
  • indexOutputPath: Desired output path for the generated vector retailer index.

Vector Retailer Index Outcome

The HNSW vector retailer can be saved within the specified output path, prepared to be used with the HNSW Retriever plugin.

The HNSW Retriever plugin processes immediate with the Gemini LLM Mannequin, enriched with extra particular info from the HNSW Vector index.

Registering the HNSW Retriever Plugin

Import the mandatory plugins into your Genkit mission:

import { googleAI } from "@genkit-ai/googleai";
import { hnswRetriever } from "genkitx-hnsw";
export default configureGenkit({
plugins: [
hnswRetriever({ apiKey: "GOOGLE_API_KEY" })

Working the Retriever

  1. Open the Genkit UI and choose the HNSW Retriever plugin.
  2. Execute the circulate with the required parameters:
  • immediate: Your enter question is for the AI.
  • indexPath: Path to the vector index file generated by the HNSW Indexer plugin.

Instance Immediate

To ask concerning the worth record of a restaurant in Surabaya Metropolis:

immediate: "What's the worth record of my restaurant in Surabaya Metropolis?"
indexPath: "/path/to/your/vector/index"

The mixing of HNSW Vector index with Genkit considerably enhances the capabilities of Generative AI fashions by offering enriched context and particular data.

This method not solely improves the accuracy of AI responses but in addition simplifies the method of data integration, making it a robust device for varied functions.

By following the steps outlined on this article, you possibly can successfully leverage the HNSW Vector index to construct extra clever and context-aware AI techniques in a really quick time like immediately!

Hope this helps and see you within the subsequent one!



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments