cognee 0.2.1.dev6__py3-none-any.whl → 0.2.2.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/.env.example +5 -0
- cognee/api/client.py +14 -1
- cognee/api/v1/add/add.py +1 -1
- cognee/api/v1/add/routers/get_add_router.py +19 -9
- cognee/api/v1/cognify/routers/get_cognify_router.py +14 -7
- cognee/api/v1/config/config.py +0 -12
- cognee/api/v1/datasets/routers/get_datasets_router.py +66 -2
- cognee/api/v1/delete/routers/get_delete_router.py +11 -0
- cognee/api/v1/permissions/routers/get_permissions_router.py +50 -1
- cognee/api/v1/search/routers/get_search_router.py +28 -5
- cognee/api/v1/users/routers/get_visualize_router.py +10 -0
- cognee/base_config.py +0 -2
- cognee/infrastructure/databases/graph/kuzu/adapter.py +31 -9
- cognee/infrastructure/databases/graph/kuzu/kuzu_migrate.py +281 -0
- cognee/infrastructure/databases/graph/neo4j_driver/adapter.py +103 -64
- cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py +10 -3
- cognee/infrastructure/databases/vector/create_vector_engine.py +3 -11
- cognee/modules/data/models/Data.py +2 -2
- cognee/modules/data/processing/document_types/UnstructuredDocument.py +2 -5
- cognee/modules/graph/cognee_graph/CogneeGraph.py +39 -20
- cognee/modules/graph/methods/get_formatted_graph_data.py +1 -1
- cognee/modules/graph/utils/expand_with_nodes_and_edges.py +1 -1
- cognee/modules/ingestion/classify.py +1 -3
- cognee/modules/pipelines/operations/run_tasks.py +1 -1
- cognee/modules/pipelines/operations/run_tasks_distributed.py +1 -1
- cognee/modules/retrieval/chunks_retriever.py +23 -1
- cognee/modules/retrieval/code_retriever.py +64 -5
- cognee/modules/retrieval/completion_retriever.py +12 -10
- cognee/modules/retrieval/graph_completion_retriever.py +1 -1
- cognee/modules/retrieval/insights_retriever.py +4 -0
- cognee/modules/retrieval/natural_language_retriever.py +6 -10
- cognee/modules/retrieval/summaries_retriever.py +23 -1
- cognee/modules/retrieval/utils/brute_force_triplet_search.py +26 -5
- cognee/modules/settings/get_settings.py +0 -4
- cognee/modules/settings/save_vector_db_config.py +1 -1
- cognee/shared/utils.py +0 -2
- cognee/tasks/graph/extract_graph_from_data.py +2 -2
- cognee/tests/test_edge_ingestion.py +88 -0
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +84 -9
- cognee/tests/unit/processing/utils/utils_test.py +0 -2
- {cognee-0.2.1.dev6.dist-info → cognee-0.2.2.dev0.dist-info}/METADATA +6 -10
- {cognee-0.2.1.dev6.dist-info → cognee-0.2.2.dev0.dist-info}/RECORD +45 -43
- cognee/tests/test_weaviate.py +0 -94
- {cognee-0.2.1.dev6.dist-info → cognee-0.2.2.dev0.dist-info}/WHEEL +0 -0
- {cognee-0.2.1.dev6.dist-info → cognee-0.2.2.dev0.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.2.1.dev6.dist-info → cognee-0.2.2.dev0.dist-info}/licenses/NOTICE.md +0 -0
cognee/api/.env.example
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Comma-separated list of allowed origins for CORS (leave empty to block all cross-origin requests)
|
|
2
|
+
# Example:
|
|
3
|
+
# CORS_ALLOWED_ORIGINS="https://yourdomain.com,https://another.com"
|
|
4
|
+
# For local development, you might use:
|
|
5
|
+
# CORS_ALLOWED_ORIGINS="http://localhost:3000"
|
cognee/api/client.py
CHANGED
|
@@ -67,13 +67,26 @@ async def lifespan(app: FastAPI):
|
|
|
67
67
|
app = FastAPI(debug=app_environment != "prod", lifespan=lifespan)
|
|
68
68
|
|
|
69
69
|
|
|
70
|
+
# Read allowed origins from environment variable (comma-separated)
|
|
71
|
+
CORS_ALLOWED_ORIGINS = os.getenv("CORS_ALLOWED_ORIGINS")
|
|
72
|
+
if CORS_ALLOWED_ORIGINS:
|
|
73
|
+
allowed_origins = [
|
|
74
|
+
origin.strip() for origin in CORS_ALLOWED_ORIGINS.split(",") if origin.strip()
|
|
75
|
+
]
|
|
76
|
+
else:
|
|
77
|
+
allowed_origins = [
|
|
78
|
+
"http://localhost:3000",
|
|
79
|
+
] # Block all except explicitly set origins
|
|
80
|
+
|
|
70
81
|
app.add_middleware(
|
|
71
82
|
CORSMiddleware,
|
|
72
|
-
allow_origins=
|
|
83
|
+
allow_origins=allowed_origins, # Now controlled by env var
|
|
73
84
|
allow_credentials=True,
|
|
74
85
|
allow_methods=["OPTIONS", "GET", "POST", "DELETE"],
|
|
75
86
|
allow_headers=["*"],
|
|
76
87
|
)
|
|
88
|
+
# To allow origins, set CORS_ALLOWED_ORIGINS env variable to a comma-separated list, e.g.:
|
|
89
|
+
# CORS_ALLOWED_ORIGINS="https://yourdomain.com,https://another.com"
|
|
77
90
|
|
|
78
91
|
|
|
79
92
|
def custom_openapi():
|
cognee/api/v1/add/add.py
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import requests
|
|
3
|
+
import subprocess
|
|
2
4
|
from uuid import UUID
|
|
3
5
|
|
|
4
|
-
from fastapi import Form, UploadFile, Depends
|
|
5
|
-
from fastapi.responses import JSONResponse
|
|
6
6
|
from fastapi import APIRouter
|
|
7
|
-
from
|
|
8
|
-
import
|
|
9
|
-
from
|
|
10
|
-
import requests
|
|
7
|
+
from fastapi.responses import JSONResponse
|
|
8
|
+
from fastapi import Form, File, UploadFile, Depends
|
|
9
|
+
from typing import List, Optional, Union, Literal
|
|
11
10
|
|
|
12
11
|
from cognee.modules.users.models import User
|
|
13
12
|
from cognee.modules.users.methods import get_authenticated_user
|
|
13
|
+
from cognee.shared.utils import send_telemetry
|
|
14
|
+
from cognee.shared.logging_utils import get_logger
|
|
14
15
|
|
|
15
16
|
logger = get_logger()
|
|
16
17
|
|
|
@@ -20,9 +21,9 @@ def get_add_router() -> APIRouter:
|
|
|
20
21
|
|
|
21
22
|
@router.post("", response_model=dict)
|
|
22
23
|
async def add(
|
|
23
|
-
data: List[UploadFile],
|
|
24
|
+
data: List[UploadFile] = File(default=None),
|
|
24
25
|
datasetName: Optional[str] = Form(default=None),
|
|
25
|
-
datasetId:
|
|
26
|
+
datasetId: Union[UUID, Literal[""], None] = Form(default=None, examples=[""]),
|
|
26
27
|
user: User = Depends(get_authenticated_user),
|
|
27
28
|
):
|
|
28
29
|
"""
|
|
@@ -38,7 +39,7 @@ def get_add_router() -> APIRouter:
|
|
|
38
39
|
- GitHub repository URLs (will be cloned and processed)
|
|
39
40
|
- Regular file uploads
|
|
40
41
|
- **datasetName** (Optional[str]): Name of the dataset to add data to
|
|
41
|
-
- **datasetId** (Optional[UUID]): UUID of
|
|
42
|
+
- **datasetId** (Optional[UUID]): UUID of an already existing dataset
|
|
42
43
|
|
|
43
44
|
Either datasetName or datasetId must be provided.
|
|
44
45
|
|
|
@@ -58,7 +59,16 @@ def get_add_router() -> APIRouter:
|
|
|
58
59
|
- GitHub repositories are cloned and all files are processed
|
|
59
60
|
- HTTP URLs are fetched and their content is processed
|
|
60
61
|
- The ALLOW_HTTP_REQUESTS environment variable controls URL processing
|
|
62
|
+
- datasetId value can only be the UUID of an already existing dataset
|
|
61
63
|
"""
|
|
64
|
+
send_telemetry(
|
|
65
|
+
"Add API Endpoint Invoked",
|
|
66
|
+
user.id,
|
|
67
|
+
additional_properties={
|
|
68
|
+
"endpoint": "POST /v1/add",
|
|
69
|
+
},
|
|
70
|
+
)
|
|
71
|
+
|
|
62
72
|
from cognee.api.v1.add import add as cognee_add
|
|
63
73
|
|
|
64
74
|
if not datasetId and not datasetName:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import asyncio
|
|
3
3
|
from uuid import UUID
|
|
4
|
-
from pydantic import
|
|
4
|
+
from pydantic import Field
|
|
5
5
|
from typing import List, Optional
|
|
6
6
|
from fastapi.responses import JSONResponse
|
|
7
7
|
from fastapi import APIRouter, WebSocket, Depends, WebSocketDisconnect
|
|
@@ -10,7 +10,6 @@ from starlette.status import WS_1000_NORMAL_CLOSURE, WS_1008_POLICY_VIOLATION
|
|
|
10
10
|
from cognee.api.DTO import InDTO
|
|
11
11
|
from cognee.modules.pipelines.methods import get_pipeline_run
|
|
12
12
|
from cognee.modules.users.models import User
|
|
13
|
-
from cognee.shared.data_models import KnowledgeGraph
|
|
14
13
|
from cognee.modules.users.methods import get_authenticated_user
|
|
15
14
|
from cognee.modules.users.get_user_db import get_user_db_context
|
|
16
15
|
from cognee.modules.graph.methods import get_formatted_graph_data
|
|
@@ -24,15 +23,16 @@ from cognee.modules.pipelines.queues.pipeline_run_info_queues import (
|
|
|
24
23
|
remove_queue,
|
|
25
24
|
)
|
|
26
25
|
from cognee.shared.logging_utils import get_logger
|
|
26
|
+
from cognee.shared.utils import send_telemetry
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
logger = get_logger("api.cognify")
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
class CognifyPayloadDTO(InDTO):
|
|
33
|
-
datasets: Optional[List[str]] = None
|
|
34
|
-
dataset_ids: Optional[List[UUID]] = None
|
|
35
|
-
run_in_background: Optional[bool] = False
|
|
33
|
+
datasets: Optional[List[str]] = Field(default=None)
|
|
34
|
+
dataset_ids: Optional[List[UUID]] = Field(default=None, examples=[[]])
|
|
35
|
+
run_in_background: Optional[bool] = Field(default=False)
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
def get_cognify_router() -> APIRouter:
|
|
@@ -57,8 +57,7 @@ def get_cognify_router() -> APIRouter:
|
|
|
57
57
|
|
|
58
58
|
## Request Parameters
|
|
59
59
|
- **datasets** (Optional[List[str]]): List of dataset names to process. Dataset names are resolved to datasets owned by the authenticated user.
|
|
60
|
-
- **dataset_ids** (Optional[List[UUID]]): List of dataset UUIDs to process. UUIDs allow processing of datasets not owned by the user (if permitted).
|
|
61
|
-
- **graph_model** (Optional[BaseModel]): Custom Pydantic model defining the knowledge graph schema. Defaults to KnowledgeGraph for general-purpose processing.
|
|
60
|
+
- **dataset_ids** (Optional[List[UUID]]): List of existing dataset UUIDs to process. UUIDs allow processing of datasets not owned by the user (if permitted).
|
|
62
61
|
- **run_in_background** (Optional[bool]): Whether to execute processing asynchronously. Defaults to False (blocking).
|
|
63
62
|
|
|
64
63
|
## Response
|
|
@@ -84,6 +83,14 @@ def get_cognify_router() -> APIRouter:
|
|
|
84
83
|
## Next Steps
|
|
85
84
|
After successful processing, use the search endpoints to query the generated knowledge graph for insights, relationships, and semantic search.
|
|
86
85
|
"""
|
|
86
|
+
send_telemetry(
|
|
87
|
+
"Cognify API Endpoint Invoked",
|
|
88
|
+
user.id,
|
|
89
|
+
additional_properties={
|
|
90
|
+
"endpoint": "POST /v1/cognify",
|
|
91
|
+
},
|
|
92
|
+
)
|
|
93
|
+
|
|
87
94
|
if not payload.datasets and not payload.dataset_ids:
|
|
88
95
|
return JSONResponse(
|
|
89
96
|
status_code=400, content={"error": "No datasets or dataset_ids provided"}
|
cognee/api/v1/config/config.py
CHANGED
|
@@ -182,15 +182,3 @@ class config:
|
|
|
182
182
|
def set_vector_db_url(db_url: str):
|
|
183
183
|
vector_db_config = get_vectordb_config()
|
|
184
184
|
vector_db_config.vector_db_url = db_url
|
|
185
|
-
|
|
186
|
-
@staticmethod
|
|
187
|
-
def set_graphistry_config(graphistry_config: dict[str, str]):
|
|
188
|
-
base_config = get_base_config()
|
|
189
|
-
|
|
190
|
-
if "username" not in graphistry_config or "password" not in graphistry_config:
|
|
191
|
-
raise InvalidValueError(
|
|
192
|
-
message="graphistry_config dictionary must contain 'username' and 'password' keys."
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
base_config.graphistry_username = graphistry_config.get("username")
|
|
196
|
-
base_config.graphistry_password = graphistry_config.get("password")
|
|
@@ -22,6 +22,7 @@ from cognee.modules.users.permissions.methods import (
|
|
|
22
22
|
)
|
|
23
23
|
from cognee.modules.graph.methods import get_formatted_graph_data
|
|
24
24
|
from cognee.modules.pipelines.models import PipelineRunStatus
|
|
25
|
+
from cognee.shared.utils import send_telemetry
|
|
25
26
|
|
|
26
27
|
logger = get_logger()
|
|
27
28
|
|
|
@@ -92,6 +93,14 @@ def get_datasets_router() -> APIRouter:
|
|
|
92
93
|
## Error Codes
|
|
93
94
|
- **418 I'm a teapot**: Error retrieving datasets
|
|
94
95
|
"""
|
|
96
|
+
send_telemetry(
|
|
97
|
+
"Datasets API Endpoint Invoked",
|
|
98
|
+
user.id,
|
|
99
|
+
additional_properties={
|
|
100
|
+
"endpoint": "GET /v1/datasets",
|
|
101
|
+
},
|
|
102
|
+
)
|
|
103
|
+
|
|
95
104
|
try:
|
|
96
105
|
datasets = await get_all_user_permission_datasets(user, "read")
|
|
97
106
|
|
|
@@ -130,6 +139,14 @@ def get_datasets_router() -> APIRouter:
|
|
|
130
139
|
## Error Codes
|
|
131
140
|
- **418 I'm a teapot**: Error creating dataset
|
|
132
141
|
"""
|
|
142
|
+
send_telemetry(
|
|
143
|
+
"Datasets API Endpoint Invoked",
|
|
144
|
+
user.id,
|
|
145
|
+
additional_properties={
|
|
146
|
+
"endpoint": "POST /v1/datasets",
|
|
147
|
+
},
|
|
148
|
+
)
|
|
149
|
+
|
|
133
150
|
try:
|
|
134
151
|
datasets = await get_datasets_by_name([dataset_data.name], user.id)
|
|
135
152
|
|
|
@@ -175,6 +192,15 @@ def get_datasets_router() -> APIRouter:
|
|
|
175
192
|
- **404 Not Found**: Dataset doesn't exist or user doesn't have access
|
|
176
193
|
- **500 Internal Server Error**: Error during deletion
|
|
177
194
|
"""
|
|
195
|
+
send_telemetry(
|
|
196
|
+
"Datasets API Endpoint Invoked",
|
|
197
|
+
user.id,
|
|
198
|
+
additional_properties={
|
|
199
|
+
"endpoint": f"DELETE /v1/datasets/{str(dataset_id)}",
|
|
200
|
+
"dataset_id": str(dataset_id),
|
|
201
|
+
},
|
|
202
|
+
)
|
|
203
|
+
|
|
178
204
|
from cognee.modules.data.methods import get_dataset, delete_dataset
|
|
179
205
|
|
|
180
206
|
dataset = await get_dataset(user.id, dataset_id)
|
|
@@ -210,6 +236,16 @@ def get_datasets_router() -> APIRouter:
|
|
|
210
236
|
- **404 Not Found**: Dataset or data item doesn't exist, or user doesn't have access
|
|
211
237
|
- **500 Internal Server Error**: Error during deletion
|
|
212
238
|
"""
|
|
239
|
+
send_telemetry(
|
|
240
|
+
"Datasets API Endpoint Invoked",
|
|
241
|
+
user.id,
|
|
242
|
+
additional_properties={
|
|
243
|
+
"endpoint": f"DELETE /v1/datasets/{str(dataset_id)}/data/{str(data_id)}",
|
|
244
|
+
"dataset_id": str(dataset_id),
|
|
245
|
+
"data_id": str(data_id),
|
|
246
|
+
},
|
|
247
|
+
)
|
|
248
|
+
|
|
213
249
|
from cognee.modules.data.methods import get_data, delete_data
|
|
214
250
|
from cognee.modules.data.methods import get_dataset
|
|
215
251
|
|
|
@@ -254,7 +290,7 @@ def get_datasets_router() -> APIRouter:
|
|
|
254
290
|
if dataset is None:
|
|
255
291
|
raise DatasetNotFoundError(message=f"Dataset ({str(dataset_id)}) not found.")
|
|
256
292
|
|
|
257
|
-
graph_data = await get_formatted_graph_data(dataset)
|
|
293
|
+
graph_data = await get_formatted_graph_data(dataset.id, user.id)
|
|
258
294
|
|
|
259
295
|
return graph_data
|
|
260
296
|
|
|
@@ -288,6 +324,15 @@ def get_datasets_router() -> APIRouter:
|
|
|
288
324
|
- **404 Not Found**: Dataset doesn't exist or user doesn't have access
|
|
289
325
|
- **500 Internal Server Error**: Error retrieving data
|
|
290
326
|
"""
|
|
327
|
+
send_telemetry(
|
|
328
|
+
"Datasets API Endpoint Invoked",
|
|
329
|
+
user.id,
|
|
330
|
+
additional_properties={
|
|
331
|
+
"endpoint": f"GET /v1/datasets/{str(dataset_id)}/data",
|
|
332
|
+
"dataset_id": str(dataset_id),
|
|
333
|
+
},
|
|
334
|
+
)
|
|
335
|
+
|
|
291
336
|
from cognee.modules.data.methods import get_dataset_data, get_dataset
|
|
292
337
|
|
|
293
338
|
# Verify user has permission to read dataset
|
|
@@ -308,7 +353,7 @@ def get_datasets_router() -> APIRouter:
|
|
|
308
353
|
|
|
309
354
|
@router.get("/status", response_model=dict[str, PipelineRunStatus])
|
|
310
355
|
async def get_dataset_status(
|
|
311
|
-
datasets: Annotated[List[UUID], Query(alias="dataset")] =
|
|
356
|
+
datasets: Annotated[List[UUID], Query(alias="dataset")] = [],
|
|
312
357
|
user: User = Depends(get_authenticated_user),
|
|
313
358
|
):
|
|
314
359
|
"""
|
|
@@ -331,6 +376,15 @@ def get_datasets_router() -> APIRouter:
|
|
|
331
376
|
## Error Codes
|
|
332
377
|
- **500 Internal Server Error**: Error retrieving status information
|
|
333
378
|
"""
|
|
379
|
+
send_telemetry(
|
|
380
|
+
"Datasets API Endpoint Invoked",
|
|
381
|
+
user.id,
|
|
382
|
+
additional_properties={
|
|
383
|
+
"endpoint": "GET /v1/datasets/status",
|
|
384
|
+
"datasets": [str(dataset_id) for dataset_id in datasets],
|
|
385
|
+
},
|
|
386
|
+
)
|
|
387
|
+
|
|
334
388
|
from cognee.api.v1.datasets.datasets import datasets as cognee_datasets
|
|
335
389
|
|
|
336
390
|
try:
|
|
@@ -367,6 +421,16 @@ def get_datasets_router() -> APIRouter:
|
|
|
367
421
|
- **404 Not Found**: Dataset or data item doesn't exist, or user doesn't have access
|
|
368
422
|
- **500 Internal Server Error**: Error accessing the raw data file
|
|
369
423
|
"""
|
|
424
|
+
send_telemetry(
|
|
425
|
+
"Datasets API Endpoint Invoked",
|
|
426
|
+
user.id,
|
|
427
|
+
additional_properties={
|
|
428
|
+
"endpoint": f"GET /v1/datasets/{str(dataset_id)}/data/{str(data_id)}/raw",
|
|
429
|
+
"dataset_id": str(dataset_id),
|
|
430
|
+
"data_id": str(data_id),
|
|
431
|
+
},
|
|
432
|
+
)
|
|
433
|
+
|
|
370
434
|
from cognee.modules.data.methods import get_data
|
|
371
435
|
from cognee.modules.data.methods import get_dataset_data
|
|
372
436
|
|
|
@@ -5,6 +5,7 @@ from uuid import UUID
|
|
|
5
5
|
from cognee.shared.logging_utils import get_logger
|
|
6
6
|
from cognee.modules.users.models import User
|
|
7
7
|
from cognee.modules.users.methods import get_authenticated_user
|
|
8
|
+
from cognee.shared.utils import send_telemetry
|
|
8
9
|
|
|
9
10
|
logger = get_logger()
|
|
10
11
|
|
|
@@ -31,6 +32,16 @@ def get_delete_router() -> APIRouter:
|
|
|
31
32
|
JSON response indicating success or failure
|
|
32
33
|
|
|
33
34
|
"""
|
|
35
|
+
send_telemetry(
|
|
36
|
+
"Delete API Endpoint Invoked",
|
|
37
|
+
user.id,
|
|
38
|
+
additional_properties={
|
|
39
|
+
"endpoint": "DELETE /v1/delete",
|
|
40
|
+
"dataset_id": str(dataset_id),
|
|
41
|
+
"data_id": str(data_id),
|
|
42
|
+
},
|
|
43
|
+
)
|
|
44
|
+
|
|
34
45
|
from cognee.api.v1.delete import delete as cognee_delete
|
|
35
46
|
|
|
36
47
|
try:
|
|
@@ -6,12 +6,13 @@ from fastapi.responses import JSONResponse
|
|
|
6
6
|
|
|
7
7
|
from cognee.modules.users.models import User
|
|
8
8
|
from cognee.modules.users.methods import get_authenticated_user
|
|
9
|
+
from cognee.shared.utils import send_telemetry
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
def get_permissions_router() -> APIRouter:
|
|
12
13
|
permissions_router = APIRouter()
|
|
13
14
|
|
|
14
|
-
@permissions_router.post("/datasets/{principal_id}
|
|
15
|
+
@permissions_router.post("/datasets/{principal_id}")
|
|
15
16
|
async def give_datasets_permission_to_principal(
|
|
16
17
|
permission_name: str,
|
|
17
18
|
dataset_ids: List[UUID],
|
|
@@ -40,6 +41,16 @@ def get_permissions_router() -> APIRouter:
|
|
|
40
41
|
- **403 Forbidden**: User doesn't have permission to grant access
|
|
41
42
|
- **500 Internal Server Error**: Error granting permission
|
|
42
43
|
"""
|
|
44
|
+
send_telemetry(
|
|
45
|
+
"Permissions API Endpoint Invoked",
|
|
46
|
+
user.id,
|
|
47
|
+
additional_properties={
|
|
48
|
+
"endpoint": f"POST /v1/permissions/datasets/{str(principal_id)}",
|
|
49
|
+
"dataset_ids": str(dataset_ids),
|
|
50
|
+
"principal_id": str(principal_id),
|
|
51
|
+
},
|
|
52
|
+
)
|
|
53
|
+
|
|
43
54
|
from cognee.modules.users.permissions.methods import authorized_give_permission_on_datasets
|
|
44
55
|
|
|
45
56
|
await authorized_give_permission_on_datasets(
|
|
@@ -72,6 +83,15 @@ def get_permissions_router() -> APIRouter:
|
|
|
72
83
|
- **400 Bad Request**: Invalid role name or role already exists
|
|
73
84
|
- **500 Internal Server Error**: Error creating the role
|
|
74
85
|
"""
|
|
86
|
+
send_telemetry(
|
|
87
|
+
"Permissions API Endpoint Invoked",
|
|
88
|
+
user.id,
|
|
89
|
+
additional_properties={
|
|
90
|
+
"endpoint": "POST /v1/permissions/roles",
|
|
91
|
+
"role_name": role_name,
|
|
92
|
+
},
|
|
93
|
+
)
|
|
94
|
+
|
|
75
95
|
from cognee.modules.users.roles.methods import create_role as create_role_method
|
|
76
96
|
|
|
77
97
|
await create_role_method(role_name=role_name, owner_id=user.id)
|
|
@@ -104,6 +124,16 @@ def get_permissions_router() -> APIRouter:
|
|
|
104
124
|
- **404 Not Found**: User or role doesn't exist
|
|
105
125
|
- **500 Internal Server Error**: Error adding user to role
|
|
106
126
|
"""
|
|
127
|
+
send_telemetry(
|
|
128
|
+
"Permissions API Endpoint Invoked",
|
|
129
|
+
user.id,
|
|
130
|
+
additional_properties={
|
|
131
|
+
"endpoint": f"POST /v1/permissions/users/{str(user_id)}/roles",
|
|
132
|
+
"user_id": str(user_id),
|
|
133
|
+
"role_id": str(role_id),
|
|
134
|
+
},
|
|
135
|
+
)
|
|
136
|
+
|
|
107
137
|
from cognee.modules.users.roles.methods import add_user_to_role as add_user_to_role_method
|
|
108
138
|
|
|
109
139
|
await add_user_to_role_method(user_id=user_id, role_id=role_id, owner_id=user.id)
|
|
@@ -136,6 +166,16 @@ def get_permissions_router() -> APIRouter:
|
|
|
136
166
|
- **404 Not Found**: User or tenant doesn't exist
|
|
137
167
|
- **500 Internal Server Error**: Error adding user to tenant
|
|
138
168
|
"""
|
|
169
|
+
send_telemetry(
|
|
170
|
+
"Permissions API Endpoint Invoked",
|
|
171
|
+
user.id,
|
|
172
|
+
additional_properties={
|
|
173
|
+
"endpoint": f"POST /v1/permissions/users/{str(user_id)}/tenants",
|
|
174
|
+
"user_id": str(user_id),
|
|
175
|
+
"tenant_id": str(tenant_id),
|
|
176
|
+
},
|
|
177
|
+
)
|
|
178
|
+
|
|
139
179
|
from cognee.modules.users.tenants.methods import add_user_to_tenant
|
|
140
180
|
|
|
141
181
|
await add_user_to_tenant(user_id=user_id, tenant_id=tenant_id, owner_id=user.id)
|
|
@@ -161,6 +201,15 @@ def get_permissions_router() -> APIRouter:
|
|
|
161
201
|
- **400 Bad Request**: Invalid tenant name or tenant already exists
|
|
162
202
|
- **500 Internal Server Error**: Error creating the tenant
|
|
163
203
|
"""
|
|
204
|
+
send_telemetry(
|
|
205
|
+
"Permissions API Endpoint Invoked",
|
|
206
|
+
user.id,
|
|
207
|
+
additional_properties={
|
|
208
|
+
"endpoint": "POST /v1/permissions/tenants",
|
|
209
|
+
"tenant_name": tenant_name,
|
|
210
|
+
},
|
|
211
|
+
)
|
|
212
|
+
|
|
164
213
|
from cognee.modules.users.tenants.methods import create_tenant as create_tenant_method
|
|
165
214
|
|
|
166
215
|
await create_tenant_method(tenant_name=tenant_name, user_id=user.id)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from uuid import UUID
|
|
2
2
|
from typing import Optional
|
|
3
3
|
from datetime import datetime
|
|
4
|
+
from pydantic import Field
|
|
4
5
|
from fastapi import Depends, APIRouter
|
|
5
6
|
from fastapi.responses import JSONResponse
|
|
6
7
|
from cognee.modules.search.types import SearchType
|
|
@@ -9,16 +10,17 @@ from cognee.modules.users.exceptions.exceptions import PermissionDeniedError
|
|
|
9
10
|
from cognee.modules.users.models import User
|
|
10
11
|
from cognee.modules.search.operations import get_history
|
|
11
12
|
from cognee.modules.users.methods import get_authenticated_user
|
|
13
|
+
from cognee.shared.utils import send_telemetry
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
# Note: Datasets sent by name will only map to datasets owned by the request sender
|
|
15
17
|
# To search for datasets not owned by the request sender dataset UUID is needed
|
|
16
18
|
class SearchPayloadDTO(InDTO):
|
|
17
|
-
search_type: SearchType
|
|
18
|
-
datasets: Optional[list[str]] = None
|
|
19
|
-
dataset_ids: Optional[list[UUID]] = None
|
|
20
|
-
query: str
|
|
21
|
-
top_k: Optional[int] = 10
|
|
19
|
+
search_type: SearchType = Field(default=SearchType.GRAPH_COMPLETION)
|
|
20
|
+
datasets: Optional[list[str]] = Field(default=None)
|
|
21
|
+
dataset_ids: Optional[list[UUID]] = Field(default=None, examples=[[]])
|
|
22
|
+
query: str = Field(default="What is in the document?")
|
|
23
|
+
top_k: Optional[int] = Field(default=10)
|
|
22
24
|
|
|
23
25
|
|
|
24
26
|
def get_search_router() -> APIRouter:
|
|
@@ -48,6 +50,14 @@ def get_search_router() -> APIRouter:
|
|
|
48
50
|
## Error Codes
|
|
49
51
|
- **500 Internal Server Error**: Error retrieving search history
|
|
50
52
|
"""
|
|
53
|
+
send_telemetry(
|
|
54
|
+
"Search API Endpoint Invoked",
|
|
55
|
+
user.id,
|
|
56
|
+
additional_properties={
|
|
57
|
+
"endpoint": "GET /v1/search",
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
|
|
51
61
|
try:
|
|
52
62
|
history = await get_history(user.id, limit=0)
|
|
53
63
|
|
|
@@ -83,6 +93,19 @@ def get_search_router() -> APIRouter:
|
|
|
83
93
|
- To search datasets not owned by the request sender, dataset UUID is needed
|
|
84
94
|
- If permission is denied, returns empty list instead of error
|
|
85
95
|
"""
|
|
96
|
+
send_telemetry(
|
|
97
|
+
"Search API Endpoint Invoked",
|
|
98
|
+
user.id,
|
|
99
|
+
additional_properties={
|
|
100
|
+
"endpoint": "POST /v1/search",
|
|
101
|
+
"search_type": str(payload.search_type),
|
|
102
|
+
"datasets": payload.datasets,
|
|
103
|
+
"dataset_ids": [str(dataset_id) for dataset_id in payload.dataset_ids or []],
|
|
104
|
+
"query": payload.query,
|
|
105
|
+
"top_k": payload.top_k,
|
|
106
|
+
},
|
|
107
|
+
)
|
|
108
|
+
|
|
86
109
|
from cognee.api.v1.search import search as cognee_search
|
|
87
110
|
|
|
88
111
|
try:
|
|
@@ -7,6 +7,7 @@ from cognee.modules.data.methods import get_authorized_existing_datasets
|
|
|
7
7
|
from cognee.modules.users.models import User
|
|
8
8
|
|
|
9
9
|
from cognee.context_global_variables import set_database_global_context_variables
|
|
10
|
+
from cognee.shared.utils import send_telemetry
|
|
10
11
|
|
|
11
12
|
logger = get_logger()
|
|
12
13
|
|
|
@@ -39,6 +40,15 @@ def get_visualize_router() -> APIRouter:
|
|
|
39
40
|
- User must have read permissions on the dataset
|
|
40
41
|
- Visualization is interactive and allows graph exploration
|
|
41
42
|
"""
|
|
43
|
+
send_telemetry(
|
|
44
|
+
"Visualize API Endpoint Invoked",
|
|
45
|
+
user.id,
|
|
46
|
+
additional_properties={
|
|
47
|
+
"endpoint": "GET /v1/visualize",
|
|
48
|
+
"dataset_id": str(dataset_id),
|
|
49
|
+
},
|
|
50
|
+
)
|
|
51
|
+
|
|
42
52
|
from cognee.api.v1.visualize import visualize_graph
|
|
43
53
|
|
|
44
54
|
try:
|
cognee/base_config.py
CHANGED
|
@@ -10,8 +10,6 @@ class BaseConfig(BaseSettings):
|
|
|
10
10
|
data_root_directory: str = get_absolute_path(".data_storage")
|
|
11
11
|
system_root_directory: str = get_absolute_path(".cognee_system")
|
|
12
12
|
monitoring_tool: object = Observer.LANGFUSE
|
|
13
|
-
graphistry_username: Optional[str] = os.getenv("GRAPHISTRY_USERNAME")
|
|
14
|
-
graphistry_password: Optional[str] = os.getenv("GRAPHISTRY_PASSWORD")
|
|
15
13
|
langfuse_public_key: Optional[str] = os.getenv("LANGFUSE_PUBLIC_KEY")
|
|
16
14
|
langfuse_secret_key: Optional[str] = os.getenv("LANGFUSE_SECRET_KEY")
|
|
17
15
|
langfuse_host: Optional[str] = os.getenv("LANGFUSE_HOST")
|
|
@@ -72,11 +72,36 @@ class KuzuAdapter(GraphDBInterface):
|
|
|
72
72
|
|
|
73
73
|
run_sync(file_storage.ensure_directory_exists())
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
self.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
try:
|
|
76
|
+
self.db = Database(
|
|
77
|
+
self.db_path,
|
|
78
|
+
buffer_pool_size=2048 * 1024 * 1024, # 2048MB buffer pool
|
|
79
|
+
max_db_size=4096 * 1024 * 1024,
|
|
80
|
+
)
|
|
81
|
+
except RuntimeError:
|
|
82
|
+
from .kuzu_migrate import read_kuzu_storage_version
|
|
83
|
+
import kuzu
|
|
84
|
+
|
|
85
|
+
kuzu_db_version = read_kuzu_storage_version(self.db_path)
|
|
86
|
+
if (
|
|
87
|
+
kuzu_db_version == "0.9.0" or kuzu_db_version == "0.8.2"
|
|
88
|
+
) and kuzu_db_version != kuzu.__version__:
|
|
89
|
+
# Try to migrate kuzu database to latest version
|
|
90
|
+
from .kuzu_migrate import kuzu_migration
|
|
91
|
+
|
|
92
|
+
kuzu_migration(
|
|
93
|
+
new_db=self.db_path + "_new",
|
|
94
|
+
old_db=self.db_path,
|
|
95
|
+
new_version=kuzu.__version__,
|
|
96
|
+
old_version=kuzu_db_version,
|
|
97
|
+
overwrite=True,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
self.db = Database(
|
|
101
|
+
self.db_path,
|
|
102
|
+
buffer_pool_size=2048 * 1024 * 1024, # 2048MB buffer pool
|
|
103
|
+
max_db_size=4096 * 1024 * 1024,
|
|
104
|
+
)
|
|
80
105
|
|
|
81
106
|
self.db.init_database()
|
|
82
107
|
self.connection = Connection(self.db)
|
|
@@ -1438,11 +1463,8 @@ class KuzuAdapter(GraphDBInterface):
|
|
|
1438
1463
|
It raises exceptions for failures occurring during deletion processes.
|
|
1439
1464
|
"""
|
|
1440
1465
|
try:
|
|
1441
|
-
# Use DETACH DELETE to remove both nodes and their relationships in one operation
|
|
1442
|
-
await self.query("MATCH (n:Node) DETACH DELETE n")
|
|
1443
|
-
logger.info("Cleared all data from graph while preserving structure")
|
|
1444
|
-
|
|
1445
1466
|
if self.connection:
|
|
1467
|
+
self.connection.close()
|
|
1446
1468
|
self.connection = None
|
|
1447
1469
|
if self.db:
|
|
1448
1470
|
self.db.close()
|