Skip to content

Commit 56e9804

Browse files
authored
test: Restore knowldege-store integration tests (#529)
* test: Restore knowldege-store integration tests These currently just demonstrate that the knowledge store can be created. That is enough to verify the schema and queries are correct. I'll add more tests over time. These are smaller than the full langchain tests to run, so are easier to use for iterating on the details.
1 parent 296d4eb commit 56e9804

File tree

6 files changed

+83
-2
lines changed

6 files changed

+83
-2
lines changed

.github/workflows/ci-unit-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ jobs:
147147
if [[ "true" == "${{ needs.preconditions.outputs.libs_colbert }}" ]]; then
148148
run_itests libs/colbert
149149
fi
150+
if [[ "true" == "${{ needs.preconditions.outputs.libs_knowledge_store }}" ]]; then
151+
run_itests libs/knowledge-store
152+
fi
150153
if [[ "true" == "${{ needs.preconditions.outputs.libs_langchain }}" ]]; then
151154
run_itests libs/langchain
152155
fi

libs/knowledge-store/pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ documentation = "https://docs.datastax.com/en/ragstack"
1010
packages = [{ include = "ragstack_knowledge_store" }]
1111

1212
[tool.poetry.dependencies]
13-
python = ">=3.8.1,<4.0"
13+
python = ">=3.9,<3.13"
1414
cassio = "^0.1.7"
1515

1616
[tool.poetry.group.dev.dependencies]
@@ -29,6 +29,10 @@ numpy = [
2929
{version = ">1.26.0,<2", python = ">=3.12"}
3030
]
3131

32+
[tool.poetry.group.test.dependencies]
33+
ragstack-ai-langchain = { path = "../langchain", develop = true }
34+
ragstack-ai-tests-utils = { path = "../tests-utils", develop = true }
35+
3236
[build-system]
3337
requires = ["poetry-core"]
3438
build-backend = "poetry.core.masonry.api"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import secrets
2+
from typing import Iterator
3+
4+
import pytest
5+
from dotenv import load_dotenv
6+
from langchain_openai import OpenAIEmbeddings
7+
from ragstack_knowledge_store.graph_store import GraphStore
8+
from ragstack_tests_utils import LocalCassandraTestStore
9+
10+
load_dotenv()
11+
12+
KEYSPACE = "default_keyspace"
13+
14+
15+
@pytest.fixture(scope="session")
16+
def cassandra() -> Iterator[LocalCassandraTestStore]:
17+
store = LocalCassandraTestStore()
18+
yield store
19+
20+
if store.docker_container:
21+
store.docker_container.stop()
22+
23+
24+
@pytest.fixture
25+
def graph_store_factory(cassandra: LocalCassandraTestStore):
26+
session = cassandra.create_cassandra_session()
27+
session.set_keyspace(KEYSPACE)
28+
29+
embedding = OpenAIEmbeddings()
30+
31+
def _make_graph_store():
32+
name = secrets.token_hex(8)
33+
34+
node_table = f"nodes_{name}"
35+
targets_table = f"targets_{name}"
36+
return GraphStore(
37+
embedding,
38+
session=session,
39+
keyspace=KEYSPACE,
40+
node_table=node_table,
41+
targets_table=targets_table,
42+
)
43+
44+
yield _make_graph_store
45+
46+
session.shutdown()
47+
48+
49+
def test_graph_store_creation(graph_store_factory):
50+
"""Test that a graph store can be created.
51+
52+
This verifies the schema can be applied and the queries prepared.
53+
"""
54+
graph_store_factory()

libs/knowledge-store/tox.ini

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,15 @@ pass_env =
1111
commands =
1212
poetry install
1313
poetry build
14-
poetry run pytest --disable-warnings {toxinidir}/tests
14+
poetry run pytest --disable-warnings {toxinidir}/tests/unit_tests
15+
16+
[testenv:integration-tests]
17+
description = run integration tests
18+
deps =
19+
poetry
20+
pass_env =
21+
OPENAI_API_KEY
22+
commands =
23+
poetry install
24+
poetry build
25+
poetry run pytest --disable-warnings {toxinidir}/tests/integration_tests

libs/langchain/tests/integration_tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def get_astradb_test_store() -> AstraDBTestStore:
2626
@pytest.fixture(scope="session", autouse=True)
2727
def before_after_tests():
2828
yield
29+
2930
if (
3031
status["local_cassandra_test_store"]
3132
and status["local_cassandra_test_store"].docker_container

libs/tests-utils/ragstack_tests_utils/cassandra_container.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ def __init__(
1212
super().__init__(image=image, **kwargs)
1313
self.port = port
1414

15+
self.with_env(
16+
"JVM_OPTS",
17+
"-Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0",
18+
)
19+
self.with_env("HEAP_NEWSIZE", "128M")
20+
self.with_env("MAX_HEAP_SIZE", "1024M")
21+
self.with_env("CASSANDRA_ENDPOINT_SNITCH", "GossipingPropertyFileSnitch")
22+
self.with_env("CASSANDRA_DC", "datacenter1")
1523
self.with_exposed_ports(self.port)
1624

1725
def _configure(self):

0 commit comments

Comments
 (0)