-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Astra] Change authentication parameters (#423)
* change auth params * make tests unit * linting * fix examples * adjust env vars from secrets * remove conftest
- Loading branch information
Showing
8 changed files
with
92 additions
and
123 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,64 +1,63 @@ | ||
# SPDX-FileCopyrightText: 2023-present Anant Corporation <[email protected]> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import os | ||
|
||
import pytest | ||
from unittest.mock import patch | ||
|
||
from haystack_integrations.components.retrievers.astra import AstraEmbeddingRetriever | ||
from haystack_integrations.document_stores.astra import AstraDocumentStore | ||
|
||
|
||
@pytest.mark.skipif( | ||
os.environ.get("ASTRA_DB_APPLICATION_TOKEN", "") == "", reason="ASTRA_DB_APPLICATION_TOKEN is not set" | ||
@patch.dict( | ||
"os.environ", {"ASTRA_TOKEN": "fake-token", "ASTRA_API_ENDPOINT": "http://fake-url.apps.astra.datastax.com"} | ||
) | ||
@pytest.mark.skipif(os.environ.get("ASTRA_DB_ID", "") == "", reason="ASTRA_DB_ID is not set") | ||
@pytest.mark.integration | ||
def test_retriever_to_json(document_store): | ||
retriever = AstraEmbeddingRetriever(document_store, filters={"foo": "bar"}, top_k=99) | ||
@patch("haystack_integrations.document_stores.astra.document_store.AstraClient") | ||
def test_retriever_to_json(*_): | ||
ds = AstraDocumentStore() | ||
|
||
retriever = AstraEmbeddingRetriever(ds, filters={"foo": "bar"}, top_k=99) | ||
assert retriever.to_dict() == { | ||
"type": "haystack_integrations.components.retrievers.astra.retriever.AstraEmbeddingRetriever", | ||
"init_parameters": { | ||
"filters": {"foo": "bar"}, | ||
"top_k": 99, | ||
"document_store": { | ||
"type": "haystack_integrations.document_stores.astra.document_store.AstraDocumentStore", | ||
"init_parameters": { | ||
"astra_collection": "haystack_integration", | ||
"astra_id": "63195634-ba44-49be-8a3c-12e830eb1c01", | ||
"astra_keyspace": "astra_haystack_test", | ||
"astra_region": "us-east-2", | ||
"duplicates_policy": "OVERWRITE", | ||
"api_endpoint": {"type": "env_var", "env_vars": ["ASTRA_API_ENDPOINT"], "strict": True}, | ||
"token": {"type": "env_var", "env_vars": ["ASTRA_TOKEN"], "strict": True}, | ||
"duplicates_policy": "NONE", | ||
"astra_keyspace": "default_keyspace", | ||
"astra_collection": "documents", | ||
"embedding_dim": 768, | ||
"similarity": "cosine", | ||
}, | ||
"type": "haystack_integrations.document_stores.astra.document_store.AstraDocumentStore", | ||
}, | ||
}, | ||
} | ||
|
||
|
||
@pytest.mark.skipif( | ||
os.environ.get("ASTRA_DB_APPLICATION_TOKEN", "") == "", reason="ASTRA_DB_APPLICATION_TOKEN is not set" | ||
@patch.dict( | ||
"os.environ", {"ASTRA_TOKEN": "fake-token", "ASTRA_API_ENDPOINT": "http://fake-url.apps.astra.datastax.com"} | ||
) | ||
@pytest.mark.skipif(os.environ.get("ASTRA_DB_ID", "") == "", reason="ASTRA_DB_ID is not set") | ||
@pytest.mark.integration | ||
def test_retriever_from_json(): | ||
@patch("haystack_integrations.document_stores.astra.document_store.AstraClient") | ||
def test_retriever_from_json(*_): | ||
|
||
data = { | ||
"type": "haystack_integrations.components.retrievers.astra.retriever.AstraEmbeddingRetriever", | ||
"init_parameters": { | ||
"filters": {"bar": "baz"}, | ||
"top_k": 42, | ||
"document_store": { | ||
"type": "haystack_integrations.document_stores.astra.document_store.AstraDocumentStore", | ||
"init_parameters": { | ||
"astra_collection": "haystack_integration", | ||
"astra_id": "63195634-ba44-49be-8a3c-12e830eb1c01", | ||
"astra_application_token": os.getenv("ASTRA_DB_APPLICATION_TOKEN", ""), | ||
"astra_keyspace": "astra_haystack_test", | ||
"astra_region": "us-east-2", | ||
"duplicates_policy": "overwrite", | ||
"api_endpoint": {"type": "env_var", "env_vars": ["ASTRA_API_ENDPOINT"], "strict": True}, | ||
"token": {"type": "env_var", "env_vars": ["ASTRA_TOKEN"], "strict": True}, | ||
"duplicates_policy": "NONE", | ||
"astra_keyspace": "default_keyspace", | ||
"astra_collection": "documents", | ||
"embedding_dim": 768, | ||
"similarity": "cosine", | ||
}, | ||
"type": "haystack_integrations.document_stores.astra.document_store.AstraDocumentStore", | ||
}, | ||
}, | ||
} | ||
|