3 Easy Steps to Train Local AI Model Ollama: Beginner Guide

Train local AI model Ollama

Have you ever wanted an AI that doesn’t just give generic answers? If you want to train local AI model Ollama to speak your language, you’ve come to the right place.

What if you could have a personal AI mentor that explains complex coding concepts with a sense of humor, all while running entirely on your laptop?

In this guide, we’ll walk through how to use Ollama to create a custom AI model. No cloud GPUs, no subscription fees, and no internet required once you’re set up.

Why Train local AI model Ollama?

Standard models like Phi-3 or Llama 3 are great, but they are “generalists.” By creating a custom Modelfile, you can:

  • Customize Personality: Make it talk like a teacher, a developer, or even a comedian.
  • Set the Tone: Control how creative or factual the responses are.
  • Privacy: Since it runs locally, your data never leaves your machine.

Get Started With Ollama

A quick guide to configure ollama on your local machine.

Prerequisites

Before we start, ensure you have Ollama installed on your system and at least one base model downloaded (this tutorial uses phi3:mini).

Step 1: Create Your Custom Modelfile

The “Modelfile” is the blueprint for your AI. Think of it as a wrapper that adds instructions on top of an existing model.

  1. Open a text editor (like Notepad or VS Code).
  2. Add the following configuration:
# Specify the base model
FROM phi3:mini

# Set the creativity level (0.0 = Robotic, 1.0 = Creative/Risky)
PARAMETER temperature 0.8

# Define the AI's personality
SYSTEM """
You are AmplifyAbhi, a tech mentor who explains coding and AI 
in a very funny way. Always use simple examples and try to 
make the user laugh while they learn.
"""

Understanding “Temperature”

  • 0.0: The model becomes predictable and robotic. It will give the same answer every time.
  • 1.0: The model becomes highly creative and unpredictable—perfect for brainstorming or story writing.
  • 0.8: This is a “sweet spot” used in the video to balance accuracy with a bit of flair. [02:39]

Step 2: Build Your Model

Once you have saved your file (e.g., as AmplifyAbhiModel), open your terminal and navigate to the folder where the file is saved. Run the following command:

ollama create AmplifyAbhi -f AmplifyAbhiModel

If successful, you will see a success message. You can verify your new model is ready by typing ollama list. You’ll see your custom model listed alongside the original base models. [06:41]

Step 3: Run and Test Your AI

Now it’s time to talk to your creation! Run your model using:

ollama run AmplifyAbhi

In the video, when asked “Who are you?”, the model responded not as a generic AI, but as a “personal jester” for tech, staying true to the funny persona defined in the System prompt. [07:58]

Conclusion

You don’t need a massive server farm to build your own version of AI. By using Ollama and a simple Modelfile, you can fine-tune the “vibe” and behavior of an AI to suit your specific needs.

What kind of AI will you build? A strict coding tutor? A poetic assistant? Let us know in the comments!

Useful Parameters

Max tokens

Controls response length.

PARAMETER num_predict 512

Context window

How much memory/context the model remembers during chat.

Higher = more RAM usage.

PARAMETER num_ctx 4096

Top P

Controls word selection diversity.

PARAMETER top_p 0.9

Usually keep:

0.8–0.95

Repeat penalty

Prevents repetitive answers.

PARAMETER repeat_penalty 1.1

Where model is saved?

Ollama stores models locally on your machine.

Usually:

macOS

~/.ollama/models

Windows

C:\Users\<username>\.ollama\models

Linux

/usr/share/ollama/.ollama/models

Best practice for your use case

Since you’re creating AI/tutorial content:

You can create multiple personalities:

amplifyabhi-teacher
amplifyabhi-funny
amplifyabhi-shorts
amplifyabhi-interviewer

Important thing many people misunderstand

You are NOT retraining the AI.

You are:

  • wrapping the base model
  • controlling behavior
  • steering responses

Real training/fine-tuning is a different process involving:

  • datasets
  • GPUs
  • LoRA/fine-tuning
  • epochs
  • weights

Your current setup is:

  • lightweight
  • fast
  • local
  • practical

which is actually perfect for creators and developers.

Train local AI model Ollama : Watch the Full Tutorial

For a visual walkthrough of this process, check out the full video by Amplifyabhi

Explore More AI & Development Tutorials :

Hope you found Train local AI model Ollama guide interesting suggestiong you to browse through AI tutorials that help you master AI integration and modern mobile development.

Master AI & LLM Integration

Level Up Your Flutter & React Native Skills

Flutter :

ReactNative

AI File Organizer: 7 Powerful Steps to Clean Your Messy Computer

AI File Organizer

This guide on AI File Organizer outlines a professional content structure for your technical blog. It focuses on local AI implementation using Ollama and Python, catering to developers interested in automation and LLMs.

Introduction: The Problem of Digital Clutter

We’ve all been there. You start your week with a clean desktop, but by Friday, your screen is a chaotic mosaic of unlabeled PDFs, random screenshots, ZIP files, and installation executables.

As we use our computers every day—downloading work reports, creating new project drafts, editing music, or saving memes—we tell ourselves we’ll “sort it out later.” But “later” rarely comes. Instead, files pile up unknowingly, turning your Desktop and Downloads folder into a digital graveyard. This isn’t just an aesthetic issue; it’s a productivity killer.

The Hidden Cost of a Messy Computer

Digital clutter impacts more than just your wallpaper. It affects your workflow and your machine’s efficiency:

  • Wasted Time: Searching for “Final_Draft_v2.docx” in a sea of 500 files costs you precious minutes every day.
  • Mental Fatigue: Research shows that visual clutter increases stress and decreases focus. A messy desktop is a constant “to-do” list screaming for your attention.
  • Storage Drain: Duplicate files and forgotten installers eat up your SSD storage, eventually slowing down your system performance.
  • Security Risks: Leaving sensitive documents (like invoices or IDs) in a general downloads folder makes them harder to track and protect.

Why Manual Cleaning Fails

The reason most of us skip cleaning is simple: It’s boring and repetitive. Sorting files by hand into categories like “Work,” “Finance,” or “Personal” feels like a chore. Most traditional scripts only look at file extensions, putting all your photos in one place, regardless of whether they are for a project or a vacation.

In this blog, we are moving past manual labor. We are going to build a local AI file organizer that understands the context of your files. Whether it’s a song you edited or a bank statement you downloaded, our AI will recognize it and put it exactly where it belongs.

What is Ollama? (The Engine)

Ollama is a lightweight, open-source framework that allows you to run large language models (LLMs) like Gemma, Llama 3, and Mistral locally on your machine.

  • Privacy: No data leaves your computer.
  • Cost: Completely free to use (no API credits).
  • Speed: Low latency since it runs on your local GPU/CPU.

Have a look at the below playlist – https://www.youtube.com/playlist?list=PL04fRXMy5cnZ4idDpAlJNY3hXI6A6eKsQ

Block-by-Block Explanation

Environment Setup & Configuration

We use pathlib for modern path handling and requests to talk to the Ollama API.

  • Key Concept: Pointing the script to the right local URL and selecting the model (e.g., gemma4:31b-cloud
OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL_NAME = "gemma4:31b-cloud"

# Change this to your Downloads path
PROJECT_FOLDER = Path.home() / "Desktop/Project"

Scanning the Messy Folder

The script iterates through your target directory and collects filenames. It ignores subfolders to avoid recursive loops during the first run.

files = [
    f.name
    for f in PROJECT_FOLDER.iterdir()
    if f.is_file()
]

if not files:
    print("No files found in Project folder.")
    exit()

print("\nFiles Found:\n")
for file in files:
    print("-", file)

The “Magic” Prompt Engineering

This is the most critical part. We tell the AI to act as an “Intelligent File Organizer.”

  • Constraint: We force the AI to return Only JSON. This allows our Python script to parse the output without manual intervention.
prompt = f"""
You are an intelligent file organizer.

Your task:
1. Analyze the filenames.
2. Create smart categories.
3. Return ONLY valid JSON.

Rules:
- No explanation
- No markdown
- No extra text
- Only JSON

Example format:
{{
  "Finance": ["invoice.pdf"],
  "Career": ["resume.pdf"],
  "Images": ["photo.png"]
}}

Files:
{files}
"""

Communication with Ollama API

We send the list of files to the local Ollama server. The script waits for the AI to “think” and return a categorized JSON object.

print("\nAnalyzing files using AI...\n")

response = requests.post(
    OLLAMA_URL,
    json={
        "model": MODEL_NAME,
        "prompt": prompt,
        "stream": False
    }
)

result = response.json()["response"]

print("AI Response:\n")
print(result)

The Safety Net (Dry Run & Confirmation)

Before moving a single byte, the script prints an “Organization Plan.” This ensures the AI didn’t hallucinate or miscategorize an important file.

try:
    categories = json.loads(result)
except Exception as e:
    print("\nFailed to parse AI response.")
    print(e)
    exit()

print("\n========== AI ORGANIZATION PLAN ==========\n")

for folder, file_list in categories.items():
    print(f"{folder}:")
    for file_name in file_list:
        print(f"   - {file_name}")
    print()

User Confirmation

After the dry run the next step is to take user confirmation to proceed with the task.

confirm = input("Proceed with organization? (y/n): ")

if confirm.lower() != "y":
    print("\nOperation cancelled.")
    exit()

Shutil Execution

Using shutil.move, the script creates folders dynamically based on the AI’s categories and physically moves the files.

for folder, file_list in categories.items():

    folder_path = PROJECT_FOLDER / folder
    folder_path.mkdir(exist_ok=True)

    for file_name in file_list:

        source = PROJECT_FOLDER / file_name
        destination = folder_path / file_name

        try:
            if source.exists():
                shutil.move(str(source), str(destination))
                print(f"Moved: {file_name} → {folder}")
            else:
                print(f"File not found: {file_name}")

        except Exception as e:
            print(f"Error moving {file_name}: {e}")

Watch the Full Build: Step-by-Step Video Tutorial

In the video below, I walk you through the entire setup of this AI File Organizer

Troubleshooting Guide

IssueSolution
Connection ErrorEnsure Ollama is running in the background (ollama serve).
JSON Decode ErrorThe AI might have added “Here is your JSON” text. Add “Strictly only JSON” to your prompt.
Model Not FoundRun ollama pull gemma4:31b-cloud in your terminal first.
Permission DeniedEnsure the script has read/write access to the PROJECT_FOLDER.

Can I use a smaller model?

Yes! If your RAM is limited, try gemma:2b or phi3. They are incredibly fast for simple tasks like file naming.

Will this delete my files?

No. shutil.move is a move operation. However, always keep a backup before running automation scripts on sensitive data.

Can it organize images based on what is inside them?

This specific script uses filenames. For visual content, you would need a Multimodal model (like Moondream or LLaVA).

GraphRAG using Ollama – Build a Knowledge Graph in 11 Powerful Steps

GraphRAG using Ollama

GraphRAG using Ollama: Build a Local Knowledge Graph in 11 Steps

GraphRAG using Ollama we build a Graph-based Retrieval Augmented Generation (GraphRAG) system using a local LLM (Ollama) and Python, without any cloud APIs.

We will:
• Extract relationships using an LLM
• Build a knowledge graph using NetworkX
• Retrieve facts from the graph
• Answer questions strictly from graph context

This entire setup runs offline.

Why Choose GraphRAG over Traditional RAG?

Traditional RAG retrieves text chunks.
GraphRAG retrieves structured facts like:

Google → developed → Flutter
Flutter → integrates_with → Firebase

This reduces hallucinations and improves factual accuracy.

Learn how to combine Ollama with NetworkX to create a hallucination-free AI retrieval system.

Total Time: 30 minutes

Install Dependencies

Set up your environment by installing requests for API calls and networkx for managing the knowledge graph structure.

Define Input Documents

Create a list of text strings (knowledge base) that contain the facts you want the AI to extract and remember.

Configure Ollama

Point your Python script to the local Ollama HTTP API endpoint and specify the model name you intend to use.

Create Relationship Extraction Prompt

Write a strict system prompt that instructs the LLM to output relationships only in a structured JSON format (Source, Relation, Target).

Set Up Safe API Calls

Implement a function to send prompts to Ollama with error handling and timeouts to ensure the script doesn’t crash during long processing tasks.

Extract Relationships (JSON-Safe)

Use Regex and JSON parsing to clean the LLM output, ensuring only valid data enters your graph while filtering out conversational “noise.”

Build the Knowledge Graph

Iterate through the extracted relationships and use NetworkX to create a directed graph where nodes are entities and edges are their connections.

Query Normalization

Create a function to lowercase and strip special characters from user questions to ensure they match the entities stored in your graph.

Retrieve Facts from Graph

Search the graph for nodes that appear in the user’s query and pull all related “edges” (facts) to serve as context for the AI.

Generate GraphRAG Answer

Feed the retrieved facts and the user’s question into a final prompt, forcing the LLM to answer only based on the graph data provided.

Run the Interactive System

Initialize the graph and start a loop that allows users to ask questions and receive structured, fact-based answers in real-time.

Prerequisites and Tech Stack

  • Python
  • Ollama (Local LLM)
  • NetworkX (Graph engine)
  • Regex + JSON parsing

Step-by-Step Guide to Implementing GraphRAG

Step 1: Install Dependencies

pip install requests networkx

Make sure Ollama is running locally:

ollama run amplifyabhi

Step 2: Define Documents (Input Knowledge)

These are the facts we want to convert into a graph.

DOCUMENTS = [
    "Flutter is a UI toolkit developed by Google.",
    "Flutter integrates with Firebase.",
    "Firebase is owned by Google."
]

Step 3: Ollama Configuration

We call Ollama directly using its HTTP API.

OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "amplifyabhi"

Step 4: Crafting the Relationship Extraction Prompt

We force the LLM to return structured JSON only.

GRAPH_PROMPT = """
Extract relationships as JSON

Format: 
{
    "relationships": [
        { "source": "", "relation": "", "target": ""}
    ]
}
Text:
"""

This prompt is critical.

Bad prompts = broken JSON.

Step 5: Call Ollama Safely

def ollama(prompt: str) -> str:
    response = requests.post(
        OLLAMA_URL,
        json={
            "model": MODEL,
            "prompt": prompt,
            "stream": False
        },
        timeout=60
    )
    return response.json().get("response", "")

We use .get(“response”, “”) to avoid crashes if Ollama returns unexpected output.

Step 6: Extract Relationships (JSON-Safe)

LLMs sometimes return extra text.
So we extract only the JSON block.

def extract_relationships(text: str):
    raw = ollama(GRAPH_PROMPT + text)

    start = raw.find("{")
    end = raw.rfind("}") + 1

    if start == -1 or end == -1:
        return []
    
    json_text = raw[start:end].strip()
    
    try:
        data = json.loads(json_text)
    except json.JSONDecodeError:
        return []
    
    relationships = data.get("relationships", [])
    return [r for r in relationships if r.get("source") and r.get("relation") and r.get("target")]

This step prevents:

  • JSONDecodeError
  • Partial JSON
  • Hallucinated keys

Step 7: Building the Graph with NetworkX

We store extracted facts in a directed graph.

def build_graph(docs):
    graph = nx.DiGraph()
    for doc in docs:
        relations = extract_relationships(doc)
        for r in relations:
            graph.add_edge(
                r["source"],
                r["target"],
                relation=r["relation"]
            )
    return graph

Step 8: Query Normalization

Used to match questions with graph nodes.

def normalize(text):
    return re.sub(r"[^a-z0-9 ]", "", text.lower())

Step 9: Retrieve Facts From Graph

This replaces vector search.

def retrieve_from_graph(query, graph):
    q = normalize(query)
    facts = []
    for u, v, d in graph.edges(data=True):
        if normalize(u) in q or normalize(v) in q:
            facts.append(f"{u} {d['relation']} {v}")
    return facts

GraphRAG using Ollama Part 1

GraphRAG using Ollama explained in detail

Step 10: GraphRAG Answer Generation

LLM is strictly bounded by graph facts.

def graphrag_answer(query, graph):
    facts = retrieve_from_graph(query, graph)

    if not facts:
        return "I don't know based on the graph."

    context = "\n".join(facts)

    prompt = f"""
        You are a technical assistant.

        Rules:
        - Answer in 1–2 factual sentences
        - Use ONLY the context
        - No assumptions

        Context:
        {context}

        Question:
        {query}

        Answer:
        """
    return ollama(prompt)

Step 11: Run the System

if __name__ == "__main__":
    graph = build_graph(DOCUMENTS)

    print("Graph Edges:\n")
    for u, v, d in graph.edges(data=True):
        print(f"{u} - [{d['relation']}]-> {v}")

    while True:
        q = input("Question: ")
        if q.lower() == "exit":
            break
        print(graphrag_answer(q, graph))

GraphRAG using Ollama Part 2

In this video, we go deep into GraphRAG (Graph-based Retrieval Augmented Generation)
and show how to STOP large language models from adding fake or extra information.

Key Takeaways

Implementing GraphRAG using Ollama these are the key takeaways
• GraphRAG reduces hallucinations
• Local LLMs can power serious AI systems
• JSON enforcement is mandatory
• Graphs > embeddings for factual queries

Troubleshooting Common GraphRAG Issues

ProblemSolution
JSONDecodeErrorEnsure your prompt explicitly demands “JSON only” and check the regex parser in Step 6.
Ollama TimeoutIncrease the timeout parameter in the requests.post call (Step 5) to 120 or 180 seconds.
No Facts FoundEnsure your normalize function isn’t being too aggressive with character stripping.
Connection RefusedVerify Ollama is running in the background and the port 11434 is open.

Frequently Asked Questions (FAQ)

Can I use this with any Ollama model?

Yes, but models like Llama3 or Mistral are better at following the strict JSON formatting required for relationship extraction.

Does this require an internet connection?

No. Once you have downloaded the Ollama model and installed the Python libraries, the entire GraphRAG system runs 100% offline.

Why use NetworkX instead of a Vector DB?

While Vector DBs are great for similarity, NetworkX allows you to map explicit relationships (e.g., “A works for B”), which significantly reduces AI hallucinations.

n8n YouTube Automation: Ultimate 100% Local AI Setup | Secure Local AI

n8n youtube automation

n8n youtube automation

n8n youtube automation, Most YouTube automation tutorials rely on paid AI APIs like ChatGPT or Gemini. While they work, they come with costs, rate limits, privacy concerns, and internet dependency.

What if you could:
• Generate YouTube titles, descriptions, and tags
• Upload videos automatically
• Run everything locally
• Use zero API keys
• Pay nothing

In this article on n8n youtube automation, we’ll build exactly that using n8n and Ollama, powered by a lightweight local LLM.

This setup is ideal for developers, YouTubers, and indie creators who want full control.

What Is n8n?

n8n is an open-source workflow automation tool, similar to Zapier, but:
• Self-hosted
• Developer-friendly
• No per-task pricing
• Full JavaScript support

It allows you to visually connect APIs, logic, files, and platforms like YouTube.Why automate YouTube uploads?

What Is Ollama?

Ollama lets you run Large Language Models (LLMs) directly on your machine.

Why Ollama?
• No internet required
• No API keys
• Runs on Mac, Windows, Linux
• Supports models like Phi-3, LLaMA, Mistral

In this workflow, Ollama acts as your local ChatGPT replacement.

Running Ollama with Docker

Why host.docker.internal?

When n8n is also running inside Docker, it cannot access localhost directly.
Instead, we use:

http://host.docker.internal:11434


This is a very common Docker networking issue, and many developers face issue for this specifically.

Calling the Ollama HTTP API from n8n

In n8n, add an HTTP Request node.

Endpoint

POST http://host.docker.internal:11434/api/generate


Request Body (JSON)

{
  "model": "phi3:mini",
  "prompt": "Generate an attractive YouTube title and description for uploading a video on Supabase backend integration.",
  "stream": false
}

Important Notes
• stream: false is mandatory for automation
• phi3:mini is lightweight and fast
• Works perfectly on Mac M1 with 8GB RAM

Filter and Clean API Output Using JavaScript in n8n

// Access input data from previous node (HTTP Request)
const inputData = $input.all();

function extractYouTubeData(inputData) {
  if (!Array.isArray(inputData) || inputData.length === 0) {
    return { title: "", description: "", tags: [] };
  }

  // Combine all responses
  let fullText = "";
  for (const item of inputData) {
    const res = item.json?.response || item.json?.data || "";
    if (res) fullText += res + "\n";
  }

  let title = "";
  let description = "";
  let tags = [];

  // 1. Try to parse JSON block if available
  const jsonMatch = fullText.match(/```(?:json)?\s*([\s\S]*?)```/i);
  if (jsonMatch) {
    try {
      const parsed = JSON.parse(jsonMatch[1]);
      title = parsed.title || "";
      description = parsed.description || "";
      tags = parsed.tags || [];
    } catch (e) {
      console.error("JSON parse error:", e);
    }
  }

  // 2. Fallback: Extract Title: ... and Description: ...
  if (!title) {
    const titleMatch = fullText.match(/Title:\s*["']?(.+?)["']?\s*(?:\n|$)/i);
    if (titleMatch) title = titleMatch[1].trim();
  }

  if (!description) {
    const descMatch = fullText.match(/Description:\s*([\s\S]+)/i);
    if (descMatch) description = descMatch[1].trim();
  }

  // 3. Optional: Auto-generate tags from title if no tags
  if (tags.length === 0 && title) {
    tags = title
      .split(/\s+/)
      .filter(word => word.length > 2)
      .map(word => word.replace(/[^a-zA-Z0-9]/g, ""))
      .slice(0, 10); // limit to 10 tags
  }

  return { title, description, tags };
}

const result = extractYouTubeData(inputData);
return [result];

Why this Code Node Is Needed in n8n

When you call a local LLM (like Ollama), the response often contains:
• Extra metadata
• Tokens
• Streaming-related fields
• Nested objects you don’t want to send to YouTube

Platforms like YouTube expect clean, minimal fields:
• title
• description
• tags

This Code node acts as a filter + transformer layer.

Using Dynamic Expressions in the YouTube Node (n8n)

In the YouTube Upload node, you should map the fields like this:

Title field

{{ $json.title }}

Description field

{{ $json.description }}


Tags field

{{ $json.tags }}

Finally we Automated flow

Now it’s time to have a look through the n8n youtube automation tutorial.

Ollama RAG Tutorial for Beginners using ChromaDB, LangChain (Proven Powerful 1 Local AI Guide)

Ollama RAG Tutorial for Beginners

LangChain RAG tutorial

Ollama RAG Tutorial for Beginners, This tutorial RAG with Ollama and ChromaDB demonstrates how to build a local Retrieval-Augmented Generation (RAG) system using Ollama for embeddings, ChromaDB for vector storage, and LangChain-style querying—without any cloud APIs.

Retrieval Augmented Generation Python

We designed this RAG model using Python to ensure wide adoption, as Python is easy to learn and is more accessible compared to many other programming languages.

Feel free to reach out if you are looking for any other programming language.

Ollama embeddings RAG

Used Ollama in generating embeddings.

ChromaDB vector database

Embeddings generated in above step are stored in chroma DB

This tutorial demonstrates a Local RAG system built using Python, combining an Offline RAG LLM, semantic search with embeddings, and efficient vector search in Python to deliver accurate, privacy-first AI responses without cloud dependencies.

Complete Code

import ollama
import chromadb

client = chromadb.Client()

collection = client.create_collection(name="my_embeddings")

sentences = [
    "ollama makes running LLMs locally easy.",
    "Sentence embeddings are useful for search.",
    "Java is great for machine learning."
]


for idx, sentence in enumerate(sentences):
    response = ollama.embeddings(
        model="nomic-embed-text",
        prompt = sentence
    )
    collection.add(
        ids = [str(idx)],
        documents=[sentence],
        embeddings=[response["embedding"]]
    )
print("Embeddings are stored")

query = "Which language is great for machine learning"

query_embedding = ollama.embeddings(
    model="nomic-embed-text",
    prompt = query
)["embedding"]

results = collection.query(
    query_embeddings = [query_embedding],
    n_results=1
)

print(results["documents"])

context = results["documents"][0][0]

prompt = f"""
Use the context to answer the question, make sure the answer is in 1 or 2 sentences and crisp

Question:
Which language is great for machine learning?
"""

response = ollama.generate(
    model="amplifyabhi",
    prompt=prompt
)

print(response["response"])

Ollama RAG Tutorial for Beginners Complete Playlist

For more interesting updates on RAG with Ollama and ChromaDB stay subscribed to Amplifyabhi