-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from topoteretes/simple-python-example
Simple python example
- Loading branch information
Showing
2 changed files
with
65 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import cognee | ||
import asyncio | ||
from cognee.api.v1.search import SearchType | ||
|
||
# Prerequisites: | ||
# 1. Copy `.env.template` and rename it to `.env`. | ||
# 2. Add your OpenAI API key to the `.env` file in the `LLM_API_KEY` field: | ||
# LLM_API_KEY = "your_key_here" | ||
# 3. (Optional) To minimize setup effort, set `VECTOR_DB_PROVIDER="lancedb"` in `.env". | ||
|
||
async def main(): | ||
# Create a clean slate for cognee -- reset data and system state | ||
await cognee.prune.prune_data() | ||
await cognee.prune.prune_system(metadata=True) | ||
|
||
# cognee knowledge graph will be created based on this text | ||
text = """ | ||
Natural language processing (NLP) is an interdisciplinary | ||
subfield of computer science and information retrieval. | ||
""" | ||
|
||
# Add the text, and make it available for cognify | ||
await cognee.add(text) | ||
|
||
# Use LLMs and cognee to create knowledge graph | ||
await cognee.cognify() | ||
|
||
# Query cognee for insights on the added text | ||
search_results = await cognee.search( | ||
SearchType.INSIGHTS, | ||
{'query': 'Tell me about NLP'} | ||
) | ||
|
||
# Display search results | ||
for result_text in search_results: | ||
print(result_text) | ||
|
||
if __name__ == '__main__': | ||
asyncio.run(main()) |