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

Last updated