cognee/cognee.ipynb
2024-03-13 17:28:52 +01:00

118 lines
3.3 KiB
Text

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "c4d5a399",
"metadata": {},
"outputs": [],
"source": [
"from os import listdir, path\n",
"from uuid import uuid5, UUID\n",
"from cognee import add\n",
"\n",
"data_path = path.abspath(\".data\")\n",
"\n",
"results = await add(data_path, \"izmene\")\n",
"for result in results:\n",
" print(result)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "47edce91",
"metadata": {},
"outputs": [],
"source": [
"import duckdb\n",
"from cognee.root_dir import get_absolute_path\n",
"\n",
"dataset_name = \"pdf_files\"\n",
"\n",
"db_path = get_absolute_path(\"./data/cognee\")\n",
"db_location = db_path + \"/cognee.duckdb\"\n",
"print(db_location)\n",
"\n",
"db = duckdb.connect(db_location)\n",
"\n",
"tables = db.sql(\"SELECT DISTINCT schema_name FROM duckdb_tables();\").df()\n",
"print(list(filter(lambda table_name: table_name.endswith('staging') is False, tables.to_dict()[\"schema_name\"].values())))\n",
"\n",
"# izmene = db.sql(f\"SELECT * FROM izmene.file_metadata;\")\n",
"\n",
"# print(izmene)\n",
"\n",
"# pravilnik = db.sql(f\"SELECT * FROM pravilnik.file_metadata;\")\n",
"\n",
"# print(pravilnik)\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "607bf624",
"metadata": {},
"outputs": [],
"source": [
"from os import path, listdir\n",
"from cognee import cognify, list_datasets\n",
"from cognee.utils import render_graph\n",
"\n",
"print(list_datasets())\n",
"\n",
"graph = await cognify(\"izmene\")\n",
"\n",
"graph_url = await render_graph(graph, graph_type = \"networkx\")\n",
"print(graph_url)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6edb9cac",
"metadata": {},
"outputs": [],
"source": [
"from cognee.infrastructure.databases.graph.get_graph_client import get_graph_client\n",
"from cognee.shared.data_models import GraphDBType\n",
"from cognee import search, SearchType\n",
"\n",
"graph_client = get_graph_client(GraphDBType.NETWORKX)\n",
"await graph_client.load_graph_from_file()\n",
"\n",
"graph = graph_client.graph\n",
"\n",
"query_params = {\n",
" SearchType.SIMILARITY: {'query': 'nacin vrsenja kontrole tehnicke dokumentacije'}\n",
"}\n",
"\n",
"results = await search(graph, query_params)\n",
"print(results)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}