Skip to content

unverciftci/vector_database_agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

🤖 Smart Math Problem Solver

I built this to show how LEANN can create an AI that actually learns from examples, just like how I solve math problems - by looking at similar ones I've seen before.

What it does

Give it any math word problem, and it:

  1. Searches through 1000+ solved problems to find similar ones
  2. Looks at how those were solved
  3. Adapts the solution approach for your specific problem
  4. Explains the steps clearly

It's like having a study buddy who remembers every math problem they've ever seen.

Try it yourself

!pip install leann datasets transformers torch

from datasets import load_dataset
from leann import LeannBuilder, LeannSearcher, LeannChat

# Load math problems (I used Microsoft's Orca dataset)
dataset = load_dataset("microsoft/orca-math-word-problems-200k", split="train[:1000]")

# Build the knowledge base
builder = LeannBuilder(backend_name="hnsw")
for item in dataset:
    text = f"Problem: {item['question']} Solution: {item['answer']}"
    builder.add_text(text)
builder.build_index("math_helper.leann")

# Set up the AI
searcher = LeannSearcher("math_helper.leann")
chat = LeannChat("math_helper.leann", 
                llm_config={"type": "hf", "model": "Qwen/Qwen3-0.6B"})

# Ask it anything!
problem = "If I buy a $100 shirt with 25% off, what do I pay?"
solution = chat.ask(f"Solve this step by step: {problem}", top_k=3)
print(solution)

Why this is cool

  • Learns like humans do: Finds similar problems instead of memorizing formulas
  • Works offline: Everything runs on your laptop, no internet needed
  • Super efficient: 1000 problems fit in just 50MB (usually takes 500MB+)
  • Actually explains: Doesn't just give answers, shows the thinking

Real example

My question: "A pizza costs $20. If I tip 18%, how much do I pay total?"

What it finds: Similar problems about calculating tips and percentages

What it says: "Looking at similar tip calculation problems, you need to find 18% of $20 and add it to the original cost. 18% of $20 = $3.60, so total = $20 + $3.60 = $23.60"

Beyond math

This same idea works for any field where you learn from examples:

  • Research: "Find papers similar to my protein study → see what methods they used"
  • Coding: "Find algorithms similar to my graph problem → adapt the approach"
  • Business: "Find companies that solved similar supply chain issues → learn their strategy"

I think this pattern of "find similar → adapt solution" is how a lot of real problem-solving works.

Quick start

  1. Copy the code above into Google Colab
  2. Run it and try asking math questions
  3. Watch it find similar problems and explain solutions
  4. Swap in your own dataset for different domains

The whole thing runs in about 5 minutes and shows how LEANN makes it easy to build AI that learns from examples rather than just memorizing facts.

What I learned building this

LEANN's storage efficiency is a game-changer. I can fit way more examples in memory, which means better similar problem matching. And since everything runs locally, I don't worry about sending my data to some API.

Perfect for building AI that actually learns the way humans do - by finding patterns in examples.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors