← all conversations

Knowledge Graph Backend Design

2025-03-302 turns4,017 charsgpt-4o
knowledge-graphbackend-designdocument-processing

Summary

Designing a FastAPI backend to process markdown files into a knowledge graph using chunking and multiple libraries.

Messages

So here is what I am trying to build so I can rubber duck this. FastAPI backend using uvicorn chromadb sql_alchemy networkx which takes from the next.js frontend's react-dropzone any .md file I input Then I implement chunking of the .md file in order for it to extract concepts from the .md files stored as embeddings in the chromadb with id, name, description, embedding and any other meta data I want. Then using networkx I can get all relationships and use those as edges and the concepts generated along with the metadata as the nodes for the graph. Then I can add the rest of the logic for the knowledge graph in the KnowledgeGraph class, like get_prerequisites, get_next_concept, get_learning_path, recommend_next_concept I could have another service for the llm calls using ollama, local mistral usually ends up being the best balance for my set up at least. I can include all of the llm calls in a class like LLMService so I can easily add or edit the prompts. Then I could have an embedding service using sentence_transformers to generate embeddings for when I add db entries to the vector store. I can use sqlalchemy to create the models. The whole concept is that you can upload your .md files and it will construct a knowledge graph which you can interact with a chat window in the next.js frontend which will generate lessons based on the content of the .md files. So what I need to do next in planning this out...
You're on the right track! Here’s what you need to do next in planning: ### **1. Define Data Flow and Architecture** - **Frontend (Next.js + React Dropzone)** - Upload `.md` files - Display knowledge graph (possibly with D3.js or ReactFlow) - Chat window to interact with knowledge graph - **Backend (FastAPI)** - **File Handling:** Accept `.md` files via an API endpoint - **Chunking & Processing:** - Extract sections/concepts from the `.md` files - Generate embeddings (SentenceTransformers) - Store in ChromaDB (with metadata) - **Graph Construction (NetworkX)** - Nodes: Concepts (extracted from `.md`) - Edges: Relationships between concepts - **Knowledge Graph API** - `get_prerequisites()` - `get_next_concept()` - `get_learning_path()` - `recommend_next_concept()` - **LLM Service (Ollama with Mistral)** - Generate summaries, quizzes, and lessons - Query knowledge graph via chat interface - **Database (SQLAlchemy + ChromaDB)** - Store metadata + embeddings in ChromaDB - Store knowledge graph relationships in SQLAlchemy ### **2. Break It Down into Tasks** #### **Backend** ✅ Set up FastAPI project ✅ Implement `.md` file upload endpoint ✅ Integrate ChromaDB for embeddings storage ✅ Implement chunking logic ✅ Implement embedding generation (SentenceTransformers) ✅ Store metadata in ChromaDB ✅ Construct knowledge graph with NetworkX ✅ Implement API routes for graph traversal ✅ Set up LLM service (Ollama/Mistral) ✅ Implement chat API #### **Frontend** ✅ Set up Next.js + React Dropzone ✅ Implement file upload to FastAPI ✅ Display knowledge graph (ReactFlow / D3.js) ✅ Integrate chat interface for interaction ### **3. Immediate Next Steps** 1. **Define Chunking Strategy** - How are you segmenting `.md` content? (Headings, sentences, paragraphs?) - Do you need hierarchical relationships? (E.g., Sections → Subsections → Concepts) 2. **Design Graph Schema** - What metadata do you want for nodes? - What types of relationships will you track? - How do you weight edges? (e.g., prerequisites vs. weak associations) 3. **LLM Service Planning** - Define initial prompt templates - Determine API structure (e.g., `/generate_lesson`, `/summarize_concept`) 4. **Define API Routes & Models** - Finalize SQLAlchemy models - Define FastAPI routes 5. **Prototype File Upload & Chunking** - Get a test `.md` file - Implement basic chunking and embedding storage Would you like help fleshing out any of these steps? 🚀
gpt-4o