Skip to content

docs: add beginner-friendly knowledge graph example#3012

Open
gourangasatapathyvit wants to merge 10 commits into
topoteretes:devfrom
gourangasatapathyvit:docs/beginner-knowledge-graph-example
Open

docs: add beginner-friendly knowledge graph example#3012
gourangasatapathyvit wants to merge 10 commits into
topoteretes:devfrom
gourangasatapathyvit:docs/beginner-knowledge-graph-example

Conversation

@gourangasatapathyvit

@gourangasatapathyvit gourangasatapathyvit commented Jun 9, 2026

Copy link
Copy Markdown

Summary

  • Adds examples/guides/beginner_knowledge_graph.py — a step-by-step example that walks beginners through the full Cognee workflow: remember → explore → recall
  • The example ingests a short paragraph about Marie Curie, prints every extracted entity and relationship from the knowledge graph, then asks natural-language questions against it
  • Adds an "Understanding the Knowledge Graph" section to the README explaining what a knowledge graph is, what Cognee does under the hood, and showing sample output
  • Adds a pointer to the example in the README Examples section

Closes #2738

What the example covers

  1. REMEMBER — Feed sample text into Cognee
  2. EXPLORE — Retrieve and print all graph nodes (entities) and edges (relationships) using get_graph_engine().get_graph_data(), filtering out internal nodes (DocumentChunk, TextSummary) for clarity
  3. RECALL — Ask three natural-language questions and print clean text answers

Changes

  • examples/guides/beginner_knowledge_graph.py — new beginner-friendly example with inline explanations of what nodes, edges, and relationships are
  • README.md — new "Understanding the Knowledge Graph" section with sample output; pointer in Examples section

Test plan

  • Ran python examples/guides/beginner_knowledge_graph.py end-to-end with Azure OpenAI — all 3 stages complete successfully
  • Verified entities (21 nodes) and relationships (33 edges) are extracted and displayed cleanly
  • Verified all 3 recall questions answered correctly
  • ruff check and ruff format --check pass
  • markdownlint MD040 resolved (language tag on fenced code block)

I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Added an "Understanding the Knowledge Graph" section explaining knowledge graphs, the product's end-to-end workflow, and a sample output with run instructions.
    • Added a "New to knowledge graphs?" callout linking to a beginner-friendly example and showing how to execute it.
  • New Features
    • Added a runnable beginner example demonstrating ingestion, entity/relationship extraction, and natural‑language querying.

Add a step-by-step example (examples/guides/beginner_knowledge_graph.py)
that walks beginners through the full Cognee workflow:
  1. REMEMBER -- ingest sample text about Marie Curie
  2. EXPLORE  -- print every extracted entity and relationship
  3. RECALL   -- ask natural-language questions against the graph

Also add a pointer to this example in the README Examples section.

Closes topoteretes#2738

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Gouranga Satapathy <pulusatapathy@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 09e6eb00-d09a-40c9-9f5b-4016b5584e2d

📥 Commits

Reviewing files that changed from the base of the PR and between 1342d0f and 23c27b6.

📒 Files selected for processing (2)
  • README.md
  • examples/guides/beginner_knowledge_graph.py
✅ Files skipped from review due to trivial changes (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/guides/beginner_knowledge_graph.py

Walkthrough

This PR adds a beginner-friendly knowledge graph example: a README section and callout linking to a new runnable script that resets state, ingests sample text, prints extracted graph nodes/edges, and runs predefined natural-language queries.

Changes

Beginner Knowledge Graph Example

Layer / File(s) Summary
README knowledge-graph documentation
README.md
Adds an "Understanding the Knowledge Graph" section describing the graph workflow, a sample output block, and a python examples/guides/beginner_knowledge_graph.py run command; also inserts a "New to knowledge graphs?" callout linking to the example.
Example script docstring, imports, and sample text
examples/guides/beginner_knowledge_graph.py
Module docstring describing REMEMBER/EXPLORE/RECALL workflow, required imports, and the SAMPLE_TEXT constant used as the demo input.
Async main workflow (reset, ingest, extract, query) and entry point
examples/guides/beginner_knowledge_graph.py
Implements async def main() with Stage 0: cognee.forget(everything=True), Stage 1: cognee.remember(...) ingest, Stage 2: get_graph_data() to retrieve and print entities and relationships, Stage 3: looping cognee.recall(question) to print answers, a final summary, and if __name__ == "__main__": asyncio.run(main()) entry point.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a beginner-friendly knowledge graph example, which directly aligns with the PR's primary objective.
Description check ✅ Passed The description provides a clear summary of changes, explicitly links the related issue (#2738), outlines what the example covers, lists concrete changes, and includes a detailed test plan with verification steps.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #2738: provides a simple beginner-friendly example demonstrating the full Cognee workflow (remember → explore → recall), shows how a knowledge graph is created from input, demonstrates output interpretation with plain-language guidance, and adds README entry points for discoverability.
Out of Scope Changes check ✅ Passed All changes are in scope: the new beginner_knowledge_graph.py example directly addresses the linked issue, and README updates document the example and explain knowledge graph concepts as intended.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Add inline explanations in the example script so beginners
  understand what nodes, edges, and relationships mean
- Add "Understanding the Knowledge Graph" section to README with
  sample output showing extracted entities and relationships
- Explains what Cognee does under the hood (chunk, extract, store,
  answer) in plain language for newcomers

Addresses topoteretes#2738

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Gouranga Satapathy <pulusatapathy@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
examples/guides/beginner_knowledge_graph.py (1)

40-40: ⚡ Quick win

Consider adding a comment about the internal API usage.

The import of get_graph_engine() from cognee.infrastructure.databases.graph is an internal API that may change in future versions. While this is intentional for the demonstration (per the PR objectives), consider adding a comment explaining that this is an advanced inspection technique for educational purposes.

📝 Suggested comment addition
 import asyncio
 import cognee
+# Note: get_graph_engine is an internal API used here for educational purposes
+# to show graph internals. For production code, use cognee.recall() instead.
 from cognee.infrastructure.databases.graph import get_graph_engine
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/guides/beginner_knowledge_graph.py` at line 40, The import of
get_graph_engine from cognee.infrastructure.databases.graph uses an internal API
that may change; update the file to add a short inline comment above the import
(near the get_graph_engine import statement) stating that this is an
internal/advanced inspection technique used for demonstration and may break
across versions, and recommend using the public API for production code or
pinning the library version when relying on it.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/guides/beginner_knowledge_graph.py`:
- Line 58: Add a short docstring to the async function main() that briefly
summarizes what the function demonstrates (e.g., initializing the knowledge
graph, creating nodes/edges, and showing query usage); place the docstring
immediately below the async def main(): line so the function is documented per
project guidelines.

---

Nitpick comments:
In `@examples/guides/beginner_knowledge_graph.py`:
- Line 40: The import of get_graph_engine from
cognee.infrastructure.databases.graph uses an internal API that may change;
update the file to add a short inline comment above the import (near the
get_graph_engine import statement) stating that this is an internal/advanced
inspection technique used for demonstration and may break across versions, and
recommend using the public API for production code or pinning the library
version when relying on it.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: baf91219-43ce-482e-ba85-fc815d92677c

📥 Commits

Reviewing files that changed from the base of the PR and between 66f8f1f and 6349b7d.

📒 Files selected for processing (2)
  • README.md
  • examples/guides/beginner_knowledge_graph.py

Comment thread examples/guides/beginner_knowledge_graph.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Line 194: The README contains a fenced code block opened with triple backticks
that lacks a language tag which triggers markdownlint MD040; update the opening
fence to include a language specifier (e.g., change ``` to ```text) so the block
is properly tagged and lint-clean, leaving the block contents unchanged and
retaining the closing triple backticks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 592e777e-43b6-4332-a533-f5737067ad0b

📥 Commits

Reviewing files that changed from the base of the PR and between 6349b7d and abe7019.

📒 Files selected for processing (2)
  • README.md
  • examples/guides/beginner_knowledge_graph.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/guides/beginner_knowledge_graph.py

Comment thread README.md Outdated
gourangasatapathyvit and others added 7 commits June 9, 2026 11:41
- Use correct property key 'type' instead of '_type' for node types
- Filter out internal nodes (DocumentChunk, TextSummary) to show only
  meaningful entities
- Filter edges to only show relationships between named nodes
- Display recall answers using .text attribute for clean output
- Add inline explanations of what nodes and edges are for beginners

Tested: runs end-to-end with Azure OpenAI, produces clean output

Addresses topoteretes#2738

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Gouranga Satapathy <pulusatapathy@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Gouranga Satapathy <pulusatapathy@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Gouranga Satapathy <pulusatapathy@gmail.com>
@gourangasatapathyvit

Copy link
Copy Markdown
Author

hi @Vasilije1990 , Can you pls review the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant