From ff4215cad9975473071a52ad5c8f891c116eab7a Mon Sep 17 00:00:00 2001 From: Aydin Abiar Date: Fri, 20 Dec 2024 20:29:42 +0000 Subject: [PATCH 1/5] bugfix when initializing with async aoss --- .../vector_stores/opensearch/base.py | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py b/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py index 034197cb484c1..9aa3870cd31cb 100644 --- a/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py +++ b/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py @@ -3,7 +3,7 @@ import uuid from datetime import datetime from typing import Any, Dict, Iterable, List, Optional, Union, cast - +import asyncio from llama_index.core.bridge.pydantic import PrivateAttr from llama_index.core.schema import BaseNode, MetadataMode, TextNode @@ -123,14 +123,18 @@ def __init__( self._os_async_client = os_async_client or self._get_async_opensearch_client( self._endpoint, **kwargs ) - self._os_version = self._get_opensearch_version() - self._efficient_filtering_enabled = self._is_efficient_filtering_enabled( - self._os_version - ) + self._efficient_filtering_enabled = self._is_efficient_filtering_enabled() not_found_error = self._import_not_found_error() try: self._os_client.indices.get(index=self._index) + except TypeError: + # Probably using async so switch to async client + try: + asyncio.run(self._os_async_client.indices.get(index=self._index)) + except not_found_error: + asyncio.run(self._os_async_client.indices.create(index=self._index, body=idx_conf)) + asyncio.run(self._os_async_client.indices.refresh(index=self._index)) except not_found_error: self._os_client.indices.create(index=self._index, body=idx_conf) self._os_client.indices.refresh(index=self._index) @@ -617,10 +621,18 @@ def _is_aoss_enabled(self, http_auth: Any) -> bool: return True return False - def _is_efficient_filtering_enabled(self, os_version: str) -> bool: + def _is_efficient_filtering_enabled(self) -> bool: """Check if kNN with efficient filtering is enabled.""" - major, minor, patch = os_version.split(".") - return int(major) >= 2 and int(minor) >= 9 + # Technically, AOSS supports efficient filtering, + # but we can't check the version number using .info(); AOSS doesn't support 'GET /' + # so we must skip and disable by default. + if self.is_aoss: + ef_enabled = False + else : + self._os_version = self._get_opensearch_version() + major, minor, patch = os_version.split(".") + ef_enabled = int(major) >= 2 and int(minor) >= 9 + return ef_enabled def index_results(self, nodes: List[BaseNode], **kwargs: Any) -> List[str]: """Store results in the index.""" From 6be80507465cc371038c0a66c7e5a0dbd0210f2f Mon Sep 17 00:00:00 2001 From: Aydin Abiar Date: Fri, 20 Dec 2024 21:38:06 +0000 Subject: [PATCH 2/5] fix self.os_version error --- .../llama_index/vector_stores/opensearch/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py b/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py index 9aa3870cd31cb..89071c37edd76 100644 --- a/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py +++ b/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py @@ -630,7 +630,7 @@ def _is_efficient_filtering_enabled(self) -> bool: ef_enabled = False else : self._os_version = self._get_opensearch_version() - major, minor, patch = os_version.split(".") + major, minor, patch = self.os_version.split(".") ef_enabled = int(major) >= 2 and int(minor) >= 9 return ef_enabled From 48add0f23ab293037010baa4cde8a802695341cb Mon Sep 17 00:00:00 2001 From: Logan Markewich Date: Fri, 20 Dec 2024 16:13:33 -0600 Subject: [PATCH 3/5] lint --- .../llama_index/vector_stores/opensearch/base.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py b/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py index 89071c37edd76..7c56873b9bca9 100644 --- a/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py +++ b/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py @@ -133,7 +133,11 @@ def __init__( try: asyncio.run(self._os_async_client.indices.get(index=self._index)) except not_found_error: - asyncio.run(self._os_async_client.indices.create(index=self._index, body=idx_conf)) + asyncio.run( + self._os_async_client.indices.create( + index=self._index, body=idx_conf + ) + ) asyncio.run(self._os_async_client.indices.refresh(index=self._index)) except not_found_error: self._os_client.indices.create(index=self._index, body=idx_conf) @@ -623,12 +627,12 @@ def _is_aoss_enabled(self, http_auth: Any) -> bool: def _is_efficient_filtering_enabled(self) -> bool: """Check if kNN with efficient filtering is enabled.""" - # Technically, AOSS supports efficient filtering, + # Technically, AOSS supports efficient filtering, # but we can't check the version number using .info(); AOSS doesn't support 'GET /' # so we must skip and disable by default. - if self.is_aoss: + if self.is_aoss: ef_enabled = False - else : + else: self._os_version = self._get_opensearch_version() major, minor, patch = self.os_version.split(".") ef_enabled = int(major) >= 2 and int(minor) >= 9 From c380264de4d394d53812b95a56f8b67b26ab696a Mon Sep 17 00:00:00 2001 From: Logan Markewich Date: Fri, 20 Dec 2024 16:14:06 -0600 Subject: [PATCH 4/5] vbump --- .../llama-index-vector-stores-opensearch/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/pyproject.toml b/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/pyproject.toml index 3db3fcc2ebbfc..db6d509ebb7b7 100644 --- a/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/pyproject.toml +++ b/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/pyproject.toml @@ -27,7 +27,7 @@ exclude = ["**/BUILD"] license = "MIT" name = "llama-index-vector-stores-opensearch" readme = "README.md" -version = "0.5.0" +version = "0.5.1" [tool.poetry.dependencies] python = ">=3.9,<4.0" From ada5dec05ab45e949b1602742c50f0d81fd6ee94 Mon Sep 17 00:00:00 2001 From: Logan Markewich Date: Mon, 23 Dec 2024 10:45:00 -0600 Subject: [PATCH 5/5] use asyncio_run --- .../llama_index/vector_stores/opensearch/base.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py b/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py index 7c56873b9bca9..3acb9291c2aab 100644 --- a/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py +++ b/llama-index-integrations/vector_stores/llama-index-vector-stores-opensearch/llama_index/vector_stores/opensearch/base.py @@ -3,9 +3,9 @@ import uuid from datetime import datetime from typing import Any, Dict, Iterable, List, Optional, Union, cast -import asyncio -from llama_index.core.bridge.pydantic import PrivateAttr +from llama_index.core.async_utils import asyncio_run +from llama_index.core.bridge.pydantic import PrivateAttr from llama_index.core.schema import BaseNode, MetadataMode, TextNode from llama_index.core.vector_stores.types import ( FilterCondition, @@ -131,14 +131,14 @@ def __init__( except TypeError: # Probably using async so switch to async client try: - asyncio.run(self._os_async_client.indices.get(index=self._index)) + asyncio_run(self._os_async_client.indices.get(index=self._index)) except not_found_error: - asyncio.run( + asyncio_run( self._os_async_client.indices.create( index=self._index, body=idx_conf ) ) - asyncio.run(self._os_async_client.indices.refresh(index=self._index)) + asyncio_run(self._os_async_client.indices.refresh(index=self._index)) except not_found_error: self._os_client.indices.create(index=self._index, body=idx_conf) self._os_client.indices.refresh(index=self._index)