DEV Community

mehmet akar
mehmet akar

Posted on

1

5 Free Vector Databases

Free vector database is such an incredible opportunity for hobby projects at first then scaling with paying as you go.

I will talk about 5 Vector DBs offer FOREVER Free Plans.

I want to point out, these are FOREVER Free, not a trial for a limited time. Of course, there are some limits but most of the companies don't even give this opportunity.

1. Free Vector DB: Upstash Vector

First free vector database I want to talk about is Upstash Vector provided by Upstash. A free vector database is an incredible opportunity for hobby projects, allowing developers and enthusiasts to explore powerful machine learning applications without worrying about upfront costs.

Vectors are essential in machine learning, powering use cases such as recommendation systems, semantic search, natural language processing, and image similarity searches. Upstash Vector simplifies the process by providing a serverless and scalable database that supports vector operations like similarity search with minimal setup.

Now, let me dive into what Upstash Vector offers and how to use it effectively in your projects!


Features of Upstash Vector

  • Free Plan: Start for free with a generous quota suitable for small to medium projects.
  • Serverless: No server management required; scale seamlessly as your needs grow.
  • Global Distribution: With a globally distributed infrastructure, enjoy low latency for your applications.
  • Simple API: Easily integrate vector operations into your applications using REST APIs or SDKs.
  • Efficient Indexing: Supports efficient vector similarity search using advanced indexing techniques.

Pricing Details

Upstash Vector provides a transparent and affordable pricing structure. Below is a summary:

Plan Free Plan Pro Plan Enterprise Plan
Monthly Price $0 Starting at $10/mo Custom Pricing
Vector Limit 10,000 vectors 100,000+ vectors Millions of vectors
API Calls 50,000/month 1 million/month Custom Limits
Custom Models Not Available Available Available
Support Community Support Priority Support Dedicated Support
SLA None 99.9% SLA Custom SLA

The free plan is perfect for getting started and experimenting with vector-based applications.


Getting Started with Upstash Vector

In this section, we’ll walk through setting up and using Upstash Vector with a hands-on tutorial.

Step 1: Sign Up for Upstash

  1. Go to Upstash and create a free account.
  2. Navigate to the Vector section on the dashboard.
  3. Create a new vector database by following the setup wizard.
  4. Once the database is created, note down the REST API Endpoint and Token.

Step 2: Setting Up Your Project

We’ll demonstrate how to use Upstash Vector with Python. Install the required libraries:

pip install requests numpy
Enter fullscreen mode Exit fullscreen mode

Step 3: Adding Vectors to the Database

Here’s how you can add vectors to your database:

import requests
import numpy as np

# Replace these with your API details
BASE_URL = "https://<your-upstash-vector-endpoint>.upstash.io"
TOKEN = "<your-access-token>"

headers = {
    "Authorization": f"Bearer {TOKEN}",
    "Content-Type": "application/json"
}

def add_vector(collection_name, vector, metadata):
    url = f"{BASE_URL}/collections/{collection_name}/vectors"
    payload = {
        "vector": vector.tolist(),
        "metadata": metadata
    }
    response = requests.post(url, json=payload, headers=headers)
    if response.status_code == 200:
        print("Vector added successfully!", response.json())
    else:
        print("Failed to add vector:", response.text)

# Example usage
collection = "my_collection"
vector = np.random.rand(128)  # Example 128-dimensional vector
metadata = {"id": 1, "name": "Sample Vector"}

add_vector(collection, vector, metadata)
Enter fullscreen mode Exit fullscreen mode

Step 4: Performing Similarity Search

Now let’s query the database for the most similar vectors:

def similarity_search(collection_name, query_vector, top_k=5):
    url = f"{BASE_URL}/collections/{collection_name}/search"
    payload = {
        "vector": query_vector.tolist(),
        "top_k": top_k
    }
    response = requests.post(url, json=payload, headers=headers)
    if response.status_code == 200:
        print("Search results:", response.json())
    else:
        print("Failed to search:", response.text)

# Example usage
query_vector = np.random.rand(128)  # Query with a random 128-dimensional vector
similarity_search(collection, query_vector)
Enter fullscreen mode Exit fullscreen mode

Step 5: Deleting Vectors

If you need to delete a vector from the database, you can do so using its metadata or ID:

def delete_vector(collection_name, metadata_id):
    url = f"{BASE_URL}/collections/{collection_name}/vectors/{metadata_id}"
    response = requests.delete(url, headers=headers)
    if response.status_code == 200:
        print("Vector deleted successfully!", response.json())
    else:
        print("Failed to delete vector:", response.text)

# Example usage
delete_vector(collection, 1)
Enter fullscreen mode Exit fullscreen mode

Step 6: Scaling Up

Once you’ve validated your project on the free plan, scaling up to the Pro or Enterprise plan is seamless. You can upgrade directly from the Upstash dashboard and benefit from higher vector limits, additional API calls, and advanced features like custom models.


Conclusion

Upstash Vector is an excellent choice for developers looking for a serverless, scalable, and affordable vector database. Its simplicity and generous free tier make it perfect for hobby projects, while its robust feature set caters to production-grade applications.

With this tutorial, you should be ready to build and deploy your vector-based applications using Upstash Vector. Whether you’re working on recommendation systems, semantic search, or AI-driven applications, Upstash Vector provides the tools you need to succeed.


2. Zilliz Cloud

Zilliz Cloud is built on the open-source Milvus vector database and provides an excellent free tier. It is ideal for developers working on projects requiring vector similarity search, such as recommendation systems and semantic search. With Zilliz Cloud, you can efficiently scale and integrate with popular AI tools like Hugging Face and OpenAI.

Pricing Details

Plan Free Tier Pro Plan Enterprise Plan
Monthly Price $0 Starting at $50/mo Custom Pricing
Vector Limit 1,000,000 vectors 10,000,000+ vectors Unlimited vectors
API Calls 10,000 calls/month 1 million/month Custom Limits
Support Community Support Priority Support Dedicated Support
SLA None 99.9% SLA Custom SLA

Getting Started with Zilliz Cloud

Step 1: Sign Up and Create a Database

  1. Go to Zilliz Cloud and sign up for a free account.
  2. Navigate to the dashboard and create a new database.
  3. Obtain your API key and endpoint for API requests.

Step 2: Install Required Libraries

Install the Python SDK for Milvus:

pip install pymilvus
Enter fullscreen mode Exit fullscreen mode

Step 3: Connect to Zilliz Cloud

from pymilvus import Collection, connections

# Replace with your details
HOST = "<your-zilliz-cloud-endpoint>"
PORT = "19530"

# Connect to the database
connections.connect("default", host=HOST, port=PORT)
print("Connected to Zilliz Cloud!")
Enter fullscreen mode Exit fullscreen mode

Step 4: Create a Collection and Add Vectors

from pymilvus import FieldSchema, CollectionSchema, DataType, Collection

# Define schema
fields = [
    FieldSchema(name="id", dtype=DataType.INT64, is_primary=True),
    FieldSchema(name="embedding", dtype=DataType.FLOAT_VECTOR, dim=128)
]
schema = CollectionSchema(fields, "Vector collection schema")

# Create collection
collection = Collection("my_collection", schema)

# Add vectors
import numpy as np
vectors = np.random.rand(10, 128).tolist()  # 10 random vectors with 128 dimensions
ids = [i for i in range(10)]
collection.insert([ids, vectors])
print("Vectors inserted!")
Enter fullscreen mode Exit fullscreen mode

Step 5: Perform Similarity Search

query_vector = np.random.rand(1, 128).tolist()  # Single query vector
collection.load()
results = collection.search(query_vector, "embedding", param={"nprobe": 10}, limit=3)

for result in results[0]:
    print(f"ID: {result.id}, Distance: {result.distance}")
Enter fullscreen mode Exit fullscreen mode

3. Qdrant Cloud

Qdrant Cloud is a fully managed vector database designed for real-time similarity search and machine learning applications. With a straightforward API and robust infrastructure, Qdrant simplifies working with high-dimensional data.

Pricing Details

Plan Free Plan Pro Plan Enterprise Plan
Monthly Price $0 Starting at $15/mo Custom Pricing
Vector Limit 10,000 vectors 100,000+ vectors Millions of vectors
API Calls 50,000/month 1 million/month Custom Limits
Support Community Support Priority Support Dedicated Support
SLA None 99.9% SLA Custom SLA

Getting Started with Qdrant Cloud

Step 1: Sign Up and Obtain API Key

  1. Visit Qdrant Cloud and create an account.
  2. Set up a new vector collection.
  3. Note your API key and endpoint URL.

Step 2: Install the Python Client

pip install qdrant-client
Enter fullscreen mode Exit fullscreen mode

Step 3: Upload Vectors

from qdrant_client import QdrantClient

client = QdrantClient(url="<your-endpoint>", api_key="<your-api-key>")

# Define collection and vectors
collection_name = "my_collection"

client.recreate_collection(
    collection_name=collection_name,
    vector_size=128,
    distance="Cosine"
)

# Add vectors
import numpy as np
vectors = np.random.rand(10, 128).tolist()
points = [{"id": i, "vector": vector} for i, vector in enumerate(vectors)]
client.upsert(collection_name=collection_name, points=points)
print("Vectors uploaded!")
Enter fullscreen mode Exit fullscreen mode

Step 4: Perform Search

query_vector = np.random.rand(1, 128).tolist()
results = client.search(
    collection_name=collection_name,
    query_vector=query_vector[0],
    limit=5
)

for result in results:
    print(f"ID: {result['id']}, Score: {result['score']}")
Enter fullscreen mode Exit fullscreen mode

4. Azure Cosmos DB for MongoDB

Azure Cosmos DB offers vector database capabilities integrated into its MongoDB API. It’s an excellent option for those already using Azure’s ecosystem and provides seamless scaling for vector-based applications.

Pricing Details

Plan Free Tier Standard Tier Enterprise Tier
Monthly Price $0 Pay-as-you-go Custom Pricing
Vector Limit 25,000 vectors 1 million+ vectors Unlimited vectors
API Calls 50,000/month Unlimited Custom Limits
Support Community Support Standard Support Dedicated Support
SLA None 99.9% SLA Custom SLA

Getting Started with Azure Cosmos DB for MongoDB

Step 1: Create a Cosmos DB Account

  1. Go to Azure Portal and create a Cosmos DB account.
  2. Choose the MongoDB API option during setup.
  3. Note the connection string for your new account.

Step 2: Install MongoDB Python Client

pip install pymongo
Enter fullscreen mode Exit fullscreen mode

Step 3: Connect and Insert Vectors

from pymongo import MongoClient
import numpy as np

# Replace with your connection string
CONNECTION_STRING = "<your-cosmos-db-connection-string>"
client = MongoClient(CONNECTION_STRING)

# Access database and collection
db = client["vector_db"]
collection = db["vectors"]

# Insert vectors
vectors = [{"_id": i, "vector": np.random.rand(128).tolist()} for i in range(10)]
collection.insert_many(vectors)
print("Vectors inserted into Cosmos DB!")
Enter fullscreen mode Exit fullscreen mode

Step 4: Perform Similarity Search

from scipy.spatial.distance import cosine

query_vector = np.random.rand(128)

# Retrieve vectors and calculate similarity
results = collection.find()
scored_results = [
    {"_id": result["_id"], "score": 1 - cosine(query_vector, result["vector"])}
    for result in results
]

# Sort by similarity
scored_results = sorted(scored_results, key=lambda x: x["score"], reverse=True)

for result in scored_results[:5]:
    print(f"ID: {result['_id']}, Similarity: {result['score']}")
Enter fullscreen mode Exit fullscreen mode

5. Milvus

Introduction

Milvus is an open-source vector database designed for high-performance vector similarity search. While it doesn’t have a managed service like Zilliz Cloud, you can deploy it on your own infrastructure for free.

Pricing Details

Plan Open-Source Managed (Zilliz Cloud) Enterprise Tier
Monthly Price $0 Starting at $50/mo Custom Pricing
Vector Limit Unlimited 1,000,000+ vectors Unlimited vectors
API Calls Unlimited 10,000/month Custom Limits
Support Community Support Priority Support Dedicated Support
SLA None 99.9% SLA Custom SLA

Getting Started with Milvus

Step 1: Install Milvus

Follow the official installation guide to set up Milvus on your infrastructure. Docker is the easiest way:

docker run -d --name milvus-standalone \
    -p 19530:19530 \
    milvusdb/milvus-standalone:latest
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Python SDK

pip install pymilvus
Enter fullscreen mode Exit fullscreen mode

Step 3: Connect and Insert Vectors

from pymilvus import Collection, connections
import numpy as np

connections.connect(host="127.0.0.1", port="19530")

# Define collection schema
fields = [
    FieldSchema(name="id", dtype=DataType.INT64, is_primary=True),
    FieldSchema(name="embedding", dtype=DataType.FLOAT_VECTOR, dim=128)
]
schema = CollectionSchema(fields, "Example collection schema")

collection = Collection("example_collection", schema)

# Insert vectors
vectors = np.random.rand(10, 128).tolist()
ids = list(range(10))
collection.insert([ids, vectors])
print("Vectors inserted into Milvus!")
Enter fullscreen mode Exit fullscreen mode

Step 4: Perform Similarity Search

query_vector = np.random.rand(1, 128).tolist()
collection.load()
results = collection.search(query_vector, "embedding", param={"nprobe": 10}, limit=5)

for result in results[0]:
    print(f"ID: {result.id}, Distance: {result.distance}")
Enter fullscreen mode Exit fullscreen mode

With these tutorials, you can now explore the best free vector database options and leverage their unique capabilities for your projects. Let me know if you need help with specific use cases or further details!

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry 👀

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay