Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast protobuf #67

Merged
merged 2 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 42 additions & 41 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ tqdm = "^4.56.0"
loguru = "^0.5.3"
typing-extensions = "^4.0.0"
grpcio = { version = "^1.46.0", allow-prereleases = true }
betterproto = { version = "2.0.0b4", allow-prereleases = true }
nest-asyncio = "^1.5.5"
grpcio-tools = "^1.48.0"

[tool.poetry.dev-dependencies]
pytest = "^7.1"
Expand Down
20 changes: 0 additions & 20 deletions qdrant_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
__version__ = '0.1.0'

from .qdrant_client import QdrantClient


def _in_ipython() -> bool:
"""
Check whether we're in an ipython environment, including jupyter notebooks.
"""
try:
eval('__IPYTHON__')
except NameError:
return False
else: # pragma: no cover
return True


if _in_ipython(): # pragma: no cover
# Python asyncio design is mediocre, it is not possible to await for a future, if there is another loop running.
# Ipython uses asyncio, which makes it impossible to run other async functions, so we need to monkey-patch it.
# It might be dangerous to do this in production, so we are doing it for Jupyter notebooks only.
import nest_asyncio
nest_asyncio.apply()
29 changes: 29 additions & 0 deletions qdrant_client/connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Optional

import grpc


def get_channel(host: str, port: int, ssl: bool, metadata: Optional[list] = None) -> grpc.Channel:
if ssl:

if metadata:
def metadata_callback(context, callback):
# for more info see grpc docs
callback(metadata, None)

# build ssl credentials using the cert the same as before
cert_creds = grpc.ssl_channel_credentials()

# now build meta data credentials
auth_creds = grpc.metadata_call_credentials(metadata_callback)

# combine the cert credentials and the macaroon auth credentials
# such that every call is properly encrypted and authenticated
creds = grpc.composite_channel_credentials(cert_creds, auth_creds)
else:
creds = grpc.ssl_channel_credentials()

# finally pass in the combined credentials when creating a channel
return grpc.secure_channel(f'{host}:{port}', creds)
else:
return grpc.insecure_channel(f'{host}:{port}')
11 changes: 4 additions & 7 deletions qdrant_client/conversions/common_types.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
from typing import Union, Type, List, Optional

import betterproto
from pydantic import BaseModel
from typing import Union, List

from qdrant_client import grpc as grpc
from qdrant_client.http import models as rest
from qdrant_client import grpc

Filter = Union[rest.Filter, grpc.Filter]
SearchParams = Union[rest.SearchParams, grpc.SearchParams]
PayloadSelector = Union[rest.PayloadSelector, grpc.WithPayloadSelector]
Distance = Union[rest.Distance, grpc.Distance]
Distance = Union[rest.Distance, int] # type(grpc.Distance) == int
HnswConfigDiff = Union[rest.HnswConfigDiff, grpc.HnswConfigDiff]
OptimizersConfigDiff = Union[rest.OptimizersConfigDiff, grpc.OptimizersConfigDiff]
WalConfigDiff = Union[rest.WalConfigDiff, grpc.WalConfigDiff]
PointId = Union[int, str, grpc.PointId]
PayloadSchemaType = Union[rest.PayloadSchemaType, rest.PayloadSchemaParams, grpc.PayloadSchemaType]
PayloadSchemaType = Union[rest.PayloadSchemaType, rest.PayloadSchemaParams, int] # type(grpc.PayloadSchemaType) == int
Points = Union[rest.Batch, List[Union[rest.PointStruct, grpc.PointStruct]]]
PointsSelector = Union[rest.PointsSelector, grpc.PointsSelector]
AliasOperations = Union[
Expand Down
Loading