From ae6b2d196eecbef60916e6e7cd8b8c54e9d07b57 Mon Sep 17 00:00:00 2001 From: Milenko Gavric Date: Thu, 15 Jan 2026 15:25:26 +0100 Subject: [PATCH 1/7] add codes from guides to a separate folder --- guides/custom_data_models.py | 38 ++++++++++++++++++ guides/custom_prompts.py | 30 ++++++++++++++ guides/custom_tasks_and_pipelines.py | 53 +++++++++++++++++++++++++ guides/graph_visualization.py | 13 +++++++ guides/low_level_llm.py | 31 +++++++++++++++ guides/memify_quickstart.py | 29 ++++++++++++++ guides/ontology_quickstart.py | 30 ++++++++++++++ guides/s3_storage.py | 25 ++++++++++++ guides/search_basics.py | 58 ++++++++++++++++++++++++++++ guides/sessions.py | 46 ++++++++++++++++++++++ guides/temporal_cognify.py | 57 +++++++++++++++++++++++++++ 11 files changed, 410 insertions(+) create mode 100644 guides/custom_data_models.py create mode 100644 guides/custom_prompts.py create mode 100644 guides/custom_tasks_and_pipelines.py create mode 100644 guides/graph_visualization.py create mode 100644 guides/low_level_llm.py create mode 100644 guides/memify_quickstart.py create mode 100644 guides/ontology_quickstart.py create mode 100644 guides/s3_storage.py create mode 100644 guides/search_basics.py create mode 100644 guides/sessions.py create mode 100644 guides/temporal_cognify.py diff --git a/guides/custom_data_models.py b/guides/custom_data_models.py new file mode 100644 index 000000000..0eb314227 --- /dev/null +++ b/guides/custom_data_models.py @@ -0,0 +1,38 @@ +import asyncio +from typing import Any +from pydantic import SkipValidation + +import cognee +from cognee.infrastructure.engine import DataPoint +from cognee.infrastructure.engine.models.Edge import Edge +from cognee.tasks.storage import add_data_points + + +class Person(DataPoint): + name: str + # Keep it simple for forward refs / mixed values + knows: SkipValidation[Any] = None # single Person or list[Person] + # Recommended: specify which fields to index for search + metadata: dict = {"index_fields": ["name"]} + + +async def main(): + # Start clean (optional in your app) + await cognee.prune.prune_data() + await cognee.prune.prune_system(metadata=True) + + alice = Person(name="Alice") + bob = Person(name="Bob") + charlie = Person(name="Charlie") + + # Create relationships - field name becomes edge label + alice.knows = bob + # You can also do lists: alice.knows = [bob, charlie] + + # Optional: add weights and custom relationship types + bob.knows = (Edge(weight=0.9, relationship_type="friend_of"), charlie) + + await add_data_points([alice, bob, charlie]) + + +asyncio.run(main()) diff --git a/guides/custom_prompts.py b/guides/custom_prompts.py new file mode 100644 index 000000000..0d0a55a80 --- /dev/null +++ b/guides/custom_prompts.py @@ -0,0 +1,30 @@ +import asyncio +import cognee +from cognee.api.v1.search import SearchType + +custom_prompt = """ +Extract only people and cities as entities. +Connect people to cities with the relationship "lives_in". +Ignore all other entities. +""" + + +async def main(): + await cognee.add( + [ + "Alice moved to Paris in 2010, while Bob has always lived in New York.", + "Andreas was born in Venice, but later settled in Lisbon.", + "Diana and Tom were born and raised in Helsingy. Diana currently resides in Berlin, while Tom never moved.", + ] + ) + await cognee.cognify(custom_prompt=custom_prompt) + + res = await cognee.search( + query_type=SearchType.GRAPH_COMPLETION, + query_text="Where does Alice live?", + ) + print(res) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/guides/custom_tasks_and_pipelines.py b/guides/custom_tasks_and_pipelines.py new file mode 100644 index 000000000..202bb128a --- /dev/null +++ b/guides/custom_tasks_and_pipelines.py @@ -0,0 +1,53 @@ +import asyncio +from typing import Any, Dict, List +from pydantic import BaseModel, SkipValidation + +import cognee +from cognee.modules.engine.operations.setup import setup +from cognee.infrastructure.llm.LLMGateway import LLMGateway +from cognee.infrastructure.engine import DataPoint +from cognee.tasks.storage import add_data_points +from cognee.modules.pipelines import Task, run_pipeline + + +class Person(DataPoint): + name: str + # Optional relationships (we'll let the LLM populate this) + knows: List["Person"] = [] + # Make names searchable in the vector store + metadata: Dict[str, Any] = {"index_fields": ["name"]} + + +class People(BaseModel): + persons: List[Person] + + +async def extract_people(text: str) -> List[Person]: + system_prompt = ( + "Extract people mentioned in the text. " + "Return as `persons: Person[]` with each Person having `name` and optional `knows` relations. " + "If the text says someone knows someone set `knows` accordingly. " + "Only include facts explicitly stated." + ) + people = await LLMGateway.acreate_structured_output(text, system_prompt, People) + return people.persons + + +async def main(): + await cognee.prune.prune_data() + await cognee.prune.prune_system(metadata=True) + await setup() + + text = "Alice knows Bob." + + tasks = [ + Task(extract_people), # input: text -> output: list[Person] + Task(add_data_points), # input: list[Person] -> output: list[Person] + ] + + async for _ in run_pipeline(tasks=tasks, data=text, datasets=["people_demo"]): + pass + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/guides/graph_visualization.py b/guides/graph_visualization.py new file mode 100644 index 000000000..d463cbb56 --- /dev/null +++ b/guides/graph_visualization.py @@ -0,0 +1,13 @@ +import asyncio +import cognee +from cognee.api.v1.visualize.visualize import visualize_graph + + +async def main(): + await cognee.add(["Alice knows Bob.", "NLP is a subfield of CS."]) + await cognee.cognify() + + await visualize_graph("./graph_after_cognify.html") + + +asyncio.run(main()) diff --git a/guides/low_level_llm.py b/guides/low_level_llm.py new file mode 100644 index 000000000..454f53f44 --- /dev/null +++ b/guides/low_level_llm.py @@ -0,0 +1,31 @@ +import asyncio + +from pydantic import BaseModel +from typing import List +from cognee.infrastructure.llm.LLMGateway import LLMGateway + + +class MiniEntity(BaseModel): + name: str + type: str + + +class MiniGraph(BaseModel): + nodes: List[MiniEntity] + + +async def main(): + system_prompt = ( + "Extract entities as nodes with name and type. " + "Use concise, literal values present in the text." + ) + + text = "Apple develops iPhone; Audi produces the R8." + + result = await LLMGateway.acreate_structured_output(text, system_prompt, MiniGraph) + print(result) + # MiniGraph(nodes=[MiniEntity(name='Apple', type='Organization'), ...]) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/guides/memify_quickstart.py b/guides/memify_quickstart.py new file mode 100644 index 000000000..040654350 --- /dev/null +++ b/guides/memify_quickstart.py @@ -0,0 +1,29 @@ +import asyncio +import cognee +from cognee import SearchType + + +async def main(): + # 1) Add two short chats and build a graph + await cognee.add( + [ + "We follow PEP8. Add type hints and docstrings.", + "Releases should not be on Friday. Susan must review PRs.", + ], + dataset_name="rules_demo", + ) + await cognee.cognify(datasets=["rules_demo"]) # builds graph + + # 2) Enrich the graph (uses default memify tasks) + await cognee.memify(dataset="rules_demo") + + # 3) Query the new coding rules + rules = await cognee.search( + query_type=SearchType.CODING_RULES, + query_text="List coding rules", + node_name=["coding_agent_rules"], + ) + print("Rules:", rules) + + +asyncio.run(main()) diff --git a/guides/ontology_quickstart.py b/guides/ontology_quickstart.py new file mode 100644 index 000000000..2784dab19 --- /dev/null +++ b/guides/ontology_quickstart.py @@ -0,0 +1,30 @@ +import asyncio +import cognee + + +async def main(): + texts = ["Audi produces the R8 and e-tron.", "Apple develops iPhone and MacBook."] + + await cognee.add(texts) + # or: await cognee.add("/path/to/folder/of/files") + + import os + from cognee.modules.ontology.ontology_config import Config + from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver + + ontology_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "ontology_input_example/basic_ontology.owl" + ) + + # Create full config structure manually + config: Config = { + "ontology_config": { + "ontology_resolver": RDFLibOntologyResolver(ontology_file=ontology_path) + } + } + + await cognee.cognify(config=config) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/guides/s3_storage.py b/guides/s3_storage.py new file mode 100644 index 000000000..e64859db7 --- /dev/null +++ b/guides/s3_storage.py @@ -0,0 +1,25 @@ +import asyncio +import cognee + + +async def main(): + # Single file + await cognee.add("s3://cognee-s3-small-test/Natural_language_processing.txt") + + # Folder/prefix (recursively expands) + await cognee.add("s3://cognee-s3-small-test") + + # Mixed list + await cognee.add( + [ + "s3://cognee-s3-small-test/Natural_language_processing.txt", + "Some inline text to ingest", + ] + ) + + # Process the data + await cognee.cognify() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/guides/search_basics.py b/guides/search_basics.py new file mode 100644 index 000000000..f1847ad4b --- /dev/null +++ b/guides/search_basics.py @@ -0,0 +1,58 @@ +import asyncio +import cognee + +from cognee.modules.search.types import SearchType, CombinedSearchResult + + +async def main(): + await cognee.prune.prune_data() + await cognee.prune.prune_system(metadata=True) + + text = """ + Natural language processing (NLP) is an interdisciplinary + subfield of computer science and information retrieval. + First rule of coding: Do not talk about coding. + """ + + text2 = """ + Sandwiches are best served toasted with cheese, ham, mayo, + lettuce, mustard, and salt & pepper. + """ + + await cognee.add(text, dataset_name="NLP_coding") + await cognee.add(text2, dataset_name="Sandwiches") + await cognee.add(text2) + + await cognee.cognify() + + # Make sure you've already run cognee.cognify(...) so the graph has content + answers = await cognee.search(query_text="What are the main themes in my data?") + assert len(answers) > 0 + + answers = await cognee.search( + query_text="List coding guidelines", + query_type=SearchType.CODING_RULES, + ) + assert len(answers) > 0 + + answers = await cognee.search( + query_text="Give me a confident answer: What is NLP?", + system_prompt="Answer succinctly and state confidence at the end.", + ) + assert len(answers) > 0 + + answers = await cognee.search( + query_text="Tell me about NLP", + only_context=True, + ) + assert len(answers) > 0 + + answers = await cognee.search( + query_text="Quarterly financial highlights", + datasets=["NLP_coding", "Sandwiches"], + use_combined_context=True, + ) + assert isinstance(answers, CombinedSearchResult) + + +asyncio.run(main()) diff --git a/guides/sessions.py b/guides/sessions.py new file mode 100644 index 000000000..e3f30dd92 --- /dev/null +++ b/guides/sessions.py @@ -0,0 +1,46 @@ +import asyncio +import cognee +from cognee import SearchType +from cognee.modules.users.methods import get_default_user +from cognee.context_global_variables import set_session_user_context_variable + +async def main(): + # Prepare knowledge base + await cognee.add([ + "Alice moved to Paris in 2010. She works as a software engineer.", + "Bob lives in New York. He is a data scientist.", + "Alice and Bob met at a conference in 2015." + ]) + await cognee.cognify() + + # Set user context (required for sessions) + user = await get_default_user() + await set_session_user_context_variable(user) + + # First search - starts a new session + result1 = await cognee.search( + query_type=SearchType.GRAPH_COMPLETION, + query_text="Where does Alice live?", + session_id="conversation_1" + ) + print("First answer:", result1[0]) + + # Follow-up search - uses conversation history + result2 = await cognee.search( + query_type=SearchType.GRAPH_COMPLETION, + query_text="What does she do for work?", + session_id="conversation_1" # Same session + ) + print("Follow-up answer:", result2[0]) + # The LLM knows "she" refers to Alice from previous context + + # Different session - no memory of previous conversation + result3 = await cognee.search( + query_type=SearchType.GRAPH_COMPLETION, + query_text="What does she do for work?", + session_id="conversation_2" # New session + ) + print("New session answer:", result3[0]) + # This won't know who "she" refers to + +asyncio.run(main()) diff --git a/guides/temporal_cognify.py b/guides/temporal_cognify.py new file mode 100644 index 000000000..34c1ee33c --- /dev/null +++ b/guides/temporal_cognify.py @@ -0,0 +1,57 @@ +import asyncio +import cognee + + +async def main(): + text = """ + In 1998 the project launched. In 2001 version 1.0 shipped. In 2004 the team merged + with another group. In 2010 support for v1 ended. + """ + + await cognee.add(text, dataset_name="timeline_demo") + + await cognee.cognify(datasets=["timeline_demo"], temporal_cognify=True) + + from cognee.api.v1.search import SearchType + + # Before / after queries + result = await cognee.search( + query_type=SearchType.TEMPORAL, query_text="What happened before 2000?", top_k=10 + ) + + assert result != [] + + result = await cognee.search( + query_type=SearchType.TEMPORAL, query_text="What happened after 2010?", top_k=10 + ) + + assert result != [] + + # Between queries + result = await cognee.search( + query_type=SearchType.TEMPORAL, query_text="Events between 2001 and 2004", top_k=10 + ) + + assert result != [] + + # Scoped descriptions + result = await cognee.search( + query_type=SearchType.TEMPORAL, + query_text="Key project milestones between 1998 and 2010", + top_k=10, + ) + + assert result != [] + + result = await cognee.search( + query_type=SearchType.TEMPORAL, + query_text="What happened after 2004?", + datasets=["timeline_demo"], + top_k=10, + ) + + assert result != [] + + +if __name__ == "__main__": + asyncio.run(main()) From 4ae64f05a3df493b2cf34208ac62248237d1ed6a Mon Sep 17 00:00:00 2001 From: Milenko Gavric Date: Thu, 15 Jan 2026 16:00:32 +0100 Subject: [PATCH 2/7] delete sessions since it needs to be improved --- guides/sessions.py | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 guides/sessions.py diff --git a/guides/sessions.py b/guides/sessions.py deleted file mode 100644 index e3f30dd92..000000000 --- a/guides/sessions.py +++ /dev/null @@ -1,46 +0,0 @@ -import asyncio -import cognee -from cognee import SearchType -from cognee.modules.users.methods import get_default_user -from cognee.context_global_variables import set_session_user_context_variable - -async def main(): - # Prepare knowledge base - await cognee.add([ - "Alice moved to Paris in 2010. She works as a software engineer.", - "Bob lives in New York. He is a data scientist.", - "Alice and Bob met at a conference in 2015." - ]) - await cognee.cognify() - - # Set user context (required for sessions) - user = await get_default_user() - await set_session_user_context_variable(user) - - # First search - starts a new session - result1 = await cognee.search( - query_type=SearchType.GRAPH_COMPLETION, - query_text="Where does Alice live?", - session_id="conversation_1" - ) - print("First answer:", result1[0]) - - # Follow-up search - uses conversation history - result2 = await cognee.search( - query_type=SearchType.GRAPH_COMPLETION, - query_text="What does she do for work?", - session_id="conversation_1" # Same session - ) - print("Follow-up answer:", result2[0]) - # The LLM knows "she" refers to Alice from previous context - - # Different session - no memory of previous conversation - result3 = await cognee.search( - query_type=SearchType.GRAPH_COMPLETION, - query_text="What does she do for work?", - session_id="conversation_2" # New session - ) - print("New session answer:", result3[0]) - # This won't know who "she" refers to - -asyncio.run(main()) From 8761eab0c0b627a8598cf4f3909dc30fe0d4fdbd Mon Sep 17 00:00:00 2001 From: Milenko Gavric Date: Thu, 15 Jan 2026 16:20:48 +0100 Subject: [PATCH 3/7] move guides to examples --- {guides => examples/guides}/custom_data_models.py | 0 {guides => examples/guides}/custom_prompts.py | 0 {guides => examples/guides}/custom_tasks_and_pipelines.py | 0 {guides => examples/guides}/graph_visualization.py | 0 {guides => examples/guides}/low_level_llm.py | 0 {guides => examples/guides}/memify_quickstart.py | 0 {guides => examples/guides}/ontology_quickstart.py | 0 {guides => examples/guides}/s3_storage.py | 0 {guides => examples/guides}/search_basics.py | 0 {guides => examples/guides}/temporal_cognify.py | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename {guides => examples/guides}/custom_data_models.py (100%) rename {guides => examples/guides}/custom_prompts.py (100%) rename {guides => examples/guides}/custom_tasks_and_pipelines.py (100%) rename {guides => examples/guides}/graph_visualization.py (100%) rename {guides => examples/guides}/low_level_llm.py (100%) rename {guides => examples/guides}/memify_quickstart.py (100%) rename {guides => examples/guides}/ontology_quickstart.py (100%) rename {guides => examples/guides}/s3_storage.py (100%) rename {guides => examples/guides}/search_basics.py (100%) rename {guides => examples/guides}/temporal_cognify.py (100%) diff --git a/guides/custom_data_models.py b/examples/guides/custom_data_models.py similarity index 100% rename from guides/custom_data_models.py rename to examples/guides/custom_data_models.py diff --git a/guides/custom_prompts.py b/examples/guides/custom_prompts.py similarity index 100% rename from guides/custom_prompts.py rename to examples/guides/custom_prompts.py diff --git a/guides/custom_tasks_and_pipelines.py b/examples/guides/custom_tasks_and_pipelines.py similarity index 100% rename from guides/custom_tasks_and_pipelines.py rename to examples/guides/custom_tasks_and_pipelines.py diff --git a/guides/graph_visualization.py b/examples/guides/graph_visualization.py similarity index 100% rename from guides/graph_visualization.py rename to examples/guides/graph_visualization.py diff --git a/guides/low_level_llm.py b/examples/guides/low_level_llm.py similarity index 100% rename from guides/low_level_llm.py rename to examples/guides/low_level_llm.py diff --git a/guides/memify_quickstart.py b/examples/guides/memify_quickstart.py similarity index 100% rename from guides/memify_quickstart.py rename to examples/guides/memify_quickstart.py diff --git a/guides/ontology_quickstart.py b/examples/guides/ontology_quickstart.py similarity index 100% rename from guides/ontology_quickstart.py rename to examples/guides/ontology_quickstart.py diff --git a/guides/s3_storage.py b/examples/guides/s3_storage.py similarity index 100% rename from guides/s3_storage.py rename to examples/guides/s3_storage.py diff --git a/guides/search_basics.py b/examples/guides/search_basics.py similarity index 100% rename from guides/search_basics.py rename to examples/guides/search_basics.py diff --git a/guides/temporal_cognify.py b/examples/guides/temporal_cognify.py similarity index 100% rename from guides/temporal_cognify.py rename to examples/guides/temporal_cognify.py From be829dcc3f89bb17ac2729c38b59f83768864853 Mon Sep 17 00:00:00 2001 From: Milenko Gavric Date: Fri, 16 Jan 2026 12:54:17 +0100 Subject: [PATCH 4/7] created search_basics_core example and renamed search_basics to search_basics_additional --- ..._basics.py => search_basics_additional.py} | 0 examples/guides/search_basics_core.py | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+) rename examples/guides/{search_basics.py => search_basics_additional.py} (100%) create mode 100644 examples/guides/search_basics_core.py diff --git a/examples/guides/search_basics.py b/examples/guides/search_basics_additional.py similarity index 100% rename from examples/guides/search_basics.py rename to examples/guides/search_basics_additional.py diff --git a/examples/guides/search_basics_core.py b/examples/guides/search_basics_core.py new file mode 100644 index 000000000..661f2ab73 --- /dev/null +++ b/examples/guides/search_basics_core.py @@ -0,0 +1,24 @@ + import asyncio + import cognee + + async def main(): + # Start clean (optional in your app) + await cognee.prune.prune_data() + await cognee.prune.prune_system(metadata=True) + # Prepare knowledge base + await cognee.add([ + "Alice moved to Paris in 2010. She works as a software engineer.", + "Bob lives in New York. He is a data scientist.", + "Alice and Bob met at a conference in 2015." + ]) + + await cognee.cognify() + + # Make sure you've already run cognee.cognify(...) so the graph has content + answers = await cognee.search( + query_text="What are the main themes in my data?" + ) + for answer in answers: + print(answer) + + asyncio.run(main()) From 6ab127c85d1171876950265b747d71b28230ce70 Mon Sep 17 00:00:00 2001 From: Milenko Gavric Date: Fri, 16 Jan 2026 13:11:46 +0100 Subject: [PATCH 5/7] fixed indentation in search_basics_core --- examples/guides/search_basics_core.py | 40 +++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/guides/search_basics_core.py b/examples/guides/search_basics_core.py index 661f2ab73..af1f914e8 100644 --- a/examples/guides/search_basics_core.py +++ b/examples/guides/search_basics_core.py @@ -1,24 +1,24 @@ - import asyncio - import cognee +import asyncio +import cognee - async def main(): - # Start clean (optional in your app) - await cognee.prune.prune_data() - await cognee.prune.prune_system(metadata=True) - # Prepare knowledge base - await cognee.add([ - "Alice moved to Paris in 2010. She works as a software engineer.", - "Bob lives in New York. He is a data scientist.", - "Alice and Bob met at a conference in 2015." - ]) +async def main(): + # Start clean (optional in your app) + await cognee.prune.prune_data() + await cognee.prune.prune_system(metadata=True) + # Prepare knowledge base + await cognee.add([ + "Alice moved to Paris in 2010. She works as a software engineer.", + "Bob lives in New York. He is a data scientist.", + "Alice and Bob met at a conference in 2015." + ]) - await cognee.cognify() + await cognee.cognify() - # Make sure you've already run cognee.cognify(...) so the graph has content - answers = await cognee.search( - query_text="What are the main themes in my data?" - ) - for answer in answers: - print(answer) + # Make sure you've already run cognee.cognify(...) so the graph has content + answers = await cognee.search( + query_text="What are the main themes in my data?" + ) + for answer in answers: + print(answer) - asyncio.run(main()) +asyncio.run(main()) From 7ae44a456504be6e9f86797fd72cbbbc5db68d62 Mon Sep 17 00:00:00 2001 From: Milenko Gavric Date: Fri, 16 Jan 2026 15:03:03 +0100 Subject: [PATCH 6/7] fix formatting in search_basics_core guide example --- examples/guides/search_basics_core.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/guides/search_basics_core.py b/examples/guides/search_basics_core.py index af1f914e8..15c073c0e 100644 --- a/examples/guides/search_basics_core.py +++ b/examples/guides/search_basics_core.py @@ -1,24 +1,26 @@ import asyncio import cognee + async def main(): # Start clean (optional in your app) await cognee.prune.prune_data() await cognee.prune.prune_system(metadata=True) # Prepare knowledge base - await cognee.add([ - "Alice moved to Paris in 2010. She works as a software engineer.", - "Bob lives in New York. He is a data scientist.", - "Alice and Bob met at a conference in 2015." - ]) + await cognee.add( + [ + "Alice moved to Paris in 2010. She works as a software engineer.", + "Bob lives in New York. He is a data scientist.", + "Alice and Bob met at a conference in 2015.", + ] + ) await cognee.cognify() # Make sure you've already run cognee.cognify(...) so the graph has content - answers = await cognee.search( - query_text="What are the main themes in my data?" - ) + answers = await cognee.search(query_text="What are the main themes in my data?") for answer in answers: print(answer) + asyncio.run(main()) From 8d238f1da34920a6017231e5b8000409f0885a25 Mon Sep 17 00:00:00 2001 From: Milenko Gavric Date: Tue, 20 Jan 2026 14:48:28 +0100 Subject: [PATCH 7/7] apply coderabbitai's fixes --- examples/guides/custom_data_models.py | 3 +- examples/guides/custom_prompts.py | 2 +- examples/guides/graph_visualization.py | 3 +- examples/guides/memify_quickstart.py | 5 +- .../ontology_input_example/basic_ontology.owl | 290 ++++++++++++++++++ examples/guides/ontology_quickstart.py | 7 +- examples/guides/search_basics_additional.py | 12 +- examples/guides/search_basics_core.py | 3 +- 8 files changed, 306 insertions(+), 19 deletions(-) create mode 100644 examples/guides/ontology_input_example/basic_ontology.owl diff --git a/examples/guides/custom_data_models.py b/examples/guides/custom_data_models.py index 0eb314227..be7a588b3 100644 --- a/examples/guides/custom_data_models.py +++ b/examples/guides/custom_data_models.py @@ -35,4 +35,5 @@ async def main(): await add_data_points([alice, bob, charlie]) -asyncio.run(main()) +if __name__ == "__main__": + asyncio.run(main()) diff --git a/examples/guides/custom_prompts.py b/examples/guides/custom_prompts.py index 0d0a55a80..64e9c59c0 100644 --- a/examples/guides/custom_prompts.py +++ b/examples/guides/custom_prompts.py @@ -14,7 +14,7 @@ async def main(): [ "Alice moved to Paris in 2010, while Bob has always lived in New York.", "Andreas was born in Venice, but later settled in Lisbon.", - "Diana and Tom were born and raised in Helsingy. Diana currently resides in Berlin, while Tom never moved.", + "Diana and Tom were born and raised in Helsinki. Diana currently resides in Berlin, while Tom never moved.", ] ) await cognee.cognify(custom_prompt=custom_prompt) diff --git a/examples/guides/graph_visualization.py b/examples/guides/graph_visualization.py index d463cbb56..3ee980081 100644 --- a/examples/guides/graph_visualization.py +++ b/examples/guides/graph_visualization.py @@ -10,4 +10,5 @@ async def main(): await visualize_graph("./graph_after_cognify.html") -asyncio.run(main()) +if __name__ == "__main__": + asyncio.run(main()) diff --git a/examples/guides/memify_quickstart.py b/examples/guides/memify_quickstart.py index 040654350..61fdf6991 100644 --- a/examples/guides/memify_quickstart.py +++ b/examples/guides/memify_quickstart.py @@ -1,6 +1,6 @@ import asyncio import cognee -from cognee import SearchType +from cognee.modules.search.types import SearchType async def main(): @@ -26,4 +26,5 @@ async def main(): print("Rules:", rules) -asyncio.run(main()) +if __name__ == "__main__": + asyncio.run(main()) diff --git a/examples/guides/ontology_input_example/basic_ontology.owl b/examples/guides/ontology_input_example/basic_ontology.owl new file mode 100644 index 000000000..81c4182d4 --- /dev/null +++ b/examples/guides/ontology_input_example/basic_ontology.owl @@ -0,0 +1,290 @@ + + + + Created for making cars accessible to everyone. + + + + + + + + + + + + + + + + + Famous for high-performance sports cars. + + + + + + + + + Pioneering social media and virtual reality technology. + + + + + + + + Known for its innovative consumer electronics and software. + + + + + + + + + + + + Known for its modern designs and technology. + + + + + + + + + + + + + + + + Focused on performance and driving pleasure. + + + + + + + + + + + + + + + + + + + + + Started as a search engine and expanded into cloud computing and AI. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Dominant in software, cloud computing, and gaming. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Synonymous with luxury and quality. + + + + + + + + + + + From e-commerce to cloud computing giant with AWS. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/guides/ontology_quickstart.py b/examples/guides/ontology_quickstart.py index 2784dab19..e3b58d5d6 100644 --- a/examples/guides/ontology_quickstart.py +++ b/examples/guides/ontology_quickstart.py @@ -1,5 +1,8 @@ import asyncio import cognee +import os +from cognee.modules.ontology.ontology_config import Config +from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver async def main(): @@ -8,10 +11,6 @@ async def main(): await cognee.add(texts) # or: await cognee.add("/path/to/folder/of/files") - import os - from cognee.modules.ontology.ontology_config import Config - from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver - ontology_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), "ontology_input_example/basic_ontology.owl" ) diff --git a/examples/guides/search_basics_additional.py b/examples/guides/search_basics_additional.py index f1847ad4b..f98dd8db9 100644 --- a/examples/guides/search_basics_additional.py +++ b/examples/guides/search_basics_additional.py @@ -1,7 +1,7 @@ import asyncio import cognee -from cognee.modules.search.types import SearchType, CombinedSearchResult +from cognee.api.v1.search import SearchType async def main(): @@ -47,12 +47,6 @@ async def main(): ) assert len(answers) > 0 - answers = await cognee.search( - query_text="Quarterly financial highlights", - datasets=["NLP_coding", "Sandwiches"], - use_combined_context=True, - ) - assert isinstance(answers, CombinedSearchResult) - -asyncio.run(main()) +if __name__ == "__main__": + asyncio.run(main()) diff --git a/examples/guides/search_basics_core.py b/examples/guides/search_basics_core.py index 15c073c0e..15e2b5670 100644 --- a/examples/guides/search_basics_core.py +++ b/examples/guides/search_basics_core.py @@ -23,4 +23,5 @@ async def main(): print(answer) -asyncio.run(main()) +if __name__ == "__main__": + asyncio.run(main())