<!-- .github/pull_request_template.md --> ## Description Notebook and python example for cognee simple example ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced an interactive demo showcasing asynchronous document processing and querying for key insights from a sample text. - **Documentation** - Added an in-depth, step-by-step guide in a Jupyter Notebook that walks users through setup, configuration, querying, and visualizing processed data. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
34 lines
960 B
Python
34 lines
960 B
Python
import asyncio
|
|
import cognee
|
|
|
|
import os
|
|
|
|
# By default cognee uses OpenAI's gpt-4o-mini LLM model
|
|
# Provide your OpenAI LLM API KEY
|
|
os.environ["LLM_API_KEY"] = ""
|
|
|
|
|
|
async def cognee_demo():
|
|
# Get file path to document to process
|
|
from pathlib import Path
|
|
|
|
current_directory = Path(__file__).resolve().parent.parent
|
|
file_path = os.path.join(current_directory, "data", "alice_in_wonderland.txt")
|
|
|
|
# Call Cognee to process document
|
|
await cognee.add(file_path)
|
|
await cognee.cognify()
|
|
|
|
# Query Cognee for information from provided document
|
|
answer = await cognee.search("List me all the important characters in Alice in Wonderland.")
|
|
print(answer)
|
|
|
|
answer = await cognee.search("How did Alice end up in Wonderland?")
|
|
print(answer)
|
|
|
|
answer = await cognee.search("Tell me about Alice's personality.")
|
|
print(answer)
|
|
|
|
|
|
# Cognee is an async library, it has to be called in an async context
|
|
asyncio.run(cognee_demo())
|