Files
qdrant-client/tools/populate_inspection_cache.py
George c152e3c7bf Agnostic local inference (#799)
* new: update previous qdrant version

* new: rollback rest client as types moved to the core

* new: add model_fields_set pydantic compat

* new: add Document to models

* new: add local inference inspectors

* new: add inference functionality to qdrant client

* fix: fix type hints

* fix: fix type hints

* fix: fix type hints

* new: remove _cloud_inference arg from methods

* refactor

* tests: update tests, add path check

* fix: fix type hint

* fix: fix type hint

* fix: resolve plain query

* fix: remove redundant checks

* fix: fix resolve query doc

* tests: add test case for several docs in prefetch

* fix: fix tests

* new: forbid cloud inference with local mode

* fix: fix is_query assignment, fix embed dict

* tests: fix sparse vector values comparison

* fix: regen async

* fix: embed batch

* tests: extend local inference tests

* tests: add update operations and update vectors tests

* tests: remove redundant tests, add plain query points test

* fix: fix type hint

* fix: add missing import

* fix: yet another type hint fix

* tests: add query points groups and query batch points tests

* fix: do not try to embed a vector, comment missed disabled test stmt

* new: add late interaction embeddings without add and query methods

* fix: fix LITE import

* fix: fix problem with retrieving not available path, enable tests

* fix: fix exception message

* refactor: update type hint

* fix: update type hints

* chore: add docstrings to embed methods

* refactor: simplify inspector init

* fix: fix type hint

* new: reuse parser, fix type import

* refactor: rename parser, add docstrings

* fix: fix type hint

* fix: fix type hint

* fix: fix type hint

* refactor: smol refactor, docstrings

* fix: fix inspect embed

* deprecation warning for grpc.PointStruct

* new: populate inspections cache (#823)

* new: populate inspections cache

* fix: fix type hints

* fix: regen async

* fix: fix type hint

* fix: fix typo in filename

* fix: fix points check

* fix: fix type hint
2024-10-29 15:48:23 +01:00

64 lines
2.1 KiB
Python

import importlib.util
import sys
from pathlib import Path
from typing import Union
from pydantic import BaseModel
from qdrant_client import models
from qdrant_client.embed.schema_parser import ModelSchemaParser
from types import ModuleType
def dynamic_import(file_path: Union[str, Path], module_name: str) -> ModuleType:
# Create a module spec from the file path
spec = importlib.util.spec_from_file_location(module_name, file_path)
if spec is None:
raise ImportError(f"Cannot create a spec for module '{module_name}' at '{file_path}'")
# Create a new module based on the spec
module = importlib.util.module_from_spec(spec)
# Execute the module to load its contents
spec.loader.exec_module(module) # type: ignore
# Optionally, add the module to sys.modules to access it globally
sys.modules[module_name] = module
return module
if __name__ == "__main__":
parser = ModelSchemaParser()
for model_name in dir(models):
if not model_name[0].isupper():
continue
model = getattr(models, model_name)
if not isinstance(model, type):
continue
if not issubclass(model, BaseModel) or model == BaseModel:
continue
if "extra" not in model.model_config or model.model_config["extra"] != "forbid": # type: ignore
continue
parser.parse_model(model)
current_path = Path(__name__)
file_path = str(
current_path.parent.parent / "qdrant_client" / "embed" / "_inspection_cache.py"
)
parser._persist(file_path)
module_name = "_inspections_cache"
# Import the newly created file dynamically
_inspections_cache = dynamic_import(file_path, module_name)
result = _inspections_cache.INCLUDED_RECURSIVE_REFS
assert parser.name_recursive_ref_mapping == _inspections_cache.NAME_RECURSIVE_REF_MAPPING
assert parser._defs == _inspections_cache.DEFS
assert parser._recursive_refs == set(_inspections_cache.RECURSIVE_REFS)
assert parser._included_recursive_refs == set(_inspections_cache.INCLUDED_RECURSIVE_REFS)
assert parser._excluded_recursive_refs == set(_inspections_cache.EXCLUDED_RECURSIVE_REFS)