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
@ -35,16 +36,16 @@ biography_1 = """
biography_2 = """ biography_2 = """
Arnulf Øverland Ole Peter Arnulf Øverland ( 27 April 1889 25 March 1968 ) was a Norwegian poet and artist . He is principally known for his poetry which served to inspire the Norwegian resistance movement during the German occupation of Norway during World War II . Arnulf Øverland Ole Peter Arnulf Øverland ( 27 April 1889 25 March 1968 ) was a Norwegian poet and artist . He is principally known for his poetry which served to inspire the Norwegian resistance movement during the German occupation of Norway during World War II .
Biography . Biography .
Øverland was born in Kristiansund and raised in Bergen . His parents were Peter Anton Øverland ( 18521906 ) and Hanna Hage ( 18541939 ) . The early death of his father , left the family economically stressed . He was able to attend Bergen Cathedral School and in 1904 Kristiania Cathedral School . He graduated in 1907 and for a time studied philology at University of Kristiania . Øverland published his first collection of poems ( 1911 ) . Øverland was born in Kristiansund and raised in Bergen . His parents were Peter Anton Øverland ( 18521906 ) and Hanna Hage ( 18541939 ) . The early death of his father , left the family economically stressed . He was able to attend Bergen Cathedral School and in 1904 Kristiania Cathedral School . He graduated in 1907 and for a time studied philology at University of Kristiania . Øverland published his first collection of poems ( 1911 ) .
Øverland became a communist sympathizer from the early 1920s and became a member of Mot Dag . He also served as chairman of the Norwegian Students Society 192328 . He changed his stand in 1937 , partly as an expression of dissent against the ongoing Moscow Trials . He was an avid opponent of Nazism and in 1936 he wrote the poem Du ikke sove which was printed in the journal Samtiden . It ends with . ( I thought: : Something is imminent . Our era is over Europes on fire! ) . Probably the most famous line of the poem is ( You mustnt endure so well the injustice that doesnt affect you yourself! ) Øverland became a communist sympathizer from the early 1920s and became a member of Mot Dag . He also served as chairman of the Norwegian Students Society 192328 . He changed his stand in 1937 , partly as an expression of dissent against the ongoing Moscow Trials . He was an avid opponent of Nazism and in 1936 he wrote the poem Du ikke sove which was printed in the journal Samtiden . It ends with . ( I thought: : Something is imminent . Our era is over Europes on fire! ) . Probably the most famous line of the poem is ( You mustnt endure so well the injustice that doesnt affect you yourself! )
During the German occupation of Norway from 1940 in World War II , he wrote to inspire the Norwegian resistance movement . He wrote a series of poems which were clandestinely distributed , leading to the arrest of both him and his future wife Margrete Aamot Øverland in 1941 . Arnulf Øverland was held first in the prison camp of Grini before being transferred to Sachsenhausen concentration camp in Germany . He spent a four-year imprisonment until the liberation of Norway in 1945 . His poems were later collected in Vi overlever alt and published in 1945 . During the German occupation of Norway from 1940 in World War II , he wrote to inspire the Norwegian resistance movement . He wrote a series of poems which were clandestinely distributed , leading to the arrest of both him and his future wife Margrete Aamot Øverland in 1941 . Arnulf Øverland was held first in the prison camp of Grini before being transferred to Sachsenhausen concentration camp in Germany . He spent a four-year imprisonment until the liberation of Norway in 1945 . His poems were later collected in Vi overlever alt and published in 1945 .
Øverland played an important role in the Norwegian language struggle in the post-war era . He became a noted supporter for the conservative written form of Norwegian called Riksmål , he was president of Riksmålsforbundet ( an organization in support of Riksmål ) from 1947 to 1956 . In addition , Øverland adhered to the traditionalist style of writing , criticising modernist poetry on several occasions . His speech Tungetale fra parnasset , published in Arbeiderbladet in 1954 , initiated the so-called Glossolalia debate . Øverland played an important role in the Norwegian language struggle in the post-war era . He became a noted supporter for the conservative written form of Norwegian called Riksmål , he was president of Riksmålsforbundet ( an organization in support of Riksmål ) from 1947 to 1956 . In addition , Øverland adhered to the traditionalist style of writing , criticising modernist poetry on several occasions . His speech Tungetale fra parnasset , published in Arbeiderbladet in 1954 , initiated the so-called Glossolalia debate .
Personal life . Personal life .
In 1918 he had married the singer Hildur Arntzen ( 18881957 ) . Their marriage was dissolved in 1939 . In 1940 , he married Bartholine Eufemia Leganger ( 19031995 ) . They separated shortly after , and were officially divorced in 1945 . Øverland was married to journalist Margrete Aamot Øverland ( 19131978 ) during June 1945 . In 1946 , the Norwegian Parliament arranged for Arnulf and Margrete Aamot Øverland to reside at the Grotten . He lived there until his death in 1968 and she lived there for another ten years until her death in 1978 . Arnulf Øverland was buried at Vår Frelsers Gravlund in Oslo . Joseph Grimeland designed the bust of Arnulf Øverland ( bronze , 1970 ) at his grave site . In 1918 he had married the singer Hildur Arntzen ( 18881957 ) . Their marriage was dissolved in 1939 . In 1940 , he married Bartholine Eufemia Leganger ( 19031995 ) . They separated shortly after , and were officially divorced in 1945 . Øverland was married to journalist Margrete Aamot Øverland ( 19131978 ) during June 1945 . In 1946 , the Norwegian Parliament arranged for Arnulf and Margrete Aamot Øverland to reside at the Grotten . He lived there until his death in 1968 and she lived there for another ten years until her death in 1978 . Arnulf Øverland was buried at Vår Frelsers Gravlund in Oslo . Joseph Grimeland designed the bust of Arnulf Øverland ( bronze , 1970 ) at his grave site .
@ -56,7 +57,7 @@ biography_2 = """
- Vi overlever alt ( 1945 ) - Vi overlever alt ( 1945 )
- Sverdet bak døren ( 1956 ) - Sverdet bak døren ( 1956 )
- Livets minutter ( 1965 ) - Livets minutter ( 1965 )
Awards . Awards .
- Gyldendals Endowment ( 1935 ) - Gyldendals Endowment ( 1935 )
- Dobloug Prize ( 1951 ) - Dobloug Prize ( 1951 )
@ -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__":