DEV Community

Cover image for Building a "Private Google" with Local AI: A Beginner's Guide to Weaviate & Ollama
Harish Kotra (he/him)
Harish Kotra (he/him)

Posted on

Building a "Private Google" with Local AI: A Beginner's Guide to Weaviate & Ollama

Have you ever wondered how Netflix knows exactly what movie you want to watch, or how Google understands that "jaguar speed" creates results about animals, not cars?

The secret is Semantic Search - searching by meaning, not just keywords.

In this guide, I'll show you how we built a full-stack search application using just two powerful (and free!) local tools: Weaviate (Vector Database) and Ollama (Local AI).

How it Works

Before we dive into the code, let's visualize how the pieces fit together.

How It Works

The Components

  1. Ollama (The Translator): Computers don't understand English. They understand numbers. Ollama takes text (like "The sky is blue") and turns it into a long list of numbers called a Vector Embedding.
    • Analogy: Imagine describing a "Strawberry" not by its name, but by its coordinates: [Red: 0.9, Sweet: 0.8, Fruit: 1.0]. That's an embedding!
  2. Weaviate (The Brain): This is a special database designed to store these vectors. Unlike a normal database that looks for exact word matches, Weaviate calculates the "distance" between vectors to find things that are conceptually close.

The Algorithms: Breaking Down the "Search"

We implemented four different ways to search. Here is exactly what they do.

1. Vector Search (Semantic Search)

"I know what you mean."

This uses the embeddings we talked about. If you search for "Planets", it finds "Mars" and "Jupiter" even if the word "Planets" never appears in the text. It knows they are related concepts.

  • Best for: Vague questions, concept exploration.
  • Drawback: Sometimes misses specific names or exact product codes.

2. Keyword Search (BM25)

"I found exactly what you said."

This is the "old school" search (like Ctrl+F). It looks for exact word matches. It uses an algorithm called BM25, which is just a fancy way of saying "Find documents where this word appears often, but isn't a common word like 'the' or 'and'."

  • Best for: Exact names, part numbers, specific jargon.
  • Drawback: "Car" won't match "Automobile".

3. Hybrid Search

"The Best of Both Worlds"

This combines Vector and Keyword search. It runs both and then merges the results. We use a slider called "Alpha" to control the balance.

  • Alpha = 0: 100% Keyword Search.
  • Alpha = 0.5: Equal mix.
  • Alpha = 1: 100% Vector Search.

Best of Both Worlds

4. Reranking

"The Double Check"

This is the most advanced technique. It works in two stages:

  1. Retrieval: We quickly grab the top 50 loosely relevant results using Vector search.
  2. Reranking: We use a special, more powerful AI model (a Cross-Encoder) to carefully read those 50 results and score them against your query. It's slower but extremely accurate.
  • Analogy: Retrieval is like skimming a library shelf and grabbing 50 books that look relevant. Reranking is reading the back cover of those 50 to pick the perfect 5.

By running this locally, you get:

  • Privacy: Your data never leaves your computer.
  • Speed: No network latency to OpenAI or Google.
  • Cost: It's 100% free.

Want to try it?

The app allows you to:

  1. Seed Data: We pull real Jeopardy questions + AI-generated facts.
  2. Search: Toggle between the algorithms to see the difference.
  3. Manage: Add your own data points and watch them become instantly searchable.

Full Codebase on Github

Top comments (0)