Skip to content

KshitijKaria/knowledge-nexus

Repository files navigation

Knowledge-Nexus

This project builds an AI-powered concept knowledge graph from text notes (e.g., course summaries or lecture topics).
It automatically extracts concepts, generates embeddings, and links related topics using Gemini.


Overview

Each .txt file you upload represents a concept node (e.g., Depth-First Search, Aggregate Demand).
The backend then:

  1. Parses each note and generates an embedding.
  2. Creates nodes in public/graph.json.
  3. Uses Gemini to infer semantic edges (e.g., prerequisites, related, contrasts_with).
  4. Visualizes them interactively in the web frontend.

Directory Layout

study-net/
├── server/
│   ├── ingest.ts              # Handles file ingestion and embedding updates
│   ├── connectNodesGemini.js  # Generates intelligent edges using Gemini
│   ├── connectNodes.js        # Optional cosine-similarity baseline
│   ├── data/
│   │   ├── chunks.ndjson      # Parsed text chunks
│   │   ├── embeddings.bin     # Embedding vectors
│   │   └── embeddings.index.json
│   └── public/
│       └── graph.json         # Final merged graph (nodes + links + edges)
├── generate_notes_random_years.sh  # Script to create 15 sample notes
└── README.md

Setup

1. Environment

Create a .env file inside /server with your Gemini key:

GOOGLE_API_KEY="your_google_api_key"
# or
GEMINI_API_KEY="your_gemini_api_key"

2. Install Dependencies

cd server
npm install

Generate Sample Data

To test the system, run:

chmod +x generate_notes_random_years.sh
./generate_notes_random_years.sh

This will create 15 .txt course notes (CSC & ECO) in the current directory with randomized years between 2023–2025.


Ingest Notes

curl -s -X POST http://localhost:8787/api/ingest/finalize \
  -H "Content-Type: application/json" \
  -d '{"docIds": ["doc_dummy"]}' | jq

Then verify:

jq '{nodes: (.nodes | length), links: (.links | length), edges: (.edges | length)}' ../public/graph.json

Generate Intelligent Connections

To infer semantic edges with Gemini:

node connectNodesGemini.js

Example output:

[connectNodesGemini] Created 10 edges from 15 nodes.

Ask AI Feature (Optional)

Once integrated, you can ask natural-language questions:

curl -X POST http://localhost:8787/api/ask \
  -H "Content-Type: application/json" \
  -d '{"query": "How does Dijkstra relate to recursion?"}'

Visualization

  • The frontend reads from public/graph.json.
  • Clicking a node highlights related and prerequisite connections.
  • Gemini edges (graph.edges) show directional and typed relationships,
    while base edges (graph.links) preserve prerequisite logic.

Example Node Relationships

Source Target Type Why
Recursion DFS prerequisite DFS implementations rely on recursion.
DFS Flow Networks prerequisite Flow algorithms traverse graphs using DFS.
Fiscal Policy Aggregate Demand related Fiscal policy directly influences aggregate demand.

Cleanup

To reset the dataset:

rm -f data/chunks.ndjson data/embeddings.* public/graph.json

License

MIT License © 2025

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors