Spaces:
Running
Running
Fix formatting in test_vector_store.py
Browse files- tests/test_vector_store.py +13 -10
tests/test_vector_store.py
CHANGED
|
@@ -1,10 +1,14 @@
|
|
| 1 |
import os
|
| 2 |
from argparse import Namespace
|
|
|
|
| 3 |
|
| 4 |
import pytest
|
| 5 |
-
from unittest.mock import patch, MagicMock
|
| 6 |
|
| 7 |
-
from sage.vector_store import
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
mock_vectors = [({"id": "1", "text": "example"}, [0.1, 0.2, 0.3])]
|
| 10 |
mock_namespace = "test_namespace"
|
|
@@ -68,7 +72,6 @@ class TestVectorStore:
|
|
| 68 |
# No specific assertion as upsert_batch is a no-op
|
| 69 |
marqo_store.upsert_batch(mock_vectors, mock_namespace)
|
| 70 |
|
| 71 |
-
|
| 72 |
def build_args(self, provider, alpha=1.0):
|
| 73 |
if provider == "pinecone":
|
| 74 |
return Namespace(
|
|
@@ -76,19 +79,19 @@ class TestVectorStore:
|
|
| 76 |
pinecone_index_name="test_index",
|
| 77 |
embedding_size=128,
|
| 78 |
retrieval_alpha=alpha,
|
| 79 |
-
index_namespace="test_namespace"
|
| 80 |
)
|
| 81 |
elif provider == "marqo":
|
| 82 |
return Namespace(
|
| 83 |
-
vector_store_provider="marqo",
|
| 84 |
-
marqo_url="http://localhost:8882",
|
| 85 |
-
index_namespace="test_index"
|
| 86 |
)
|
| 87 |
|
| 88 |
def build_bm25_cache_path(self):
|
| 89 |
return os.path.join(".bm25_cache", "test_namespace", "bm25_encoder.json")
|
| 90 |
|
| 91 |
-
def test_builds_pinecone_vector_store_with_default_bm25_encoder(
|
|
|
|
|
|
|
| 92 |
args = self.build_args("pinecone", alpha=0.5)
|
| 93 |
store = build_vector_store_from_args(args, data_manager=mock_data_manager)
|
| 94 |
assert isinstance(store, PineconeVectorStore)
|
|
@@ -120,5 +123,5 @@ class TestVectorStore:
|
|
| 120 |
with pytest.raises(ValueError, match="Unrecognized vector store type unknown"):
|
| 121 |
build_vector_store_from_args(args)
|
| 122 |
|
| 123 |
-
if __name__ ==
|
| 124 |
-
pytest.main()
|
|
|
|
| 1 |
import os
|
| 2 |
from argparse import Namespace
|
| 3 |
+
from unittest.mock import MagicMock, patch
|
| 4 |
|
| 5 |
import pytest
|
|
|
|
| 6 |
|
| 7 |
+
from sage.vector_store import (
|
| 8 |
+
MarqoVectorStore,
|
| 9 |
+
PineconeVectorStore,
|
| 10 |
+
build_vector_store_from_args,
|
| 11 |
+
)
|
| 12 |
|
| 13 |
mock_vectors = [({"id": "1", "text": "example"}, [0.1, 0.2, 0.3])]
|
| 14 |
mock_namespace = "test_namespace"
|
|
|
|
| 72 |
# No specific assertion as upsert_batch is a no-op
|
| 73 |
marqo_store.upsert_batch(mock_vectors, mock_namespace)
|
| 74 |
|
|
|
|
| 75 |
def build_args(self, provider, alpha=1.0):
|
| 76 |
if provider == "pinecone":
|
| 77 |
return Namespace(
|
|
|
|
| 79 |
pinecone_index_name="test_index",
|
| 80 |
embedding_size=128,
|
| 81 |
retrieval_alpha=alpha,
|
| 82 |
+
index_namespace="test_namespace",
|
| 83 |
)
|
| 84 |
elif provider == "marqo":
|
| 85 |
return Namespace(
|
| 86 |
+
vector_store_provider="marqo", marqo_url="http://localhost:8882", index_namespace="test_index"
|
|
|
|
|
|
|
| 87 |
)
|
| 88 |
|
| 89 |
def build_bm25_cache_path(self):
|
| 90 |
return os.path.join(".bm25_cache", "test_namespace", "bm25_encoder.json")
|
| 91 |
|
| 92 |
+
def test_builds_pinecone_vector_store_with_default_bm25_encoder(
|
| 93 |
+
self, pinecone_store, mock_bm25_encoder, mock_data_manager, mock_nltk
|
| 94 |
+
):
|
| 95 |
args = self.build_args("pinecone", alpha=0.5)
|
| 96 |
store = build_vector_store_from_args(args, data_manager=mock_data_manager)
|
| 97 |
assert isinstance(store, PineconeVectorStore)
|
|
|
|
| 123 |
with pytest.raises(ValueError, match="Unrecognized vector store type unknown"):
|
| 124 |
build_vector_store_from_args(args)
|
| 125 |
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
pytest.main()
|