Skip to content

Commit 7fee82d

Browse files
Gaudy BlancoGaudy Blanco
authored andcommitted
clean test for vector store
1 parent 15f2144 commit 7fee82d

File tree

5 files changed

+60
-15
lines changed

5 files changed

+60
-15
lines changed

tests/integration/vector_stores/test_azure_ai_search.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import pytest
1010

11+
from graphrag.config.models.vector_store_schema_config import VectorStoreSchemaConfig
1112
from graphrag.vector_stores.azure_ai_search import AzureAISearchVectorStore
1213
from graphrag.vector_stores.base import VectorStoreDocument
1314

@@ -39,7 +40,10 @@ def mock_index_client(self):
3940
@pytest.fixture
4041
def vector_store(self, mock_search_client, mock_index_client):
4142
"""Create an Azure AI Search vector store instance."""
42-
vector_store = AzureAISearchVectorStore(collection_name="test_vectors")
43+
vector_store = AzureAISearchVectorStore(
44+
collection_name="test_vectors",
45+
vector_store_schema_config=VectorStoreSchemaConfig(),
46+
)
4347

4448
# Create the necessary mocks first
4549
vector_store.db_connection = mock_search_client

tests/integration/vector_stores/test_cosmosdb.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import numpy as np
99
import pytest
1010

11+
from graphrag.config.models.vector_store_schema_config import VectorStoreSchemaConfig
1112
from graphrag.vector_stores.base import VectorStoreDocument
1213
from graphrag.vector_stores.cosmosdb import CosmosDBVectorStore
1314

@@ -25,6 +26,7 @@ def test_vector_store_operations():
2526
"""Test basic vector store operations with CosmosDB."""
2627
vector_store = CosmosDBVectorStore(
2728
collection_name="testvector",
29+
vector_store_schema_config=VectorStoreSchemaConfig(),
2830
)
2931

3032
try:
@@ -79,6 +81,7 @@ def test_clear():
7981
"""Test clearing the vector store."""
8082
vector_store = CosmosDBVectorStore(
8183
collection_name="testclear",
84+
vector_store_schema_config=VectorStoreSchemaConfig(),
8285
)
8386
try:
8487
vector_store.connect(

tests/integration/vector_stores/test_factory.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pytest
99

1010
from graphrag.config.enums import VectorStoreType
11+
from graphrag.config.models.vector_store_schema_config import VectorStoreSchemaConfig
1112
from graphrag.vector_stores.azure_ai_search import AzureAISearchVectorStore
1213
from graphrag.vector_stores.base import BaseVectorStore
1314
from graphrag.vector_stores.cosmosdb import CosmosDBVectorStore
@@ -21,10 +22,12 @@ def test_create_lancedb_vector_store():
2122
"db_uri": "/tmp/lancedb",
2223
}
2324
vector_store = VectorStoreFactory.create_vector_store(
24-
VectorStoreType.LanceDB.value, kwargs
25+
vector_store_type=VectorStoreType.LanceDB.value,
26+
vector_store_schema_config=VectorStoreSchemaConfig(),
27+
kwargs=kwargs,
2528
)
2629
assert isinstance(vector_store, LanceDBVectorStore)
27-
assert vector_store.collection_name == "test_collection"
30+
assert vector_store.index_name == "test_collection"
2831

2932

3033
@pytest.mark.skip(reason="Azure AI Search requires credentials and setup")
@@ -35,7 +38,9 @@ def test_create_azure_ai_search_vector_store():
3538
"api_key": "test_key",
3639
}
3740
vector_store = VectorStoreFactory.create_vector_store(
38-
VectorStoreType.AzureAISearch.value, kwargs
41+
vector_store_type=VectorStoreType.AzureAISearch.value,
42+
vector_store_schema_config=VectorStoreSchemaConfig(),
43+
kwargs=kwargs,
3944
)
4045
assert isinstance(vector_store, AzureAISearchVectorStore)
4146

@@ -47,9 +52,13 @@ def test_create_cosmosdb_vector_store():
4752
"connection_string": "AccountEndpoint=https://test.documents.azure.com:443/;AccountKey=test_key==",
4853
"database_name": "test_db",
4954
}
55+
5056
vector_store = VectorStoreFactory.create_vector_store(
51-
VectorStoreType.CosmosDB.value, kwargs
57+
vector_store_type=VectorStoreType.CosmosDB.value,
58+
vector_store_schema_config=VectorStoreSchemaConfig(),
59+
kwargs=kwargs,
5260
)
61+
5362
assert isinstance(vector_store, CosmosDBVectorStore)
5463

5564

@@ -67,7 +76,12 @@ def test_register_and_create_custom_vector_store():
6776
VectorStoreFactory.register(
6877
"custom", lambda **kwargs: custom_vector_store_class(**kwargs)
6978
)
70-
vector_store = VectorStoreFactory.create_vector_store("custom", {})
79+
80+
vector_store = VectorStoreFactory.create_vector_store(
81+
vector_store_type="custom",
82+
vector_store_schema_config=VectorStoreSchemaConfig(),
83+
kwargs={},
84+
)
7185

7286
assert custom_vector_store_class.called
7387
assert vector_store is instance
@@ -89,7 +103,11 @@ def test_get_vector_store_types():
89103

90104
def test_create_unknown_vector_store():
91105
with pytest.raises(ValueError, match="Unknown vector store type: unknown"):
92-
VectorStoreFactory.create_vector_store("unknown", {})
106+
VectorStoreFactory.create_vector_store(
107+
vector_store_type="unknown",
108+
vector_store_schema_config=VectorStoreSchemaConfig(),
109+
kwargs={},
110+
)
93111

94112

95113
def test_is_supported_type():
@@ -139,6 +157,9 @@ def search_by_id(self, id):
139157

140158
# Test creating an instance
141159
vector_store = VectorStoreFactory.create_vector_store(
142-
"custom_class", {"collection_name": "test"}
160+
vector_store_type="custom_class",
161+
vector_store_schema_config=VectorStoreSchemaConfig(),
162+
kwargs={"collection_name": "test"},
143163
)
164+
144165
assert isinstance(vector_store, CustomVectorStore)

tests/integration/vector_stores/test_lancedb.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import numpy as np
1010

11+
from graphrag.config.models.vector_store_schema_config import VectorStoreSchemaConfig
1112
from graphrag.vector_stores.base import VectorStoreDocument
1213
from graphrag.vector_stores.lancedb import LanceDBVectorStore
1314

@@ -17,7 +18,11 @@ def test_vector_store_operations():
1718
# Create a temporary directory for the test database
1819
temp_dir = tempfile.mkdtemp()
1920
try:
20-
vector_store = LanceDBVectorStore(collection_name="test_collection")
21+
vector_store = LanceDBVectorStore(
22+
vector_store_schema_config=VectorStoreSchemaConfig(
23+
index_name="test_collection"
24+
)
25+
)
2126
vector_store.connect(db_uri=temp_dir)
2227

2328
docs = [
@@ -42,7 +47,7 @@ def test_vector_store_operations():
4247
]
4348
vector_store.load_documents(docs[:2])
4449

45-
assert vector_store.collection_name in vector_store.db_connection.table_names()
50+
assert vector_store.index_name in vector_store.db_connection.table_names()
4651

4752
doc = vector_store.search_by_id("1")
4853
assert doc.id == "1"
@@ -91,7 +96,11 @@ def test_empty_collection():
9196
# Create a temporary directory for the test database
9297
temp_dir = tempfile.mkdtemp()
9398
try:
94-
vector_store = LanceDBVectorStore(collection_name="empty_collection")
99+
vector_store = LanceDBVectorStore(
100+
vector_store_schema_config=VectorStoreSchemaConfig(
101+
index_name="empty_collection"
102+
)
103+
)
95104
vector_store.connect(db_uri=temp_dir)
96105

97106
# Load the vector store with a document, then delete it
@@ -102,12 +111,12 @@ def test_empty_collection():
102111
attributes={"title": "Tmp"},
103112
)
104113
vector_store.load_documents([sample_doc])
105-
vector_store.db_connection.open_table(vector_store.collection_name).delete(
114+
vector_store.db_connection.open_table(vector_store.index_name).delete(
106115
"id = 'tmp'"
107116
)
108117

109118
# Should still have the collection
110-
assert vector_store.collection_name in vector_store.db_connection.table_names()
119+
assert vector_store.index_name in vector_store.db_connection.table_names()
111120

112121
# Add a document after creating an empty collection
113122
doc = VectorStoreDocument(
@@ -131,7 +140,12 @@ def test_filter_search():
131140
# Create a temporary directory for the test database
132141
temp_dir = tempfile.mkdtemp()
133142
try:
134-
vector_store = LanceDBVectorStore(collection_name="filter_collection")
143+
vector_store = LanceDBVectorStore(
144+
vector_store_schema_config=VectorStoreSchemaConfig(
145+
index_name="filter_collection"
146+
)
147+
)
148+
135149
vector_store.connect(db_uri=temp_dir)
136150

137151
# Create test documents with different categories

tests/unit/query/context_builder/test_entity_extraction.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from typing import Any
55

6+
from graphrag.config.models.vector_store_schema_config import VectorStoreSchemaConfig
67
from graphrag.data_model.entity import Entity
78
from graphrag.data_model.types import TextEmbedder
89
from graphrag.language_model.manager import ModelManager
@@ -19,7 +20,9 @@
1920

2021
class MockBaseVectorStore(BaseVectorStore):
2122
def __init__(self, documents: list[VectorStoreDocument]) -> None:
22-
super().__init__("mock")
23+
super().__init__(
24+
vector_store_schema_config=VectorStoreSchemaConfig(index_name="mock")
25+
)
2326
self.documents = documents
2427

2528
def connect(self, **kwargs: Any) -> None:

0 commit comments

Comments
 (0)