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);
Then, we can use the Add a VectorDB method to register our client to the SDK:
await personalized.addVdb('my_db', vs);
The Typesense vector store also accepts an optional arguments:
collectionName
collection to connect toembeddingSize
vector embedding dimensionhistoryField
the name of the field for filtering that avoids previously retrieved datadistanceMetrics
the distance metric
Last updated