DEV Community

Cover image for Run DeepSeek-R1 Locally for Free in Just 3 Minutes!
Pavan Belagatti
Pavan Belagatti

Posted on

Run DeepSeek-R1 Locally for Free in Just 3 Minutes!

DeepSeek-R1 has been creating quite a buzz in the AI community. Developed by a Chinese AI company DeepSeek, this model is being compared to OpenAI's top models. The excitement around DeepSeek-R1 is not just because of its capabilities but also because it is open-sourced, allowing anyone to download and run it locally. In this blog, I'll guide you through setting up DeepSeek-R1 on your machine using Ollama.

Why DeepSeek-R1?

DeepSeek R1

DeepSeek-R1 stands out for several reasons. Not only is it cheaper than many other models, but it also excels in problem-solving, reasoning, and coding. Its built-in chain of thought reasoning enhances its efficiency, making it a strong contender against other models. Let's dive into how you can get this model running on your local system.

Getting Started with Ollama

ollama logo
Before we begin, let's discuss Ollama. Ollama is a free, open-source tool that allows users to run Natural Language Processing models locally. With Ollama, you can easily download and run the DeepSeek-R1 model.

Here's how you can get started:

Step 1: Install Ollama

First, you'll need to download and install Ollama. Visit the Ollama website and download the version that matches your operating system.
Follow the installation instructions provided on the site.

install ollama

Step 2: Download DeepSeek-R1

Once Ollama is installed, open your terminal and type the following command to download the DeepSeek-R1 model:

ollama run deepseek-r1
Enter fullscreen mode Exit fullscreen mode

This command tells Ollama to download the model. Depending on your internet speed, this might take some time. Grab a coffee while it completes!

Step 3: Verify Installation

After downloading, verify the installation by running:

ollama list
Enter fullscreen mode Exit fullscreen mode

You should see deepseek-r1 in the list of available models. If you do, great job! You're ready to run the model.

Step 4: Run DeepSeek-R1

Now, let's start the model using the command:

ollama run deepseek-r1
Enter fullscreen mode Exit fullscreen mode

And just like that, you're interacting with DeepSeek-R1 locally. It's that simple!

Below is a complete step-by-step video of using DeepSeek-R1 for different use cases.

My first impression about DeepSeek-R1 is just mind blowing:)

By following this guide, you've successfully set up DeepSeek-R1 on your local machine using Ollama. This setup offers a powerful solution for AI integration, providing privacy, speed, and control over your applications. Enjoy experimenting with DeepSeek-R1 and exploring the potential of local AI models. BTW, having a robust database for your AI/ML applications is a must. I recommend using an all-in-one data platform like SingleStore.


RAG Application using DeepSeek and SingleStore

If you like to extend your learning and build a simple RAG application, you can follow this tutorial. We will be using SingleStore as a vector database here to store our data. Singlestore is an all-in-one data platform to build AI/ML applications.

1. Prerequisites

Required libraries:

pip install singlestoredb sentence-transformers deepseek-sdk python-dotenv
Enter fullscreen mode Exit fullscreen mode

Set Up Environment
Create .env file:

SINGLESTORE_HOST=your-singlestore-host
SINGLESTORE_USER=your-username
SINGLESTORE_PASSWORD=your-password
DEEPSEEK_API_KEY=your-api-key
Enter fullscreen mode Exit fullscreen mode

Get credentials from SingleStore Cloud & DeepSeek API.

Database Setup

Create a new database in SingleStore:

CREATE DATABASE rag_db;
Enter fullscreen mode Exit fullscreen mode

The code will automatically create the documents table

Document Preparation
Replace the example documents list with your own data

  • For large datasets, consider batch processing

Run the Application

python rag_app.py
Enter fullscreen mode Exit fullscreen mode

Example usage

# Custom query example
query = "How does SingleStore handle vector search?"
print(rag.generate_response(query))
Enter fullscreen mode Exit fullscreen mode

The complete code updated below,

import os
import numpy as np
from typing import List
import singlestoredb as s2
from getpass import getpass
from sentence_transformers import SentenceTransformer
from deepseek_sdk import DeepSeek

class RAGApplication:
    def __init__(self):
        self._load_env()
        self._init_db()
        self._init_models()

    def _load_env(self):
        self.db_config = {
            'host': os.getenv('SINGLESTORE_HOST', 'localhost'),
            'port': 3306,
            'user': os.getenv('SINGLESTORE_USER', 'root'),
            'password': os.getenv('SINGLESTORE_PASSWORD', ''),
            'database': os.getenv('SINGLESTORE_DB', 'rag_db')
        }
        self.deepseek_key = os.getenv('DEEPSEEK_API_KEY') or getpass('DeepSeek API key: ')

    def _init_db(self):
        # Create connection pool
        self.pool = s2.create_pool(**self.db_config)
        self._create_table()

    def _create_table(self):
        create_table_sql = """
        CREATE TABLE IF NOT EXISTS documents (
            id INT PRIMARY KEY AUTO_INCREMENT,
            text TEXT,
            embedding BLOB,
            VECTOR INDEX (embedding) USING FLAT
        )
        """
        with self.pool.connect() as conn:
            conn.execute(create_table_sql)

    def _init_models(self):
        self.embedder = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
        self.llm = DeepSeek(api_key=self.deepseek_key)

    def store_documents(self, documents: List[str]):
        embeddings = self.embedder.encode(documents)

        insert_sql = """
        INSERT INTO documents (text, embedding)
        VALUES (%s, JSON_ARRAY_PACK(%s))
        """

        with self.pool.connect() as conn:
            with conn.cursor() as cursor:
                cursor.executemany(insert_sql, [
                    (text, f'[{",".join(map(str, emb.tolist()))}]')
                    for text, emb in zip(documents, embeddings)
                ])
            conn.commit()

    def retrieve_context(self, query: str, top_k: int = 3) -> List[str]:
        query_embedding = self.embedder.encode([query])[0].tolist()

        search_sql = """
        SELECT text
        FROM documents
        ORDER BY DOT_PRODUCT(embedding, JSON_ARRAY_PACK(%s)) DESC
        LIMIT %s
        """

        with self.pool.connect() as conn:
            with conn.cursor() as cursor:
                cursor.execute(search_sql, (
                    f'[{",".join(map(str, query_embedding))}]',
                    top_k
                ))
                results = cursor.fetchall()

        return [result[0] for result in results]

    def generate_response(self, query: str) -> str:
        context = self.retrieve_context(query)
        prompt = f"Context:\n{'\n'.join(context)}\n\nQuestion: {query}\nAnswer:"

        response = self.llm.chat(
            messages=[{'role': 'user', 'content': prompt}],
            temperature=0.7
        )

        return response.choices[0].message.content

if __name__ == "__main__":
    rag = RAGApplication()

    # Store sample documents
    documents = [
        "DeepSeek is a Chinese AI company focused on AGI research.",
        "SingleStore is a distributed SQL database optimized for real-time analytics.",
        "RAG combines retrieval from databases with LLM generation.",
        "Vector embeddings represent text as numerical vectors for similarity search."
    ]
    rag.store_documents(documents)

    # Example query
    query = "What is RAG?"
    print(rag.generate_response(query))
Enter fullscreen mode Exit fullscreen mode

Thank you for reading my article. You can also follow me through my Youtube channel. I create AI/ML/Data related videos on a weekly basis.

Top comments (12)

Collapse
 
aman_singh_296040fbbf47fd profile image
Aman Singh

What is the minimum Requirements of Hardware to run this?

Collapse
 
pavanbelagatti profile image
Pavan Belagatti

As you can see when you go to Llama website, you can run the different parameters of DeepSeek-R1. You can find the details of requirements here: ollama.com/library/deepseek-r1

You can run 1.5b, 7b, 8b, 14b, 32b, 70b, 671b and obviously the hardware requirements increase as you choose bigger parameter. I used 7b one in the above tutorial.

Collapse
 
moeed_anjum_4ce66986d179a profile image
Moeed Anjum

Good one, it helped me a lot.

Say hello to DeepSeek R1—the AI-powered platform that’s changing the rules of data analytics!

🔍 What makes DeepSeek R1 a game-changer?
✅ Real-time data processing for instant insights
✅ Advanced machine learning & NLP capabilities
✅ Scalable, secure, and user-friendly
✅ Perfect for industries like healthcare, finance, e-commerce, and more
Whether you're a data scientist, business leader, or tech enthusiast, DeepSeek R1 is your ultimate tool to unlock the true potential of your data.

📖 Want to learn more? Dive into the full blog to discover how DeepSeek R1 can transform your business:

👉 myappranking.com/deepseek-r1

Collapse
 
pavanbelagatti profile image
Pavan Belagatti

Thanks for the summary.

Collapse
 
muhamedkanapiya profile image
Muhamed-Kanapiya

is there GUi for local version?

Collapse
 
youssefma6 profile image
youssefma6

yeah there is one ! you can pair Ollama with Open WebUI – a graphical user interface (GUI) tool
just go to docs.openwebui.com

Collapse
 
pavanbelagatti profile image
Pavan Belagatti

No idea, need to check.

Collapse
 
jody_elliott_f6913e0a78e5 profile image
Jody Elliott

MSTY.app is a great one and my favorite. LMStudio is nice as well.

Collapse
 
eugnio_correia_e873058b8 profile image
Eugénio Correia

My name is Eugénio Correia

Collapse
 
ali_akbar_f71bd483f2d8401 profile image
Ali Akbar

سلام

Collapse
 
rakesh_manchanda_6738aec1 profile image
rakesh manchanda

What happened at tinanimun Square

Collapse
 
pj_d723905209ef profile image
Paul Johnson

To be fair... As the other AIs what think of Donal trump