AI Campus • Prayogika kalike

Build a cited study-note search tool

Find supporting passages in your own notes, with file and line citations. Learn the retrieval stage used inside larger AI assistants.

Beginner · 45–90 minutes

Before you start

  • Python 3.10 or newer and a text editor.
  • A UTF-8 notes.txt file containing a few paragraphs you have permission to use.

Cost: No API fees or extra packages. Uses Python and a local text file.

Step-by-step walkthrough

  1. 1. Prepare your notes

    Create a project folder and notes.txt. Put one passage per line. For a first check, include “Vectors represent directions.” on line two. Keep the original line order so citations remain meaningful.

  2. 2. Save the complete program

    Save the code below as study_search.py in the same folder. It scores word overlap, returns the best passages, and does not invent a passage when no words match.

  3. 3. Run a supported query

    In PowerShell, Command Prompt, or a terminal, run: python study_search.py notes.txt vectors. Expect a result beginning [notes.txt:2] with the matching sentence.

  4. 4. Test an unsupported query

    Run: python study_search.py notes.txt quantum. If your notes do not mention quantum, expect “No supporting passage found in these notes.”

  5. 5. Make it portfolio-ready

    Write a README with the two commands, expected results, and a screenshot. Explain that this is keyword retrieval, not semantic search or generated answers. Compare it with embeddings as a future extension.

Complete code: study_search.py

Download Python file
import argparse
import re
from pathlib import Path

def words(text):
    return set(re.findall(r"[a-z0-9]+", text.lower()))

def main():
    parser = argparse.ArgumentParser(description="Search notes with line citations")
    parser.add_argument("notes")
    parser.add_argument("question", nargs="+")
    args = parser.parse_args()
    file = Path(args.notes)
    try:
        lines = file.read_text(encoding="utf-8-sig").splitlines()
    except (OSError, UnicodeError):
        parser.exit(2, "Cannot read the notes as UTF-8 text.\n")
    query = words(" ".join(args.question))
    ranked = []
    for number, line in enumerate(lines, 1):
        tokens = words(line)
        score = len(query & tokens) / max(1, len(query | tokens))
        if score > 0:
            ranked.append((score, number, line))
    ranked.sort(key=lambda row: (-row[0], row[1]))
    if not ranked:
        print("No supporting passage found in these notes.")
    for score, number, line in ranked[:3]:
        print(f"[{file.name}:{number}] {line}")

if __name__ == "__main__":
    main()

Run and verify

python study_search.py notes.txt vectors
python study_search.py notes.txt quantum

Matching passages include [filename:line] citations. Unmatched questions return an explicit no-support message.

Understand the limits

Keyword overlap misses synonyms and cannot establish factual correctness. This project deliberately teaches retrieval without calling a model.

Official references

AI Campus Weekly Dispatch

AI Campus updates padeyiri.

AI suddi, tools mattu kalikeya maahitiyannu vaarakke omme nimma inbox nalli padeyiri.

Weekly curated AI intelligence for students. Unsubscribe anytime in 1 click.

Essential cookies site kelasa maadalu beku. Bhaashe mattu subscription aaykegalu nimma device nalli ulitaave. Optional analytics athava advertising cookies eega balasuttilla.

Vivara mattu settings