Skip to content

Commit 542476a

Browse files
Add test for OpenSearchDB http_auth initialization
This commit introduces a new test validating the initialization of `OpenSearchDB` with `AWSV4SignerAuth` for HTTP authentication. Additionally, it updates the `poetry.lock` file to reflect dependencies changes with Poetry 2.1.1. Related to mem0ai#2375
1 parent 4be426f commit 542476a

File tree

4 files changed

+212
-604
lines changed

4 files changed

+212
-604
lines changed

mem0/configs/vector_stores/opensearch.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class OpenSearchConfig(BaseModel):
1414
verify_certs: bool = Field(False, description="Verify SSL certificates (default False for OpenSearch)")
1515
use_ssl: bool = Field(False, description="Use SSL for connection (default False for OpenSearch)")
1616
auto_create_index: bool = Field(True, description="Automatically create index during initialization")
17+
http_auth: Optional[object] = Field(None, description="HTTP authentication method / AWS SigV4")
1718

1819
@model_validator(mode="before")
1920
@classmethod
@@ -23,7 +24,7 @@ def validate_auth(cls, values: Dict[str, Any]) -> Dict[str, Any]:
2324
raise ValueError("Host must be provided for OpenSearch")
2425

2526
# Authentication: Either API key or user/password must be provided
26-
if not any([values.get("api_key"), (values.get("user") and values.get("password"))]):
27+
if not any([values.get("api_key"), (values.get("user") and values.get("password")), values.get("http_auth")]):
2728
raise ValueError("Either api_key or user/password must be provided for OpenSearch authentication")
2829

2930
return values

mem0/vector_stores/opensearch.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any, Dict, List, Optional
33

44
try:
5-
from opensearchpy import OpenSearch
5+
from opensearchpy import OpenSearch, RequestsHttpConnection
66
from opensearchpy.helpers import bulk
77
except ImportError:
88
raise ImportError("OpenSearch requires extra dependencies. Install with `pip install opensearch-py`") from None
@@ -28,9 +28,10 @@ def __init__(self, **kwargs):
2828
# Initialize OpenSearch client
2929
self.client = OpenSearch(
3030
hosts=[{"host": config.host, "port": config.port or 9200}],
31-
http_auth=(config.user, config.password) if (config.user and config.password) else None,
31+
http_auth=config.http_auth if config.http_auth else ((config.user, config.password) if (config.user and config.password) else None),
3232
use_ssl=config.use_ssl,
3333
verify_certs=config.verify_certs,
34+
connection_class=RequestsHttpConnection
3435
)
3536

3637
self.collection_name = config.collection_name

0 commit comments

Comments
 (0)