refactor: Update examples to use pprint

This commit is contained in:
Igor Ilic 2025-12-18 14:17:24 +01:00
parent b5949580de
commit cc41ef853c
9 changed files with 33 additions and 20 deletions

View file

@ -1,8 +1,9 @@
import asyncio import asyncio
import cognee import cognee
import os import os
from pprint import pprint
# By default cognee uses OpenAI's gpt-5-mini LLM model # By default cognee uses OpenAI's gpt-5-mini LLM model
# Provide your OpenAI LLM API KEY # Provide your OpenAI LLM API KEY
os.environ["LLM_API_KEY"] = "" os.environ["LLM_API_KEY"] = ""
@ -24,13 +25,13 @@ async def cognee_demo():
# Query Cognee for information from provided document # Query Cognee for information from provided document
answer = await cognee.search("List me all the important characters in Alice in Wonderland.") answer = await cognee.search("List me all the important characters in Alice in Wonderland.")
print(answer) pprint(answer)
answer = await cognee.search("How did Alice end up in Wonderland?") answer = await cognee.search("How did Alice end up in Wonderland?")
print(answer) pprint(answer)
answer = await cognee.search("Tell me about Alice's personality.") answer = await cognee.search("Tell me about Alice's personality.")
print(answer) pprint(answer)
# Cognee is an async library, it has to be called in an async context # Cognee is an async library, it has to be called in an async context

View file

@ -1,4 +1,5 @@
import asyncio import asyncio
from pprint import pprint
import cognee import cognee
from cognee.api.v1.search import SearchType from cognee.api.v1.search import SearchType
@ -187,7 +188,7 @@ async def main(enable_steps):
search_results = await cognee.search( search_results = await cognee.search(
query_type=SearchType.GRAPH_COMPLETION, query_text="Who has experience in design tools?" query_type=SearchType.GRAPH_COMPLETION, query_text="Who has experience in design tools?"
) )
print(search_results) pprint(search_results)
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -1,6 +1,8 @@
import os import os
import asyncio import asyncio
import pathlib import pathlib
from pprint import pprint
from cognee.shared.logging_utils import setup_logging, ERROR from cognee.shared.logging_utils import setup_logging, ERROR
import cognee import cognee
@ -42,7 +44,7 @@ async def main():
# Display search results # Display search results
for result_text in search_results: for result_text in search_results:
print(result_text) pprint(result_text)
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -1,5 +1,6 @@
import asyncio import asyncio
import os import os
from pprint import pprint
import cognee import cognee
from cognee.api.v1.search import SearchType from cognee.api.v1.search import SearchType
@ -77,7 +78,7 @@ async def main():
query_type=SearchType.GRAPH_COMPLETION, query_type=SearchType.GRAPH_COMPLETION,
query_text="What are the exact cars and their types produced by Audi?", query_text="What are the exact cars and their types produced by Audi?",
) )
print(search_results) pprint(search_results)
await visualize_graph() await visualize_graph()

View file

@ -1,6 +1,7 @@
import os import os
import cognee import cognee
import pathlib import pathlib
from pprint import pprint
from cognee.modules.users.exceptions import PermissionDeniedError from cognee.modules.users.exceptions import PermissionDeniedError
from cognee.modules.users.tenants.methods import select_tenant from cognee.modules.users.tenants.methods import select_tenant
@ -86,7 +87,7 @@ async def main():
) )
print("\nSearch results as user_1 on dataset owned by user_1:") print("\nSearch results as user_1 on dataset owned by user_1:")
for result in search_results: for result in search_results:
print(f"{result}\n") pprint(result)
# But user_1 cant read the dataset owned by user_2 (QUANTUM dataset) # But user_1 cant read the dataset owned by user_2 (QUANTUM dataset)
print("\nSearch result as user_1 on the dataset owned by user_2:") print("\nSearch result as user_1 on the dataset owned by user_2:")
@ -134,7 +135,7 @@ async def main():
dataset_ids=[quantum_dataset_id], dataset_ids=[quantum_dataset_id],
) )
for result in search_results: for result in search_results:
print(f"{result}\n") pprint(result)
# If we'd like for user_1 to add new documents to the QUANTUM dataset owned by user_2, user_1 would have to get # If we'd like for user_1 to add new documents to the QUANTUM dataset owned by user_2, user_1 would have to get
# "write" access permission, which user_1 currently does not have # "write" access permission, which user_1 currently does not have
@ -217,7 +218,7 @@ async def main():
dataset_ids=[quantum_cognee_lab_dataset_id], dataset_ids=[quantum_cognee_lab_dataset_id],
) )
for result in search_results: for result in search_results:
print(f"{result}\n") pprint(result)
# Note: All of these function calls and permission system is available through our backend endpoints as well # Note: All of these function calls and permission system is available through our backend endpoints as well

View file

@ -1,4 +1,6 @@
import asyncio import asyncio
from pprint import pprint
import cognee import cognee
from cognee.modules.engine.operations.setup import setup from cognee.modules.engine.operations.setup import setup
from cognee.modules.users.methods import get_default_user from cognee.modules.users.methods import get_default_user
@ -71,7 +73,7 @@ async def main():
print("Search results:") print("Search results:")
# Display results # Display results
for result_text in search_results: for result_text in search_results:
print(result_text) pprint(result_text)
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -1,4 +1,6 @@
import asyncio import asyncio
from pprint import pprint
import cognee import cognee
from cognee.shared.logging_utils import setup_logging, ERROR from cognee.shared.logging_utils import setup_logging, ERROR
from cognee.api.v1.search import SearchType from cognee.api.v1.search import SearchType
@ -54,7 +56,7 @@ async def main():
print("Search results:") print("Search results:")
# Display results # Display results
for result_text in search_results: for result_text in search_results:
print(result_text) pprint(result_text)
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -1,4 +1,5 @@
import asyncio import asyncio
from pprint import pprint
import cognee import cognee
from cognee.shared.logging_utils import setup_logging, INFO from cognee.shared.logging_utils import setup_logging, INFO
from cognee.api.v1.search import SearchType from cognee.api.v1.search import SearchType
@ -87,7 +88,8 @@ async def main():
top_k=15, top_k=15,
) )
print(f"Query: {query_text}") print(f"Query: {query_text}")
print(f"Results: {search_results}\n") print("Results:")
pprint(search_results)
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -1,4 +1,5 @@
import asyncio import asyncio
from pprint import pprint
import cognee import cognee
from cognee.memify_pipelines.create_triplet_embeddings import create_triplet_embeddings from cognee.memify_pipelines.create_triplet_embeddings import create_triplet_embeddings
@ -65,7 +66,7 @@ async def main():
query_type=SearchType.TRIPLET_COMPLETION, query_type=SearchType.TRIPLET_COMPLETION,
query_text="What are the models produced by Volkswagen based on the context?", query_text="What are the models produced by Volkswagen based on the context?",
) )
print(search_results) pprint(search_results)
if __name__ == "__main__": if __name__ == "__main__":