cognee 0.5.0.dev1__py3-none-any.whl → 0.5.1__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/search/search.py +4 -0
- cognee/modules/search/methods/search.py +25 -18
- cognee/tests/unit/modules/search/test_search.py +100 -0
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dist-info}/METADATA +1 -1
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dist-info}/RECORD +9 -8
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dist-info}/WHEEL +0 -0
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dist-info}/entry_points.txt +0 -0
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dist-info}/licenses/NOTICE.md +0 -0
cognee/api/v1/search/search.py
CHANGED
|
@@ -33,6 +33,7 @@ async def search(
|
|
|
33
33
|
session_id: Optional[str] = None,
|
|
34
34
|
wide_search_top_k: Optional[int] = 100,
|
|
35
35
|
triplet_distance_penalty: Optional[float] = 3.5,
|
|
36
|
+
verbose: bool = False,
|
|
36
37
|
) -> Union[List[SearchResult], CombinedSearchResult]:
|
|
37
38
|
"""
|
|
38
39
|
Search and query the knowledge graph for insights, information, and connections.
|
|
@@ -123,6 +124,8 @@ async def search(
|
|
|
123
124
|
|
|
124
125
|
session_id: Optional session identifier for caching Q&A interactions. Defaults to 'default_session' if None.
|
|
125
126
|
|
|
127
|
+
verbose: If True, returns detailed result information including graph representation (when possible).
|
|
128
|
+
|
|
126
129
|
Returns:
|
|
127
130
|
list: Search results in format determined by query_type:
|
|
128
131
|
|
|
@@ -204,6 +207,7 @@ async def search(
|
|
|
204
207
|
session_id=session_id,
|
|
205
208
|
wide_search_top_k=wide_search_top_k,
|
|
206
209
|
triplet_distance_penalty=triplet_distance_penalty,
|
|
210
|
+
verbose=verbose,
|
|
207
211
|
)
|
|
208
212
|
|
|
209
213
|
return filtered_search_results
|
|
@@ -49,6 +49,7 @@ async def search(
|
|
|
49
49
|
session_id: Optional[str] = None,
|
|
50
50
|
wide_search_top_k: Optional[int] = 100,
|
|
51
51
|
triplet_distance_penalty: Optional[float] = 3.5,
|
|
52
|
+
verbose: bool = False,
|
|
52
53
|
) -> Union[CombinedSearchResult, List[SearchResult]]:
|
|
53
54
|
"""
|
|
54
55
|
|
|
@@ -140,6 +141,7 @@ async def search(
|
|
|
140
141
|
)
|
|
141
142
|
|
|
142
143
|
if use_combined_context:
|
|
144
|
+
# Note: combined context search must always be verbose and return a CombinedSearchResult with graphs info
|
|
143
145
|
prepared_search_results = await prepare_search_result(
|
|
144
146
|
search_results[0] if isinstance(search_results, list) else search_results
|
|
145
147
|
)
|
|
@@ -173,25 +175,30 @@ async def search(
|
|
|
173
175
|
datasets = prepared_search_results["datasets"]
|
|
174
176
|
|
|
175
177
|
if only_context:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
178
|
+
search_result_dict = {
|
|
179
|
+
"search_result": [context] if context else None,
|
|
180
|
+
"dataset_id": datasets[0].id,
|
|
181
|
+
"dataset_name": datasets[0].name,
|
|
182
|
+
"dataset_tenant_id": datasets[0].tenant_id,
|
|
183
|
+
}
|
|
184
|
+
if verbose:
|
|
185
|
+
# Include graphs only in verbose mode
|
|
186
|
+
search_result_dict["graphs"] = graphs
|
|
187
|
+
|
|
188
|
+
return_value.append(search_result_dict)
|
|
185
189
|
else:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
190
|
+
search_result_dict = {
|
|
191
|
+
"search_result": [result] if result else None,
|
|
192
|
+
"dataset_id": datasets[0].id,
|
|
193
|
+
"dataset_name": datasets[0].name,
|
|
194
|
+
"dataset_tenant_id": datasets[0].tenant_id,
|
|
195
|
+
}
|
|
196
|
+
if verbose:
|
|
197
|
+
# Include graphs only in verbose mode
|
|
198
|
+
search_result_dict["graphs"] = graphs
|
|
199
|
+
|
|
200
|
+
return_value.append(search_result_dict)
|
|
201
|
+
|
|
195
202
|
return return_value
|
|
196
203
|
else:
|
|
197
204
|
return_value = []
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import types
|
|
2
|
+
from uuid import uuid4
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from cognee.modules.search.types import SearchType
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _make_user(user_id: str = "u1", tenant_id=None):
|
|
10
|
+
return types.SimpleNamespace(id=user_id, tenant_id=tenant_id)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _make_dataset(*, name="ds", tenant_id="t1", dataset_id=None, owner_id=None):
|
|
14
|
+
return types.SimpleNamespace(
|
|
15
|
+
id=dataset_id or uuid4(),
|
|
16
|
+
name=name,
|
|
17
|
+
tenant_id=tenant_id,
|
|
18
|
+
owner_id=owner_id or uuid4(),
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture
|
|
23
|
+
def search_mod():
|
|
24
|
+
import importlib
|
|
25
|
+
|
|
26
|
+
return importlib.import_module("cognee.modules.search.methods.search")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@pytest.fixture(autouse=True)
|
|
30
|
+
def _patch_side_effect_boundaries(monkeypatch, search_mod):
|
|
31
|
+
"""
|
|
32
|
+
Keep production logic; patch only unavoidable side-effect boundaries.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
async def dummy_log_query(_query_text, _query_type, _user_id):
|
|
36
|
+
return types.SimpleNamespace(id="qid-1")
|
|
37
|
+
|
|
38
|
+
async def dummy_log_result(*_args, **_kwargs):
|
|
39
|
+
return None
|
|
40
|
+
|
|
41
|
+
async def dummy_prepare_search_result(search_result):
|
|
42
|
+
if isinstance(search_result, tuple) and len(search_result) == 3:
|
|
43
|
+
result, context, datasets = search_result
|
|
44
|
+
return {"result": result, "context": context, "graphs": {}, "datasets": datasets}
|
|
45
|
+
return {"result": None, "context": None, "graphs": {}, "datasets": []}
|
|
46
|
+
|
|
47
|
+
monkeypatch.setattr(search_mod, "send_telemetry", lambda *a, **k: None)
|
|
48
|
+
monkeypatch.setattr(search_mod, "log_query", dummy_log_query)
|
|
49
|
+
monkeypatch.setattr(search_mod, "log_result", dummy_log_result)
|
|
50
|
+
monkeypatch.setattr(search_mod, "prepare_search_result", dummy_prepare_search_result)
|
|
51
|
+
|
|
52
|
+
yield
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@pytest.mark.asyncio
|
|
56
|
+
async def test_search_access_control_returns_dataset_shaped_dicts(monkeypatch, search_mod):
|
|
57
|
+
user = _make_user()
|
|
58
|
+
ds = _make_dataset(name="ds1", tenant_id="t1")
|
|
59
|
+
|
|
60
|
+
async def dummy_authorized_search(**kwargs):
|
|
61
|
+
assert kwargs["dataset_ids"] == [ds.id]
|
|
62
|
+
return [("r", ["ctx"], [ds])]
|
|
63
|
+
|
|
64
|
+
monkeypatch.setattr(search_mod, "backend_access_control_enabled", lambda: True)
|
|
65
|
+
monkeypatch.setattr(search_mod, "authorized_search", dummy_authorized_search)
|
|
66
|
+
|
|
67
|
+
out_non_verbose = await search_mod.search(
|
|
68
|
+
query_text="q",
|
|
69
|
+
query_type=SearchType.CHUNKS,
|
|
70
|
+
dataset_ids=[ds.id],
|
|
71
|
+
user=user,
|
|
72
|
+
verbose=False,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
assert out_non_verbose == [
|
|
76
|
+
{
|
|
77
|
+
"search_result": ["r"],
|
|
78
|
+
"dataset_id": ds.id,
|
|
79
|
+
"dataset_name": "ds1",
|
|
80
|
+
"dataset_tenant_id": "t1",
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
out_verbose = await search_mod.search(
|
|
85
|
+
query_text="q",
|
|
86
|
+
query_type=SearchType.CHUNKS,
|
|
87
|
+
dataset_ids=[ds.id],
|
|
88
|
+
user=user,
|
|
89
|
+
verbose=True,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
assert out_verbose == [
|
|
93
|
+
{
|
|
94
|
+
"search_result": ["r"],
|
|
95
|
+
"dataset_id": ds.id,
|
|
96
|
+
"dataset_name": "ds1",
|
|
97
|
+
"dataset_tenant_id": "t1",
|
|
98
|
+
"graphs": {},
|
|
99
|
+
}
|
|
100
|
+
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cognee
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: Cognee - is a library for enriching LLM context with a semantic layer for better understanding and reasoning.
|
|
5
5
|
Project-URL: Homepage, https://www.cognee.ai
|
|
6
6
|
Project-URL: Repository, https://github.com/topoteretes/cognee
|
|
@@ -56,7 +56,7 @@ cognee/api/v1/responses/routers/__init__.py,sha256=X2qishwGRVFXawnvkZ5bv420PuPRL
|
|
|
56
56
|
cognee/api/v1/responses/routers/default_tools.py,sha256=1SM-hnmJWAjjtEVdgTDRpocPrj0LjOUW-Y9TPQMcu2o,2968
|
|
57
57
|
cognee/api/v1/responses/routers/get_responses_router.py,sha256=ggbLhY9IXaInCgIs5TUuOCkFW64xmTKZQsc2ENq2Ocs,5979
|
|
58
58
|
cognee/api/v1/search/__init__.py,sha256=Sqw60DcOj4Bnvt-EWFknT31sPcvROIRKCWLr5pbkFr4,39
|
|
59
|
-
cognee/api/v1/search/search.py,sha256=
|
|
59
|
+
cognee/api/v1/search/search.py,sha256=qLxCgisrkdHvI5jXD9HkZgdgpz4sNUPo0-QC8k3WuNo,9411
|
|
60
60
|
cognee/api/v1/search/routers/__init__.py,sha256=6RebeLX_2NTRxIMPH_mGuLztPxnGnMJK1y_O93CtRm8,49
|
|
61
61
|
cognee/api/v1/search/routers/get_search_router.py,sha256=vMAgHG26AcNBkiK-aKIQgADSX4shLfu68tgWbblv3Go,6354
|
|
62
62
|
cognee/api/v1/settings/routers/__init__.py,sha256=wj_UYAXNMPCkn6Mo1YB01dCBiV9DQwTIf6OWjnGRpf8,53
|
|
@@ -630,7 +630,7 @@ cognee/modules/search/exceptions/exceptions.py,sha256=Zc5Y0M-r-UnSSlpKzHKBplfjZ-
|
|
|
630
630
|
cognee/modules/search/methods/__init__.py,sha256=jGfRvNwM5yIzj025gaVhcx7nCupRSXbUUnFjYVjL_Js,27
|
|
631
631
|
cognee/modules/search/methods/get_search_type_tools.py,sha256=1XL-dxinGDVB7aiVwi5573qJAOux7LLj-ISQ8Xi3Sko,9213
|
|
632
632
|
cognee/modules/search/methods/no_access_control_search.py,sha256=9npzFlFk5XteUoTgMbSyPtCqMl0Ve5JJEtt1kx_TDWE,2267
|
|
633
|
-
cognee/modules/search/methods/search.py,sha256=
|
|
633
|
+
cognee/modules/search/methods/search.py,sha256=8df0H3zQCeIeFWQ10N0JzB5Ts6t3V95ySx8UX-SqvfY,16632
|
|
634
634
|
cognee/modules/search/models/Query.py,sha256=9WcF5Z1oCFtA4O-7An37eNAPX3iyygO4B5NSwhx7iIg,558
|
|
635
635
|
cognee/modules/search/models/Result.py,sha256=U7QtoNzAtZnUDwGWhjVfcalHQd4daKtYYvJz2BeWQ4w,564
|
|
636
636
|
cognee/modules/search/operations/__init__.py,sha256=AwJl6v9BTpocoefEZLk-flo1EtydYb46NSUoNFHkhX0,156
|
|
@@ -966,6 +966,7 @@ cognee/tests/unit/modules/retrieval/temporal_retriever_test.py,sha256=5AJi0aL-hG
|
|
|
966
966
|
cognee/tests/unit/modules/retrieval/test_brute_force_triplet_search.py,sha256=ANo4dDrVM1K3yYvXN-KzdFcr9OeYd1EV9_ltkNUQqHw,23148
|
|
967
967
|
cognee/tests/unit/modules/retrieval/triplet_retriever_test.py,sha256=D0wo6boeg3wRFHgPfa0KxtablpL4agT3irLC_R3lHLM,2861
|
|
968
968
|
cognee/tests/unit/modules/retriever/test_description_to_codepart_search.py,sha256=oayCbXQtvmTnlgOuR67w_r278TGMEv-puaTR_jI6weo,4164
|
|
969
|
+
cognee/tests/unit/modules/search/test_search.py,sha256=7KOV3_Qu7H-n4ztH_YvJBEEv-CSYSwptw2cuTIw298c,2930
|
|
969
970
|
cognee/tests/unit/modules/users/__init__.py,sha256=SkGMpbXemeX0834-eUj14VuNlZgtOGMxk0C-r-jSsnU,37
|
|
970
971
|
cognee/tests/unit/modules/users/test_conditional_authentication.py,sha256=dqJpllMIznMc8d0-fh1-u1UftWJyyEXxoykbmeZhcHE,8190
|
|
971
972
|
cognee/tests/unit/modules/users/test_tutorial_notebook_creation.py,sha256=M_NXBSLr-U7MqKtHiERMRzI7pWRm0CywZYzFUwKYV0w,16028
|
|
@@ -994,9 +995,9 @@ distributed/tasks/queued_add_edges.py,sha256=kz1DHE05y-kNHORQJjYWHUi6Q1QWUp_v3Dl
|
|
|
994
995
|
distributed/tasks/queued_add_nodes.py,sha256=aqK4Ij--ADwUWknxYpiwbYrpa6CcvFfqHWbUZW4Kh3A,452
|
|
995
996
|
distributed/workers/data_point_saving_worker.py,sha256=kmaQy2A2J7W3k9Gd5lyoiT0XYOaJmEM8MbkKVOFOQVU,4729
|
|
996
997
|
distributed/workers/graph_saving_worker.py,sha256=b5OPLLUq0OBALGekdp73JKxU0GrMlVbO4AfIhmACKkQ,4724
|
|
997
|
-
cognee-0.5.
|
|
998
|
-
cognee-0.5.
|
|
999
|
-
cognee-0.5.
|
|
1000
|
-
cognee-0.5.
|
|
1001
|
-
cognee-0.5.
|
|
1002
|
-
cognee-0.5.
|
|
998
|
+
cognee-0.5.1.dist-info/METADATA,sha256=CvUNUJM5DCrgbKL51i8LDAxBXMQH19Gt2gatzOeFxPU,15632
|
|
999
|
+
cognee-0.5.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
1000
|
+
cognee-0.5.1.dist-info/entry_points.txt,sha256=GCCTsNg8gzOJkolq7dR7OK1VlIAO202dGDnMI8nm8oQ,55
|
|
1001
|
+
cognee-0.5.1.dist-info/licenses/LICENSE,sha256=pHHjSQj1DD8SDppW88MMs04TPk7eAanL1c5xj8NY7NQ,11344
|
|
1002
|
+
cognee-0.5.1.dist-info/licenses/NOTICE.md,sha256=6L3saP3kSpcingOxDh-SGjMS8GY79Rlh2dBNLaO0o5c,339
|
|
1003
|
+
cognee-0.5.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|