0.10.3 • Published 8 months ago

@agentica/pg-selector v0.10.3

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

pg-selector

GitHub license npm version

A library that significantly accelerates AI function selection through vector embeddings.

Overview

@agentica/pg-selector drastically improves function selection speed compared to traditional LLM-based methods. By leveraging vector embeddings and semantic similarity, it can identify the most appropriate functions for a given context multiple times faster than conventional approaches.

import { Agentica } from "@agentica/core";
import { AgenticaPgVectorSelector } from "@agentica/pg-selector";

import typia from "typia";


// Initialize with connector-hive server
const selectorExecute = AgenticaPgVectorSelector.boot<"chatgpt">(
  'https://your-connector-hive-server.com'
);


const agent = new Agentica({
  model: "chatgpt",
  vendor: {
    model: "gpt-4o-mini",
    api: new OpenAI({
      apiKey: process.env.CHATGPT_API_KEY,
    }),
  },
  controllers: [
    await fetch(
      "https://shopping-be.wrtn.ai/editor/swagger.json",
    ).then(r => r.json()),
    typia.llm.application<ShoppingCounselor>(),
    typia.llm.application<ShoppingPolicy>(),
    typia.llm.application<ShoppingSearchRag>(),
  ],
  config: {
    executor: {
      select: selectorExecute,
    }
  }
});
await agent.conversate("I wanna buy MacBook Pro");

How to Use

Setup

npm install @agentica/core @agentica/pg-selector typia
npx typia setup

To use pg-selector, you need:

  1. A running connector-hive server
  2. PostgreSQL database connected to the connector-hive server
  3. pgvector extension installed in PostgreSQL

Initialization

First, initialize the library with your connector-hive server:

import { AgenticaPgVectorSelector } from 'pg-selector';

const selectorExecute = AgenticaPgVectorSelector.boot<YourSchemaModel>(
  'https://your-connector-hive-server.com'
);

Just apply Selector and Start conversation

Select the most appropriate functions for a given context:

const agent = new Agentica({
  model: "chatgpt",
  vendor: {
    model: "gpt-4o-mini",
    api: new OpenAI({
      apiKey: process.env.CHATGPT_API_KEY,
    }),
  },
  controllers: [
    await fetch(
      "https://shopping-be.wrtn.ai/editor/swagger.json",
    ).then(r => r.json()),
    typia.llm.application<ShoppingCounselor>(),
    typia.llm.application<ShoppingPolicy>(),
    typia.llm.application<ShoppingSearchRag>(),
  ],
  config: {
    executor: {
      select: selectorExecute,
    }
  }
});
await agent.conversate("I wanna buy MacBook Pro");