forked from topoteretes/cognee
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisambiguate_entities_example.py
More file actions
60 lines (48 loc) · 1.57 KB
/
Copy pathdisambiguate_entities_example.py
File metadata and controls
60 lines (48 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import asyncio
import os
from pathlib import Path
from typing import Optional
from disambiguate_entities import disambiguate_entities_pipeline
import cognee
from cognee import visualize_graph
async def main(
example, use_poc, vector_search_limit: Optional[int] = None, custom_prompt: Optional[str] = None
):
await cognee.prune.prune_data()
await cognee.prune.prune_system(metadata=True)
graph_visualization_path = os.path.join(
os.path.dirname(__file__),
f"results/{'poc_' if use_poc else ''}cognify_disambiguate_{example}_result.html",
)
with open(
os.path.join(Path(__file__).resolve().parent, "data/" + example + ".txt"),
"r",
encoding="utf-8",
) as f:
text = f.read()
text = text.split("\n")
for line in text:
await cognee.add(line)
if use_poc:
kwargs = {"vector_search_limit": vector_search_limit}
await disambiguate_entities_pipeline(custom_prompt=custom_prompt, **kwargs)
else:
await cognee.cognify()
await visualize_graph(graph_visualization_path)
async def _run():
with open("prompts/prompt1.txt", "r") as f:
custom_prompt_text = f.read()
for i in range(1, 5):
example_id = str(i)
await main(
example="example" + example_id,
use_poc=True,
vector_search_limit=5,
custom_prompt=custom_prompt_text,
)
await main(
example="example" + example_id,
use_poc=False,
)
if __name__ == "__main__":
asyncio.run(_run())