Coder Social home page Coder Social logo

firstbatchxyz / firstbatch-sdk-ts Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 1.0 181 KB

TypeScript SDK for FirstBatch: Real-time Personalization using VectorDBs.

Home Page: https://firstbatch.xyz/

License: MIT License

TypeScript 100.00%
personalization pinecone sdk typesense vector-database vectordb weaviate

firstbatch-sdk-ts's Introduction

logo

FirstBatch SDK

FirstBatch SDK provides an interface for integrating vector databases and powering personalized AI experiences in your application.

License: MIT NPM Discord

  • Seamlessly manage user sessions with persistent IDs or temporary sessions.
  • Send signal actions like likes, clicks, etc. to update user embeddings in real-time.
  • Fetch personalized batches of data tailored to each user's embeddings.
  • Support for multiple vector database integrations: Pinecone, Weaviate, etc.
  • Built-in algorithms for common personalization use cases.

For more information, see the User Embedding Guide or the SDK Documentation.

Installation

Install the package from NPM:

npm install firstbatch  # npm
yarn add firstbatch     # yarn
pnpm add firstbatch     # pnpm

Usage

FirstBatch SDK is used together with an existing vector store, where you register the vector store to our SDK and then create personalization sessions from it.

Adding a Client

First, initialize a Vector Database of your choice; our SDK supports:

Let us go over an example using Pinecone.

import {Pinecone as PineconeClient} from '@pinecone-database/pinecone';
import {Pinecone, FirstBatch, Signals} from 'firstbatch';

// create Pinecone client
const pinecone = new PineconeClient({apiKey: 'pinecone-api-key', environment: 'pinecone-env'});
await pinecone.describeIndex('index-name');
const index = pinecone.index('index-name');

Then, create a Vector Store with this index and pass it in the FirstBatch SDK.

// create SDK
const personalized = await FirstBatch.new('firstbatch-api-key');

// add vector store to SDK
const vectorStore = new Pinecone(index);
const vdbid = 'pinecone-example-db';
await personalized.addVectorStore(vdbid, vectorStore);

Personalization

Now, we can create a session with an algorithm that suits our use-case, and provide personalization to our users.

// create a session
const session = personalized.session('ALGORITHM_NAME', vdbid);

// make recommendations
const [ids, batch] = personalized.batch(session);

Suppose that the user has liked the first content from the batch above. We can provide personalization over this as follows:

// the user liked the first content of the previous batch
const userPick = ids[0];

// signal this to the session
personalized.addSignal(sessionId, Signals.LIKE, userPick);

Here, LIKE signal is one of the many preset signals provided by our SDK. You can also define your own signals:

import type {Signal} from 'firstbatch';

const mySignal: Signal = {label: 'SOME_USER_ACTION', weight: 0.5};

Building

Install the dependencies:

bun install

Then, build everything with:

bun run build
bun b # alternative

Note

If you get an error like "expected content key ... to exist" simply delete the .parcel-cache folder and build again.

Testing

Run all tests via:

bun run test
bun t # alternative

Bun will look for .env.test during the tests.

Styling

Check formatting:

bun format

Lint everything:

bun lint

firstbatch-sdk-ts's People

Contributors

anilaltuner avatar erhant avatar firstbatchdevops avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kerimrock

firstbatch-sdk-ts's Issues

Redundant existence checks during `addVdb`

addVdb checks if the given vectorDB with vdbid exists via an API call. Sometimes we can be SURE that it exists, i.e. we have done the setup and this thing works in a serverless function etc. so we dont have to check for existence in those cases.

It is possible to bypass this by doing:

sdk.store[vdbid] = vectorStore;

instead of

await sdk.addVdb(vdbid, vectorStore);

which saves making an api call.

We can make this clear to the user via docs, perhaps?

`addSignal` return type

  • Currently, it returns response.success
  • In Python, it does not return anything
  • It should perhaps return the new state of DFA for debugging purposes?

Weaviate integration tests

Due to a hidden bug from before, the tests were passing although there were errors within Weaviate integration related to metadata. That is hot-fixed now, but requires further care.

Pinecone metadatas

It may be the case that we are setting the metadata wrong, instead of an object like {id: string, metadata: any} we might have {id: string, metadata: {id: string, data: any}} instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.