Package genlayer_embeddings#

class genlayer_embeddings.Distance[source]#

Bases: Protocol

__call__(l, r) Any[source]#

Call self as a function.

Return type:

Any

__init__(*args, **kwargs)#
class genlayer_embeddings.EuclideanDistanceSquared[source]#

Bases: Distance

__call__(l, r)[source]#

Call self as a function.

__gl_allow_storage__ = True#
__init__(*args, **kwargs)#
batch(l, r)[source]#
genlayer_embeddings.SentenceTransformer(model: str) Callable[[str], ndarray][source]#
Return type:

Callable[[str], ndarray]

genlayer_embeddings.SentenceTransformerFromPath(path: str) Callable[[str], ndarray][source]#
Return type:

Callable[[str], ndarray]

class genlayer_embeddings.VecDB[source]#

Bases: Generic

Data structure that supports storing and querying vector data using Cover Trees

Cover trees provide logarithmic time nearest neighbor search with theoretical guarantees.

There are two entities that can act as a key:

  1. vector (can have duplicates)

  2. id (int alias, can’t have duplicates)

Warning

import numpy before from genlayer import * if you wish to use VecDB!

Element = Element#
Id = Id#
__gl_allow_storage__ = True#
__init__()[source]#
__iter__()[source]#
__len__() int[source]#
Return type:

int

get_by_id(id: Id) VecDBElement[T, S, V, None][source]#
Return type:

VecDBElement[T, S, V, None]

get_by_id_or_none(id: Id) VecDBElement[T, S, V, None] | None[source]#
Return type:

VecDBElement[T, S, V, None] | None

insert(key: np.ndarray[tuple[S], np.dtype[T]], val: V) Id[source]#
Return type:

Id

knn(v: np.ndarray[tuple[S], np.dtype[T]], k: int) Iterator[VecDBElement[T, S, V, T]][source]#

Find k nearest neighbors using cover tree with pruning

Return type:

Iterator[VecDBElement[T, S, V, T]]

genlayer_embeddings.get_model(model: str, inputs: dict[str, DTypeLike], *, models_db=_ALL_MODELS)[source]#