QUICKSTART
Setup
To run cognee, you will need the following:
- Install cognee using poetry
poetry config virtualenvs.in-project true
poetry self add poetry-plugin-shell
poetry install
poetry shell
- OpenAI API key (Ollama or Anyscale could work as well)
Add your LLM API key to the environment variables
import os
os.environ["LLM_API_KEY"] = "YOUR_OPENAI_API_KEY"
or
cognee.config.llm_api_key = "YOUR_OPENAI_API_KEY"
If you are using Networkx, create an account on Graphistry to visualize results:
cognee.config.set_graphistry_config({
"username": "YOUR_USERNAME",
"password": "YOUR_PASSWORD"
})
If you want to run Postgres instead of Sqlite, run postgres Docker container. Navigate to cognee folder and run:
docker compose up postgres
Add the following environment variables to .env file
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USERNAME=cognee # or any username you want
DB_PASSWORD=cognee # or any password you want
DB_NAME=cognee_db # or any db name you want
DB_PROVIDER=postgres
Run
cognee is asynchronous by design, meaning that operations like adding information, processing it, and querying it can run concurrently without blocking the execution of other tasks. Make sure to await the results of the functions that you call.
import cognee
from cognee.api.v1.search import SearchType
text = """Natural language processing (NLP) is an interdisciplinary
subfield of computer science and information retrieval"""
await cognee.add(text) # Add a new piece of information
await cognee.cognify() # Use LLMs and cognee to create knowledge
search_results = await cognee.search(query_type=SearchType.INSIGHTS, query_text="Tell me about NLP") # Query cognee for the knowledge
for result_text in search_results:
print(result_text)
In the example above, we add a piece of information to cognee, use LLMs to create a GraphRAG, and then query cognee for the knowledge. cognee is composable and you can build your own cognee pipelines using our pipelines.
Have you seen cognee’s starter repo?
This repository is designed to help you get started quickly by providing example data and pre-built data pipelines using cognee to build powerful knowledge graphs. With this, you can visualize generated graphs and run search queries to get insights about the ingested data.
By following this guide, you will:
- Quickly load data to cognee
- Utilize pre-built pipelines for data processing
- Perform graph-based search and query operations
- Visualize entity relationships effortlessly on a graph
Try it out on GitHub now!
Join the Conversation!
Have questions? Join our community now to connect with professionals, share insights, and get your questions answered!