refactor: remove pgvector runtime
This commit is contained in:
@@ -2,11 +2,11 @@ import pytest
|
||||
|
||||
from tht.adapters.dwh import PostgresDwhAdapter, ThothRestDwhAdapter
|
||||
from tht.adapters.factory import build_dwh, build_vector_store
|
||||
from tht.adapters.vector import PgVectorStore, QdrantVectorStore, ThothHttpVectorStore
|
||||
from tht.adapters.vector import QdrantVectorStore
|
||||
from tht.config import Config, ConfigError
|
||||
|
||||
|
||||
def _config(*, dwh_type="thoth_rest", vector_type="thoth_vector_http", reader=True, writer=True):
|
||||
def _config(*, dwh_type="thoth_rest", include_vectors=True):
|
||||
dwh = (
|
||||
{
|
||||
"type": "thoth_rest",
|
||||
@@ -27,48 +27,12 @@ def _config(*, dwh_type="thoth_rest", vector_type="thoth_vector_http", reader=Tr
|
||||
)
|
||||
vectors = (
|
||||
{
|
||||
"type": "thoth_vector_http",
|
||||
**(
|
||||
{"reader": {"base_url": "https://vectors.test/", "api_key": "reader"}}
|
||||
if reader
|
||||
else {}
|
||||
),
|
||||
**(
|
||||
{"writer": {"base_url": "https://vectors.test/", "api_key": "writer"}}
|
||||
if writer
|
||||
else {}
|
||||
),
|
||||
}
|
||||
if vector_type == "thoth_vector_http"
|
||||
else {
|
||||
"type": "pgvector_direct",
|
||||
**(
|
||||
{
|
||||
"reader": {
|
||||
"host": "vector-db",
|
||||
"database": "postgres",
|
||||
"schema": "vectors",
|
||||
"user": "reader",
|
||||
"password": "secret",
|
||||
}
|
||||
}
|
||||
if reader
|
||||
else {}
|
||||
),
|
||||
**(
|
||||
{
|
||||
"writer": {
|
||||
"host": "vector-db",
|
||||
"database": "postgres",
|
||||
"schema": "vectors",
|
||||
"user": "writer",
|
||||
"password": "secret",
|
||||
}
|
||||
}
|
||||
if writer
|
||||
else {}
|
||||
),
|
||||
"type": "qdrant",
|
||||
"base_url": "http://qdrant:6333",
|
||||
"collection": "psd-clinical",
|
||||
}
|
||||
if include_vectors
|
||||
else None
|
||||
)
|
||||
legacy_database = (
|
||||
dwh["connection"]
|
||||
@@ -80,7 +44,19 @@ def _config(*, dwh_type="thoth_rest", vector_type="thoth_vector_http", reader=Tr
|
||||
"transport": "rest",
|
||||
}
|
||||
)
|
||||
return Config.model_validate({"dwh": dwh, "vectors": vectors, "database": legacy_database})
|
||||
payload = {"dwh": dwh, "database": legacy_database}
|
||||
if vectors is not None:
|
||||
payload["vectors"] = vectors
|
||||
payload["embeddings"] = {
|
||||
"provider": "ollama_internal",
|
||||
"base_url": "http://embedding:11434",
|
||||
"model": "qwen3-embedding:0.6b",
|
||||
"dim": 1024,
|
||||
}
|
||||
config = Config.model_validate(payload)
|
||||
config._workspace_id = "psd-clinical"
|
||||
config._workspace_revision = "a" * 40
|
||||
return config
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -91,76 +67,8 @@ def test_factory_selects_dwh_adapter(dwh_type, adapter_type):
|
||||
assert isinstance(build_dwh(_config(dwh_type=dwh_type)), adapter_type)
|
||||
|
||||
|
||||
def test_factory_selects_http_vector_and_requires_writer():
|
||||
config = _config(writer=False)
|
||||
|
||||
assert isinstance(build_vector_store(config), ThothHttpVectorStore)
|
||||
with pytest.raises(ConfigError, match="writer"):
|
||||
build_vector_store(config, require_write=True)
|
||||
|
||||
|
||||
def test_factory_builds_writer_only_http_vector_when_write_is_required():
|
||||
config = _config(reader=False, writer=True)
|
||||
|
||||
store = build_vector_store(config, require_write=True)
|
||||
assert isinstance(store, ThothHttpVectorStore)
|
||||
assert store.capabilities.search is False
|
||||
assert store.capabilities.upsert is True
|
||||
|
||||
|
||||
def test_factory_selects_direct_vector_store_and_requires_writer():
|
||||
config = _config(vector_type="pgvector_direct", writer=False)
|
||||
|
||||
assert isinstance(build_vector_store(config), PgVectorStore)
|
||||
with pytest.raises(ConfigError, match="writer"):
|
||||
build_vector_store(config, require_write=True)
|
||||
|
||||
|
||||
def test_factory_builds_writer_only_direct_vector_when_write_is_required():
|
||||
store = build_vector_store(
|
||||
_config(vector_type="pgvector_direct", reader=False), require_write=True
|
||||
)
|
||||
assert isinstance(store, PgVectorStore)
|
||||
assert store.capabilities.search is False
|
||||
assert store.capabilities.upsert is True
|
||||
|
||||
|
||||
def test_factory_selects_qdrant_for_schema_v3_runtime():
|
||||
config = Config.model_validate(
|
||||
{
|
||||
"dwh": {
|
||||
"type": "postgres_direct",
|
||||
"connection": {
|
||||
"host": "db",
|
||||
"database": "analytics",
|
||||
"schema": "mart",
|
||||
"user": "reader",
|
||||
"password": "secret",
|
||||
},
|
||||
},
|
||||
"database": {
|
||||
"host": "db",
|
||||
"database": "analytics",
|
||||
"schema": "mart",
|
||||
"user": "reader",
|
||||
"password": "secret",
|
||||
"transport": "direct",
|
||||
},
|
||||
"vectors": {
|
||||
"type": "qdrant",
|
||||
"base_url": "http://qdrant:6333",
|
||||
"collection": "psd-clinical",
|
||||
},
|
||||
"embeddings": {
|
||||
"provider": "ollama_internal",
|
||||
"base_url": "http://embedding:11434",
|
||||
"model": "qwen3-embedding:0.6b",
|
||||
"dim": 1024,
|
||||
},
|
||||
}
|
||||
)
|
||||
config._workspace_id = "psd-clinical"
|
||||
config._workspace_revision = "a" * 40
|
||||
config = _config(dwh_type="postgres_direct")
|
||||
|
||||
store = build_vector_store(config, require_write=True)
|
||||
|
||||
@@ -169,18 +77,9 @@ def test_factory_selects_qdrant_for_schema_v3_runtime():
|
||||
assert store.capabilities.upsert is True
|
||||
|
||||
|
||||
def test_factory_reuses_legacy_direct_connection_for_server_writes_only():
|
||||
server = _config(vector_type="pgvector_direct", writer=False)
|
||||
server.vectors.connection = server.vectors.reader
|
||||
server.vectors.reader = None
|
||||
|
||||
store = build_vector_store(server, require_write=True)
|
||||
assert store.capabilities.search is True
|
||||
assert store.capabilities.upsert is True
|
||||
|
||||
server.profile = "workstation"
|
||||
with pytest.raises(ConfigError, match="writer"):
|
||||
build_vector_store(server, require_write=True)
|
||||
def test_factory_requires_qdrant_vector_resource():
|
||||
with pytest.raises(ConfigError, match="vectors"):
|
||||
build_vector_store(_config(include_vectors=False))
|
||||
|
||||
|
||||
def test_factory_propagates_non_default_statement_timeout():
|
||||
|
||||
Reference in New Issue
Block a user