-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an specific embedded Infinity python module (#1792)
### What problem does this PR solve? - Create an specific embedded Infinity python module - delete embedded infinity in old infinity_sdk Issue link:#1786 ### Type of change - [x] New Feature (non-breaking change which adds functionality) - [x] Python SDK impacted, Need to update PyPI --------- Co-authored-by: Zhichang Yu <[email protected]>
- Loading branch information
1 parent
cb0d0b3
commit 67f0720
Showing
50 changed files
with
1,074 additions
and
378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright(C) 2023 InfiniFlow, Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# import importlib.metadata | ||
# | ||
# __version__ = importlib.metadata.version("infinity_sdk") | ||
|
||
import os | ||
# import pkg_resources | ||
# __version__ = pkg_resources.get_distribution("infinity_sdk").version | ||
|
||
from infinity_embedded.common import URI, NetworkAddress, LOCAL_HOST, LOCAL_INFINITY_PATH, InfinityException | ||
from infinity_embedded.infinity import InfinityConnection | ||
from infinity_embedded.local_infinity.infinity import LocalInfinityConnection | ||
from infinity_embedded.errors import ErrorCode | ||
|
||
def connect(uri) -> InfinityConnection: | ||
if isinstance(uri, str) and len(uri) != 0: | ||
return LocalInfinityConnection(uri) | ||
else: | ||
raise InfinityException(ErrorCode.INVALID_SERVER_ADDRESS, f"Unknown uri: {uri}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright(C) 2023 InfiniFlow, Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from pathlib import Path | ||
from typing import Union | ||
from dataclasses import dataclass | ||
import numpy as np | ||
|
||
|
||
class NetworkAddress: | ||
def __init__(self, ip, port): | ||
self.ip = ip | ||
self.port = port | ||
|
||
def __str__(self): | ||
return f'IP: {self.ip}, Port: {self.port}' | ||
|
||
|
||
@dataclass | ||
class SparseVector: | ||
indices: list[int] | ||
values: Union[list[float], list[int], None] = None | ||
|
||
def __post_init__(self): | ||
assert (self.values is None) or (len(self.indices) == len(self.values)) | ||
|
||
def to_dict_old(self): | ||
d = {"indices": self.indices} | ||
if self.values is not None: | ||
d["values"] = self.values | ||
return d | ||
|
||
def to_dict(self): | ||
if self.values is None: | ||
raise ValueError("SparseVector.values is None") | ||
result = {} | ||
for i, v in zip(self.indices, self.values): | ||
result[str(i)] = v | ||
return result | ||
|
||
@staticmethod | ||
def from_dict(d): | ||
return SparseVector(d["indices"], d.get("values")) | ||
|
||
def __str__(self): | ||
return f"SparseVector(indices={self.indices}{'' if self.values is None else f', values={self.values}'})" | ||
|
||
def __repr__(self): | ||
return str(self) | ||
|
||
|
||
URI = Union[NetworkAddress, Path] | ||
VEC = Union[list, np.ndarray] | ||
INSERT_DATA = dict[str, Union[str, int, float, list[Union[int, float]]], SparseVector, dict] | ||
|
||
LOCAL_HOST = NetworkAddress("127.0.0.1", 23817) | ||
|
||
# test embedded_infinity | ||
LOCAL_INFINITY_PATH = "/var/infinity" | ||
|
||
|
||
class ConflictType(object): | ||
Ignore = 0 | ||
Error = 1 | ||
Replace = 2 | ||
|
||
|
||
class InfinityException(Exception): | ||
def __init__(self, error_code=0, error_message=None): | ||
self.error_code = error_code | ||
self.error_message = error_message | ||
|
||
|
||
DEFAULT_MATCH_VECTOR_TOPN = 10 | ||
DEFAULT_MATCH_SPARSE_TOPN = 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright(C) 2023 InfiniFlow, Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
class Database(ABC): | ||
|
||
@abstractmethod | ||
def create_table(self, table_name, schema, options): | ||
pass # implement create table logic here | ||
|
||
@abstractmethod | ||
def drop_table(self, table_name): | ||
pass # implement drop table logic here | ||
|
||
@abstractmethod | ||
def list_tables(self): | ||
pass # implement list tables logic here | ||
|
||
@abstractmethod | ||
def show_table(self, table_name): | ||
pass # implement describe table logic here | ||
|
||
@abstractmethod | ||
def show_columns(self, table_name): | ||
pass # implement describe table logic here | ||
|
||
@abstractmethod | ||
def get_table(self, table_name): | ||
pass # implement get table logic here | ||
|
||
@abstractmethod | ||
def show_tables(self): | ||
pass |
Oops, something went wrong.