embeddings = InfinityEmbeddingsLocal(
model="sentence-transformers/all-MiniLM-L6-v2",
# revision
revision=None,
# best to keep at 32
batch_size=32,
# for AMD/Nvidia GPUs via torch
device="cuda",
# warm up model before execution
)
async def embed():
# TODO: This function is just to showcase that your call can run async.
# important: use engine inside of `async with` statement to start/stop the batching engine.
async with embeddings:
# avoid closing and starting the engine often.
# rather keep it running.
# you may call `await embeddings.__aenter__()` and `__aexit__()
# if you are sure when to manually start/stop execution` in a more granular way
documents_embedded = await embeddings.aembed_documents(documents)
query_result = await embeddings.aembed_query(query)
print("embeddings created successful")
return documents_embedded, query_result