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

Fix detection of Amazon OpenSearch Serverless #14591

Closed
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 @@ -81,14 +81,16 @@ def _validate_aoss_with_engines(is_aoss: bool, engine: str) -> None:


def _is_aoss_enabled(http_auth: Any) -> bool:
"""Check if the service is http_auth is set as `aoss`."""
if (
http_auth is not None
and hasattr(http_auth, "service")
and http_auth.service == "aoss"
):
return True
return False
"""Check if service attribute of http_auth is set to `aoss`."""
if http_auth is not None:
if hasattr(http_auth, "service") and http_auth.service == "aoss":
return True
elif hasattr(http_auth, "signer") and http_auth.signer.service == "aoss":
return True
else:
return False
else:
return False


def _bulk_ingest_embeddings(
Expand Down
4 changes: 4 additions & 0 deletions libs/community/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ msal = {version = "^1.25.0", optional = true}
databricks-vectorsearch = {version = "^0.21", optional = true}
dgml-utils = {version = "^0.3.0", optional = true}
datasets = {version = "^2.15.0", optional = true}
requests-aws4auth = {version = "^1.2.3", optional = true}
opensearch-py = {version = "^2.4.2", optional = true}

[tool.poetry.group.test]
optional = true
Expand Down Expand Up @@ -241,6 +243,8 @@ extended_testing = [
"databricks-vectorsearch",
"dgml-utils",
"cohere",
"opensearch-py",
"requests-aws4auth",
]

[tool.ruff]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import pytest
from pytest_mock import MockerFixture

from langchain_community.embeddings import FakeEmbeddings
from langchain_community.vectorstores.opensearch_vector_search import (
OpenSearchVectorSearch,
)


@pytest.mark.requires("opensearchpy")
@pytest.mark.parametrize(["service", "expected"], [("aoss", True), ("es", False)])
def test_detect_aoss_using_signer_auth(
mocker: MockerFixture, service: str, expected: bool
) -> None:
from opensearchpy import RequestsAWSV4SignerAuth

mocker.patch.object(RequestsAWSV4SignerAuth, "_sign_request")
http_auth = RequestsAWSV4SignerAuth(
credentials="credentials", region="eu-central-1", service=service
)
database = OpenSearchVectorSearch(
opensearch_url="http://localhost:9200",
index_name="test",
embedding_function=FakeEmbeddings(size=42),
http_auth=http_auth,
)

assert database.is_aoss == expected


@pytest.mark.requires("opensearchpy")
@pytest.mark.requires("requests_aws4auth")
@pytest.mark.parametrize(["service", "expected"], [("aoss", True), ("es", False)])
def test_detect_aoss_using_aws4auth(service: str, expected: bool) -> None:
from requests_aws4auth import AWS4Auth

http_auth = AWS4Auth("access_key_id", "secret_access_key", "eu-central-1", service)
database = OpenSearchVectorSearch(
opensearch_url="http://localhost:9200",
index_name="test",
embedding_function=FakeEmbeddings(size=42),
http_auth=http_auth,
)

assert database.is_aoss == expected


@pytest.mark.requires("opensearchpy")
def test_detect_aoss_using_no_auth() -> None:
database = OpenSearchVectorSearch(
opensearch_url="http://localhost:9200",
index_name="test",
embedding_function=FakeEmbeddings(size=42),
)

assert database.is_aoss is False
Loading