diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e61812f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +notes/ diff --git a/smart-notes/rag_mvp/README.md b/smart-notes/rag_mvp/README.md new file mode 100644 index 0000000..2ce2968 --- /dev/null +++ b/smart-notes/rag_mvp/README.md @@ -0,0 +1,42 @@ +# Smart Notes – Local Q&A (RAG MVP) + +This is a minimal, local-first MVP that allows users to ask natural-language questions over their markdown notes. + +## Features (Current MVP) + +- Loads markdown files from a local `notes/` directory +- Supports natural-language questions (e.g., "what is AI", "where is AI used") +- Returns sentence-level answers from notes +- Shows the source note filename +- Interactive CLI loop (type `exit` to quit) + +This is a starter implementation intended to be extended with embeddings and vector search in future iterations. + +--- + +## How it works + +1. Notes are loaded from the local `notes/` directory. +2. Question words (what, where, who, when, etc.) are filtered. +3. Notes are split into sentences. +4. Relevant sentences are returned based on keyword matching. + +--- + +## How to run + +```bash +python smart-notes/rag_mvp/qa_cli.py + + + +>> what is AI + +[1] From test.md: +Artificial Intelligence (AI) is the simulation of human intelligence in machines. + + +>> what is machine learning +how is machine learning used +difference between AI and ML + diff --git a/smart-notes/rag_mvp/qa_cli.py b/smart-notes/rag_mvp/qa_cli.py new file mode 100644 index 0000000..210d56a --- /dev/null +++ b/smart-notes/rag_mvp/qa_cli.py @@ -0,0 +1,77 @@ +import os +import re + +QUESTION_WORDS = { + "what", "where", "who", "when", "which", + "is", "are", "was", "were", "the", "a", "an", + "of", "to", "in", "on", "for" +} + +NOTES_DIR = "notes" + + +def load_notes(): + notes = [] + if not os.path.exists(NOTES_DIR): + print(f"Notes directory '{NOTES_DIR}' not found.") + return notes + + for file in os.listdir(NOTES_DIR): + if file.endswith(".md"): + path = os.path.join(NOTES_DIR, file) + with open(path, "r", encoding="utf-8") as f: + notes.append({ + "filename": file, + "content": f.read() + }) + return notes + + +def split_sentences(text): + return re.split(r'(?<=[.!?])\s+', text) + + +def search_notes(query, notes): + results = [] + + query_words = [ + word.lower() + for word in query.split() + if word.lower() not in QUESTION_WORDS + ] + + for note in notes: + sentences = split_sentences(note["content"]) + for sentence in sentences: + sentence_lower = sentence.lower() + if any(word in sentence_lower for word in query_words): + results.append({ + "filename": note["filename"], + "sentence": sentence.strip() + }) + + return results + + +if __name__ == "__main__": + notes = load_notes() + + print("Ask questions about your notes (type 'exit' to quit)\n") + + while True: + query = input(">> ").strip() + + if query.lower() == "exit": + print("Goodbye 👋") + break + + matches = search_notes(query, notes) + + if not matches: + print("No relevant notes found.\n") + else: + print("\n--- Answers ---\n") + for i, m in enumerate(matches, 1): + print(f"[{i}] From {m['filename']}:") + print(m["sentence"]) + print()