Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
001e539
feat: adds triplet datapoint
hajdul88 Nov 25, 2025
1e3c304
feat: adds get triplet batches adapter level method
hajdul88 Nov 25, 2025
e6b6e82
feat: adds initial get_triplet_datapoints
hajdul88 Nov 25, 2025
0b393a7
feat: adds first version of get_triplet_datapoints task
hajdul88 Nov 25, 2025
a512e1d
ruff format
hajdul88 Nov 25, 2025
01921d6
Update get_triplet_datapoints.py
hajdul88 Nov 25, 2025
df88fac
Update get_triplet_datapoints.py
hajdul88 Nov 25, 2025
de4aa73
Merge branch 'dev' into feature/cog-3326-2triplet-embedding-via-memify
hajdul88 Nov 26, 2025
855eb1f
feat: adds logging to get_triplet_datapoints
hajdul88 Nov 26, 2025
acc370c
ruff
hajdul88 Nov 26, 2025
64f81a5
removes indexing from get_triplet datapoints
hajdul88 Nov 26, 2025
207fe58
feat: introduces memify wrapping
hajdul88 Nov 26, 2025
717cc69
fix: fixes batching and pipeline yielding logic
hajdul88 Nov 26, 2025
2472174
ruff format
hajdul88 Nov 26, 2025
72f4533
fix: fixing user issue with new memify pipeline
hajdul88 Nov 26, 2025
b7cd326
uc and poetry fix for lancedb
hajdul88 Nov 27, 2025
09ad8ea
Revert "uc and poetry fix for lancedb"
hajdul88 Nov 27, 2025
565ed40
fix: fixes logging
hajdul88 Nov 27, 2025
36162f5
fix: fixes embedded text by adding separators
hajdul88 Nov 27, 2025
8cc7530
feat: adds triplet completion to search types
hajdul88 Nov 27, 2025
16e9e76
feat: adds triplet retriever and connects it to search type tools
hajdul88 Nov 27, 2025
2a447e0
ruff fix
hajdul88 Nov 27, 2025
232c761
fix: lancedb fix in order to be able to run CI (TO REVERT)
hajdul88 Nov 27, 2025
77dd332
fix: fixes no triplet embedding error (thats why you should never cop…
hajdul88 Nov 27, 2025
1ecbcff
feat: adds memify triplet embedding example
hajdul88 Nov 27, 2025
5e8b53f
feat: adds get_triplet_datapoints unit test
hajdul88 Nov 27, 2025
dcf43be
feat: adds integration test for get_triplet_datapoints
hajdul88 Nov 27, 2025
4d062df
ruff format
hajdul88 Nov 27, 2025
c00814b
Update test_get_triplet_datapoints.py
hajdul88 Nov 27, 2025
df7018e
Update test_get_triplet_datapoints.py
hajdul88 Nov 27, 2025
2335f78
feat: adds unit and integration test to triplet retriever
hajdul88 Nov 27, 2025
ac57ff2
feat: adds triplet embedding example
hajdul88 Nov 28, 2025
36cdd2e
ruff format
hajdul88 Nov 28, 2025
05db29b
feat: extends session history test with new triplet completion retriever
hajdul88 Nov 28, 2025
7d7133d
ruff
hajdul88 Nov 28, 2025
f32578f
feat: extends multidb search test with triplet embedding test
hajdul88 Nov 28, 2025
6b7c483
chore: deletes comments
hajdul88 Nov 28, 2025
2380ebb
chores: deletes some comments
hajdul88 Dec 1, 2025
2a0972a
chore: deletes some comments from conv history
hajdul88 Dec 1, 2025
29575f9
chore: deletes comments from search db test
hajdul88 Dec 1, 2025
ddebafe
Merge branch 'dev' into feature/cog-3326-2triplet-embedding-via-memify
hajdul88 Dec 1, 2025
c988fab
chore: fixes coderabbit findings (unused imports)
hajdul88 Dec 2, 2025
fb11dd0
Revert "fix: lancedb fix in order to be able to run CI (TO REVERT)"
hajdul88 Dec 2, 2025
3cb8305
feat: separates session vs non session logic into private methods
hajdul88 Dec 2, 2025
608bdc3
chore: removes if (not needed)
hajdul88 Dec 2, 2025
463fc30
chore: moves continue a bit earlier in the loop
hajdul88 Dec 2, 2025
41488e9
ruff ruff
hajdul88 Dec 2, 2025
d96d536
chore: moving if earlier
hajdul88 Dec 2, 2025
3293ab4
chore: remove unused import
hajdul88 Dec 2, 2025
b287701
Revert "chore: remove unused import"
hajdul88 Dec 2, 2025
7ab00b5
Merge branch 'dev' into feature/cog-3326-2triplet-embedding-via-memify
hajdul88 Dec 2, 2025
5424ebc
chore: breaks the get_triplet_datapoints logic into chain of private …
hajdul88 Dec 2, 2025
6363bda
ruff format
hajdul88 Dec 2, 2025
61f7a2e
Merge branch 'feature/cog-3326-2triplet-embedding-via-memify' of gith…
hajdul88 Dec 2, 2025
804289b
feat: adds vector+graph consistency check for triplet embedding
hajdul88 Dec 2, 2025
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
Prev Previous commit
Next Next commit
feat: adds unit and integration test to triplet retriever
  • Loading branch information
hajdul88 committed Nov 27, 2025
commit 2335f7886acbf7478a05b5bbbac4df4ad4c77e36
84 changes: 84 additions & 0 deletions cognee/tests/integration/retrieval/test_triplet_retriever.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import os
import pytest
import pathlib
import pytest_asyncio
import cognee

from cognee.low_level import setup
from cognee.tasks.storage import add_data_points
from cognee.modules.retrieval.exceptions.exceptions import NoDataError
from cognee.modules.retrieval.triplet_retriever import TripletRetriever
from cognee.modules.engine.models import Triplet


@pytest_asyncio.fixture
async def setup_test_environment_with_triplets():
"""Set up a clean test environment with triplets."""
base_dir = pathlib.Path(__file__).parent.parent.parent.parent
system_directory_path = str(base_dir / ".cognee_system/test_triplet_retriever_context_simple")
data_directory_path = str(base_dir / ".data_storage/test_triplet_retriever_context_simple")

cognee.config.system_root_directory(system_directory_path)
cognee.config.data_root_directory(data_directory_path)

await cognee.prune.prune_data()
await cognee.prune.prune_system(metadata=True)
await setup()

triplet1 = Triplet(
from_node_id="node1",
to_node_id="node2",
text="Alice knows Bob",
)
triplet2 = Triplet(
from_node_id="node2",
to_node_id="node3",
text="Bob works at Tech Corp",
)

triplets = [triplet1, triplet2]
await add_data_points(triplets)

yield

try:
await cognee.prune.prune_data()
await cognee.prune.prune_system(metadata=True)
except Exception:
pass


@pytest_asyncio.fixture
async def setup_test_environment_empty():
"""Set up a clean test environment without triplets."""
base_dir = pathlib.Path(__file__).parent.parent.parent.parent
system_directory_path = str(
base_dir / ".cognee_system/test_triplet_retriever_context_empty_collection"
)
data_directory_path = str(
base_dir / ".data_storage/test_triplet_retriever_context_empty_collection"
)

cognee.config.system_root_directory(system_directory_path)
cognee.config.data_root_directory(data_directory_path)

await cognee.prune.prune_data()
await cognee.prune.prune_system(metadata=True)

yield

try:
await cognee.prune.prune_data()
await cognee.prune.prune_system(metadata=True)
except Exception:
pass


@pytest.mark.asyncio
async def test_triplet_retriever_context_simple(setup_test_environment_with_triplets):
"""Integration test: verify TripletRetriever can retrieve triplet context."""
retriever = TripletRetriever(top_k=5)

context = await retriever.get_context("Alice")

assert "Alice knows Bob" in context, "Failed to get Alice triplet"
83 changes: 83 additions & 0 deletions cognee/tests/unit/modules/retrieval/triplet_retriever_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import pytest
from unittest.mock import AsyncMock, patch, MagicMock

from cognee.modules.retrieval.triplet_retriever import TripletRetriever
from cognee.modules.retrieval.exceptions.exceptions import NoDataError
from cognee.infrastructure.databases.vector.exceptions import CollectionNotFoundError


@pytest.fixture
def mock_vector_engine():
"""Create a mock vector engine."""
engine = AsyncMock()
engine.has_collection = AsyncMock(return_value=True)
engine.search = AsyncMock()
return engine


@pytest.mark.asyncio
async def test_get_context_success(mock_vector_engine):
"""Test successful retrieval of triplet context."""
mock_result1 = MagicMock()
mock_result1.payload = {"text": "Alice knows Bob"}
mock_result2 = MagicMock()
mock_result2.payload = {"text": "Bob works at Tech Corp"}

mock_vector_engine.search.return_value = [mock_result1, mock_result2]

retriever = TripletRetriever(top_k=5)

with patch(
"cognee.modules.retrieval.triplet_retriever.get_vector_engine",
return_value=mock_vector_engine,
):
context = await retriever.get_context("test query")

assert context == "Alice knows Bob\nBob works at Tech Corp"
mock_vector_engine.search.assert_awaited_once_with("Triplet_text", "test query", limit=5)


@pytest.mark.asyncio
async def test_get_context_no_collection(mock_vector_engine):
"""Test that NoDataError is raised when Triplet_text collection doesn't exist."""
mock_vector_engine.has_collection.return_value = False

retriever = TripletRetriever()

with patch(
"cognee.modules.retrieval.triplet_retriever.get_vector_engine",
return_value=mock_vector_engine,
):
with pytest.raises(NoDataError, match="create_triplet_embeddings"):
await retriever.get_context("test query")


@pytest.mark.asyncio
async def test_get_context_empty_results(mock_vector_engine):
"""Test that empty string is returned when no triplets are found."""
mock_vector_engine.search.return_value = []

retriever = TripletRetriever()

with patch(
"cognee.modules.retrieval.triplet_retriever.get_vector_engine",
return_value=mock_vector_engine,
):
context = await retriever.get_context("test query")

assert context == ""


@pytest.mark.asyncio
async def test_get_context_collection_not_found_error(mock_vector_engine):
"""Test that CollectionNotFoundError is converted to NoDataError."""
mock_vector_engine.has_collection.side_effect = CollectionNotFoundError("Collection not found")

retriever = TripletRetriever()

with patch(
"cognee.modules.retrieval.triplet_retriever.get_vector_engine",
return_value=mock_vector_engine,
):
with pytest.raises(NoDataError, match="No data found"):
await retriever.get_context("test query")
Loading