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: pass namespace in the docstore init #683

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -55,6 +55,7 @@ def __init__(
embedding_dimension: int = 768,
duplicates_policy: DuplicatePolicy = DuplicatePolicy.NONE,
similarity: str = "cosine",
namespace: Optional[str] = None,
):
"""
The connection to Astra DB is established and managed through the JSON API.
Expand Down Expand Up @@ -99,13 +100,16 @@ def __init__(
self.embedding_dimension = embedding_dimension
self.duplicates_policy = duplicates_policy
self.similarity = similarity
if namespace:
self.namespace = namespace
masci marked this conversation as resolved.
Show resolved Hide resolved

self.index = AstraClient(
resolved_api_endpoint,
resolved_token,
self.collection_name,
self.embedding_dimension,
self.similarity,
namespace,
)

@classmethod
Expand Down
12 changes: 12 additions & 0 deletions integrations/astra/tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
import os
from typing import List
from unittest import mock

import pytest
from haystack import Document
Expand All @@ -13,6 +14,17 @@
from haystack_integrations.document_stores.astra import AstraDocumentStore


def test_namespace_init():
with mock.patch("haystack_integrations.document_stores.astra.astra_client.AstraDB") as client:
AstraDocumentStore()
assert "namespace" in client.call_args.kwargs
assert client.call_args.kwargs["namespace"] is None

AstraDocumentStore(namespace="foo")
assert "namespace" in client.call_args.kwargs
assert client.call_args.kwargs["namespace"] == "foo"


@pytest.mark.integration
@pytest.mark.skipif(
os.environ.get("ASTRA_DB_APPLICATION_TOKEN", "") == "", reason="ASTRA_DB_APPLICATION_TOKEN env var not set"
Expand Down