FirstBatch SDK
  • Get Started
    • Introduction
    • Installation
    • Quick Start
  • Learn
    • Key Concepts
      • Embeddings
      • Vector Databases
      • User Embeddings
    • Sessions
    • Signals
    • Batches
    • Algorithms
      • Batch Types
        • Random
        • Sampled
        • Personalized
        • Biased
      • Parameters & Tuning
    • Cookbook
      • Simple Flask App
      • Personalized RSS Feed
      • Personalized Mini TikTok
      • User-Intent AI Agents
      • Extending RAG: User Embeddings
      • Prompt Based User Journeys
      • User-Centric Promoted Content
  • Modules
    • FirstBatch
    • Algorithms
    • VectorStores
      • Pinecone
      • Weaviate
      • Qdrant
      • Typesense
      • Supabase
      • Chroma
Powered by GitBook
On this page
  1. Modules
  2. VectorStores

Typesense

FirstBatch integrates Typesense through the Typesense Class.

Example run:

import typesense
from firstbatch import TypeSense

embedding_size = int(os.environ["EMBEDDING_SIZE"])
client = typesense.Client({
    'api_key': os.environ["TYPESENSE_API_KEY"],
    'nodes': [{
        'host': 'localhost',
        'port': '8108',
        'protocol': 'http'
    }],
    'connection_timeout_seconds': 2
})
config = Config(batch_size=20, verbose=True)
personalized = FirstBatch(api_key=os.environ["FIRSTBATCH_API_KEY"], config=config)
personalized.add_vdb("typesense_db", TypeSense(client=client, collection_name="default", embedding_size=embedding_size))

Distance metric can explicitly be provided. If not, default value is COSINE_SIM

class DistanceMetric(Enum):
    COSINE_SIM = "cosine_sim"
    EUCLIDEAN_DIST = "euclidean_dist"
    DOT_PRODUCT = "dot_product"
from firstbatch import DistanceMetric

TypeSense(client=client, collection_name="default", 
distance_metric=DistanceMetric.EUCLIDEAN_DIST)W

FirstBatch integrates Typesense through the Typesense class.

First, we create a VectorStore instance:

import {Client as TypesenseClient} from 'typesense';
import {Typesense} from 'firstbatch';

// create a Typesense client
const client = new TypesenseClient({
  apiKey: 'your-api-key',
  nodes: [
    {
      host: 'your-host',
      port: 1111, // your port
      protocol: 'http',
    },
  ],
});

// instantiate the vector store
vs = new Typesense(client);
await personalized.addVdb('my_db', vs);

The Typesense vector store also accepts an optional arguments:

  • collectionName collection to connect to

  • embeddingSize vector embedding dimension

  • historyField the name of the field for filtering that avoids previously retrieved data

  • distanceMetrics the distance metric

PreviousQdrantNextSupabase

Last updated 1 year ago

Then, we can use the method to register our client to the SDK:

Add a VectorDB