cognee 0.5.0.dev1__py3-none-any.whl → 0.5.1.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cognee/api/v1/add/add.py +2 -1
- cognee/api/v1/datasets/routers/get_datasets_router.py +1 -0
- cognee/api/v1/memify/routers/get_memify_router.py +1 -0
- cognee/infrastructure/databases/relational/config.py +16 -1
- cognee/infrastructure/databases/relational/create_relational_engine.py +13 -3
- cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py +24 -2
- cognee/infrastructure/databases/vector/create_vector_engine.py +9 -2
- cognee/infrastructure/llm/LLMGateway.py +0 -13
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py +17 -12
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/gemini/adapter.py +31 -25
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/generic_llm_api/adapter.py +132 -7
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py +5 -5
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/llm_interface.py +2 -6
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/mistral/adapter.py +58 -13
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/ollama/adapter.py +0 -1
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py +25 -131
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/types.py +10 -0
- cognee/modules/data/models/Data.py +2 -1
- cognee/modules/retrieval/triplet_retriever.py +1 -1
- cognee/modules/retrieval/utils/brute_force_triplet_search.py +0 -18
- cognee/tasks/ingestion/data_item.py +8 -0
- cognee/tasks/ingestion/ingest_data.py +12 -1
- cognee/tasks/ingestion/save_data_item_to_storage.py +5 -0
- cognee/tests/integration/retrieval/test_chunks_retriever.py +252 -0
- cognee/tests/integration/retrieval/test_graph_completion_retriever.py +268 -0
- cognee/tests/integration/retrieval/test_graph_completion_retriever_context_extension.py +226 -0
- cognee/tests/integration/retrieval/test_graph_completion_retriever_cot.py +218 -0
- cognee/tests/integration/retrieval/test_rag_completion_retriever.py +254 -0
- cognee/tests/{unit/modules/retrieval/structured_output_test.py → integration/retrieval/test_structured_output.py} +87 -77
- cognee/tests/integration/retrieval/test_summaries_retriever.py +184 -0
- cognee/tests/integration/retrieval/test_temporal_retriever.py +306 -0
- cognee/tests/integration/retrieval/test_triplet_retriever.py +35 -0
- cognee/tests/test_custom_data_label.py +68 -0
- cognee/tests/test_search_db.py +334 -181
- cognee/tests/unit/eval_framework/benchmark_adapters_test.py +25 -0
- cognee/tests/unit/eval_framework/corpus_builder_test.py +33 -4
- cognee/tests/unit/infrastructure/databases/relational/test_RelationalConfig.py +69 -0
- cognee/tests/unit/modules/retrieval/chunks_retriever_test.py +181 -199
- cognee/tests/unit/modules/retrieval/conversation_history_test.py +338 -0
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +454 -162
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +674 -156
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +625 -200
- cognee/tests/unit/modules/retrieval/rag_completion_retriever_test.py +319 -203
- cognee/tests/unit/modules/retrieval/summaries_retriever_test.py +189 -155
- cognee/tests/unit/modules/retrieval/temporal_retriever_test.py +539 -58
- cognee/tests/unit/modules/retrieval/test_brute_force_triplet_search.py +218 -9
- cognee/tests/unit/modules/retrieval/test_completion.py +343 -0
- cognee/tests/unit/modules/retrieval/test_graph_summary_completion_retriever.py +157 -0
- cognee/tests/unit/modules/retrieval/test_user_qa_feedback.py +312 -0
- cognee/tests/unit/modules/retrieval/triplet_retriever_test.py +246 -0
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dev0.dist-info}/METADATA +1 -1
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dev0.dist-info}/RECORD +56 -42
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dev0.dist-info}/WHEEL +0 -0
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dev0.dist-info}/entry_points.txt +0 -0
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dev0.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dev0.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -82,3 +82,38 @@ async def test_triplet_retriever_context_simple(setup_test_environment_with_trip
|
|
|
82
82
|
context = await retriever.get_context("Alice")
|
|
83
83
|
|
|
84
84
|
assert "Alice knows Bob" in context, "Failed to get Alice triplet"
|
|
85
|
+
assert isinstance(context, str), "Context should be a string"
|
|
86
|
+
assert len(context) > 0, "Context should not be empty"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@pytest.mark.asyncio
|
|
90
|
+
async def test_triplet_retriever_context_multiple_triplets(setup_test_environment_with_triplets):
|
|
91
|
+
"""Integration test: verify TripletRetriever can retrieve multiple triplets."""
|
|
92
|
+
retriever = TripletRetriever(top_k=5)
|
|
93
|
+
|
|
94
|
+
context = await retriever.get_context("Bob")
|
|
95
|
+
|
|
96
|
+
assert "Alice knows Bob" in context or "Bob works at Tech Corp" in context, (
|
|
97
|
+
"Failed to get Bob-related triplets"
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@pytest.mark.asyncio
|
|
102
|
+
async def test_triplet_retriever_top_k_limit(setup_test_environment_with_triplets):
|
|
103
|
+
"""Integration test: verify TripletRetriever respects top_k parameter."""
|
|
104
|
+
retriever = TripletRetriever(top_k=1)
|
|
105
|
+
|
|
106
|
+
context = await retriever.get_context("Alice")
|
|
107
|
+
|
|
108
|
+
assert isinstance(context, str), "Context should be a string"
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
@pytest.mark.asyncio
|
|
112
|
+
async def test_triplet_retriever_context_empty(setup_test_environment_empty):
|
|
113
|
+
"""Integration test: verify TripletRetriever handles empty graph correctly."""
|
|
114
|
+
await setup()
|
|
115
|
+
|
|
116
|
+
retriever = TripletRetriever()
|
|
117
|
+
|
|
118
|
+
with pytest.raises(NoDataError):
|
|
119
|
+
await retriever.get_context("Alice")
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import cognee
|
|
3
|
+
from cognee.shared.logging_utils import setup_logging, ERROR
|
|
4
|
+
from cognee.api.v1.search import SearchType
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
async def main():
|
|
8
|
+
# Create a clean slate for cognee -- reset data and system state
|
|
9
|
+
print("Resetting cognee data...")
|
|
10
|
+
await cognee.prune.prune_data()
|
|
11
|
+
await cognee.prune.prune_system(metadata=True)
|
|
12
|
+
print("Data reset complete.\n")
|
|
13
|
+
|
|
14
|
+
# cognee knowledge graph will be created based on this text
|
|
15
|
+
text = """
|
|
16
|
+
Natural language processing (NLP) is an interdisciplinary
|
|
17
|
+
subfield of computer science and information retrieval.
|
|
18
|
+
"""
|
|
19
|
+
from cognee.tasks.ingestion.data_item import DataItem
|
|
20
|
+
|
|
21
|
+
test_item = DataItem(text, "test_item")
|
|
22
|
+
# Add the text, and make it available for cognify
|
|
23
|
+
await cognee.add(test_item)
|
|
24
|
+
|
|
25
|
+
# Use LLMs and cognee to create knowledge graph
|
|
26
|
+
ret_val = await cognee.cognify()
|
|
27
|
+
|
|
28
|
+
query_text = "Tell me about NLP"
|
|
29
|
+
print(f"Searching cognee for insights with query: '{query_text}'")
|
|
30
|
+
# Query cognee for insights on the added text
|
|
31
|
+
search_results = await cognee.search(
|
|
32
|
+
query_type=SearchType.GRAPH_COMPLETION, query_text=query_text
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
print("Search results:")
|
|
36
|
+
# Display results
|
|
37
|
+
for result_text in search_results:
|
|
38
|
+
print(result_text)
|
|
39
|
+
|
|
40
|
+
from cognee.modules.data.methods.get_dataset_data import get_dataset_data
|
|
41
|
+
|
|
42
|
+
for pipeline in ret_val.values():
|
|
43
|
+
dataset_id = pipeline.dataset_id
|
|
44
|
+
|
|
45
|
+
dataset_data = await get_dataset_data(dataset_id=dataset_id)
|
|
46
|
+
|
|
47
|
+
from fastapi.encoders import jsonable_encoder
|
|
48
|
+
|
|
49
|
+
data = [
|
|
50
|
+
dict(
|
|
51
|
+
**jsonable_encoder(data),
|
|
52
|
+
dataset_id=dataset_id,
|
|
53
|
+
)
|
|
54
|
+
for data in dataset_data
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
# Check if label is properly added and stored
|
|
58
|
+
assert data[0]["label"] == "test_item"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if __name__ == "__main__":
|
|
62
|
+
logger = setup_logging(log_level=ERROR)
|
|
63
|
+
loop = asyncio.new_event_loop()
|
|
64
|
+
asyncio.set_event_loop(loop)
|
|
65
|
+
try:
|
|
66
|
+
loop.run_until_complete(main())
|
|
67
|
+
finally:
|
|
68
|
+
loop.run_until_complete(loop.shutdown_asyncgens())
|