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

Kdbai rest compatible #14511

Merged
merged 5 commits into from
Jul 2, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def __init__(

if hybrid_search:
if sparse_encoder is None:
if kdbai.version("kdbai_client") >= "1.2.0":
self._sparse_encoder = default_sparse_encoder_v2
else:
if isinstance(self._table, kdbai.Table):
self._sparse_encoder = default_sparse_encoder_v1
elif isinstance(self._table, kdbai.TablePyKx):
self._sparse_encoder = default_sparse_encoder_v2
else:
self._sparse_encoder = sparse_encoder

Expand Down Expand Up @@ -129,17 +129,17 @@ def add(
df = pd.DataFrame()
docs = []

if kdbai.version("kdbai_client") >= "1.2.0":
if isinstance(self._table, kdbai.Table):
schema = self._table.schema()["columns"]
elif isinstance(self._table, kdbai.TablePyKx):
schema = self._table.schema["schema"]["c"]
types = self._table.schema["schema"]["t"].decode("utf-8")
else:
schema = self._table.schema()["columns"]

if self.hybrid_search:
if kdbai.version("kdbai_client") >= "1.2.0":
schema = [item for item in schema if item != "sparseVectors"]
else:
if isinstance(self._table, kdbai.Table):
schema = [item for item in schema if item["name"] != "sparseVectors"]
elif isinstance(self._table, kdbai.TablePyKx):
schema = [item for item in schema if item != "sparseVectors"]

try:
for node in nodes:
Expand All @@ -154,7 +154,17 @@ def add(

# handle extra columns
if len(schema) > len(DEFAULT_COLUMN_NAMES):
if kdbai.version("kdbai_client") >= "1.2.0":
if isinstance(self._table, kdbai.Table):
for column in schema[len(DEFAULT_COLUMN_NAMES) :]:
try:
doc[column["name"]] = convert_metadata_col_v1(
column, node.metadata[column["name"]]
)
except Exception as e:
logger.error(
f"Error writing column {column['name']} as type {column['pytype']}: {e}."
)
elif isinstance(self._table, kdbai.TablePyKx):
for column_name, column_type in zip(
schema[len(DEFAULT_COLUMN_NAMES) :],
types[len(DEFAULT_COLUMN_NAMES) :],
Expand All @@ -167,16 +177,6 @@ def add(
logger.error(
f"Error writing column {column_name} as qtype {column_type}: {e}."
)
else:
for column in schema[len(DEFAULT_COLUMN_NAMES) :]:
try:
doc[column["name"]] = convert_metadata_col_v1(
column, node.metadata[column["name"]]
)
except Exception as e:
logger.error(
f"Error writing column {column['name']} as type {column['pytype']}: {e}."
)

docs.append(doc)

Expand Down Expand Up @@ -216,10 +216,10 @@ def query(self, query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResul
if self.hybrid_search:
alpha = query.alpha if query.alpha is not None else 0.5

if kdbai.version("kdbai_client") >= "1.2.0":
sparse_vectors = [self._sparse_encoder([query.query_str])]
else:
if isinstance(self._table, kdbai.Table):
sparse_vectors = self._sparse_encoder([query.query_str])
elif isinstance(self._table, kdbai.TablePyKx):
sparse_vectors = [self._sparse_encoder([query.query_str])]

results = self._table.hybrid_search(
dense_vectors=[query.query_embedding],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ exclude = ["**/BUILD"]
license = "MIT"
name = "llama-index-vector-stores-kdbai"
readme = "README.md"
version = "0.1.7"
version = "0.1.8"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
Expand Down
Loading