mirror of
https://github.com/qdrant/qdrant-client.git
synced 2026-07-30 14:41:03 -05:00
* wip: add draft implementation of batch processing * fix: embed dict and list of docs, remove redundant code * new: regen async, small refactor * refactor: add docstrings, rename methods * Upload points local inference (#881) * new: separate single and plural model embeddings * fix: fix lazy embed models * new: add inference object inspections to upload methods * wip: local inference upload parallel * new: add local inference to upload points and upload collection, refactor mixin * fix: remove redundant code * redundant import * tests: check is query for query points batch * refactor: refactor semi ordered map * tests: add test for local inference with batches with docs and vectors * tests: check the order of dict processing * new: distinguish models by options * fix: fix typing * fix: fix types * new: embed batches with different options * tests: add tests for batch with different options * fix: ignore ide incorrect type inspection * tests: wait for points to be inserted * fix: set threads to 1 in parallel inference * new: adjust max internal batch size * fix: fix type hints * function to get embeddings size (#892) * function to get embeddings size * async client * keep sync * new: extend embedding size to support image and late interaction models --------- Co-authored-by: George Panchuk <george.panchuk@qdrant.tech> * new: add local inference batch size (#894) --------- Co-authored-by: Andrey Vasnetsov <andrey@vasnetsov.com>
79 lines
2.8 KiB
Python
79 lines
2.8 KiB
Python
import inspect
|
|
from typing import Optional
|
|
|
|
from tools.async_client_generator.async_client_base import AsyncQdrantBase
|
|
from tools.async_client_generator.base_generator import BaseGenerator
|
|
from tools.async_client_generator.transformers import (
|
|
ClassDefTransformer,
|
|
ImportFromTransformer,
|
|
ImportTransformer,
|
|
)
|
|
from tools.async_client_generator.transformers.fastembed import (
|
|
FastembedCallTransformer,
|
|
FastembedFunctionDefTransformer,
|
|
)
|
|
|
|
|
|
class FastembedGenerator(BaseGenerator):
|
|
def __init__(
|
|
self,
|
|
keep_sync: Optional[list[str]] = None,
|
|
class_replace_map: Optional[dict[str, str]] = None,
|
|
import_replace_map: Optional[dict[str, str]] = None,
|
|
):
|
|
super().__init__()
|
|
self._async_methods: Optional[list[str]] = None
|
|
self.transformers.append(FastembedCallTransformer(async_methods=self.async_methods))
|
|
self.transformers.append(ClassDefTransformer(class_replace_map=class_replace_map))
|
|
self.transformers.append(ImportTransformer(import_replace_map=import_replace_map))
|
|
self.transformers.append(ImportFromTransformer(import_replace_map=import_replace_map))
|
|
self.transformers.append(FastembedFunctionDefTransformer(keep_sync=keep_sync))
|
|
|
|
@property
|
|
def async_methods(self) -> list[str]:
|
|
if self._async_methods is None:
|
|
self._async_methods = self.get_async_methods(AsyncQdrantBase)
|
|
return self._async_methods
|
|
|
|
@staticmethod
|
|
def get_async_methods(class_obj: type) -> list[str]:
|
|
async_methods = []
|
|
for name, method in inspect.getmembers(class_obj):
|
|
if inspect.iscoroutinefunction(method):
|
|
async_methods.append(name)
|
|
return async_methods
|
|
|
|
|
|
if __name__ == "__main__":
|
|
from tools.async_client_generator.config import CLIENT_DIR, CODE_DIR
|
|
|
|
with open(CLIENT_DIR / "qdrant_fastembed.py", "r") as source_file:
|
|
code = source_file.read()
|
|
|
|
generator = FastembedGenerator(
|
|
keep_sync=[
|
|
"__init__",
|
|
"set_model",
|
|
"set_sparse_model",
|
|
"get_vector_field_name",
|
|
"get_sparse_vector_field_name",
|
|
"get_embedding_size",
|
|
"get_fastembed_vector_params",
|
|
"get_fastembed_sparse_vector_params",
|
|
"embedding_model_name",
|
|
"sparse_embedding_model_name",
|
|
],
|
|
class_replace_map={
|
|
"QdrantBase": "AsyncQdrantBase",
|
|
"QdrantFastembedMixin": "AsyncQdrantFastembedMixin",
|
|
},
|
|
import_replace_map={
|
|
"qdrant_client.client_base": "qdrant_client.async_client_base",
|
|
"QdrantBase": "AsyncQdrantBase",
|
|
},
|
|
)
|
|
modified_code = generator.generate(code)
|
|
|
|
with open(CODE_DIR / "async_qdrant_fastembed.py", "w") as target_file:
|
|
target_file.write(modified_code)
|