Use a Free Vector Database with Python
Python is the dominant language for AI and machine learning, and all major free vector databases ship Python client libraries. This guide covers what working with a free vector database from Python looks like — connecting, inserting vectors, and running similarity queries — using a working code example throughout.
What You Need
- Python 3.8+
- pip — included with Python
- A running vector database instance — local via Docker, or a free cloud sandbox
How Python Clients for Vector Databases Work
Free vector databases expose their functionality over REST and, increasingly, gRPC APIs. Python client libraries wrap these APIs into idiomatic Python objects — so instead of crafting HTTP requests manually, you call methods like collection.query.near_vector() or batch.add_object().
Modern vector database Python clients (v4 generation) use gRPC for data operations — inserts, queries, batch writes — and fall back to REST for administrative tasks like creating collections. This gives significantly faster throughput than REST-only clients, particularly for bulk inserts.
Install the Python Client
The example in this guide uses the Python client for an open-source free vector database, installable with a single pip command:
pip install weaviate-client
Start a Local Instance (If You Don’t Have One)
The fastest way to get a local vector database running for Python development is Docker:
docker run -d -p 8080:8080 -p 50051:50051 cr.weaviate.io/semitechnologies/weaviate:1.38.0
Alternatively, sign up for a free cloud sandbox — no credit card required — and use the cluster URL and API key instead of localhost.
Example: Connect, Create, Insert, Query
Connect to a Local Instance
import weaviate
client = weaviate.connect_to_local()
print(client.is_ready()) # True
Connect to a Free Cloud Sandbox
import weaviate
from weaviate.auth import AuthApiKey
client = weaviate.connect_to_weaviate_cloud(
cluster_url="https://your-sandbox.weaviate.network",
auth_credentials=AuthApiKey("your-api-key"),
)
Create a Collection
A collection defines the schema — the properties stored alongside each vector. Setting the vectorizer to none means you supply your own vectors at insert time:
from weaviate.classes.config import Configure, Property, DataType
client.collections.create(
name="Article",
vectorizer_config=Configure.Vectorizer.none(),
properties=[
Property(name="title", data_type=DataType.TEXT),
Property(name="content", data_type=DataType.TEXT),
]
)
Insert Vectors
Single insert and batch insert both follow the same pattern — properties plus a pre-computed vector:
import numpy as np
articles = client.collections.get("Article")
# Single insert
articles.data.insert(
properties={"title": "What is vector search", "content": "Vector search finds semantically similar items..."},
vector=np.random.rand(384).tolist(), # replace with a real embedding
)
# Batch insert — more efficient for large datasets
with articles.batch.dynamic() as batch:
for item in dataset:
batch.add_object(
properties={"title": item["title"], "content": item["content"]},
vector=item["embedding"],
)
Run a Similarity Query
query_vector = np.random.rand(384).tolist() # replace with a real query embedding
results = articles.query.near_vector(
near_vector=query_vector,
limit=5,
return_properties=["title", "content"],
)
for obj in results.objects:
print(obj.properties["title"])
Let the Database Handle Vectorization
Free vector databases with built-in vectorizer support can generate embeddings automatically — removing the need to call an embedding API separately in your Python code. Configure a vectorizer when creating the collection and the database handles embedding at both insert and query time:
client.collections.create(
name="Document",
vectorizer_config=Configure.Vectorizer.text2vec_openai(),
properties=[
Property(name="body", data_type=DataType.TEXT),
]
)
docs = client.collections.get("Document")
docs.data.insert(properties={"body": "The database generates the embedding automatically."})
Hybrid Search (Vector + Keyword)
Many free vector databases support hybrid search — combining dense vector similarity with BM25 keyword scoring. This improves recall on RAG and semantic search workloads:
results = articles.query.hybrid(
query="how to run vector search in production",
limit=5,
return_properties=["title"],
)
for obj in results.objects:
print(obj.properties["title"])
Always Close the Connection
client.close()
gRPC-based clients maintain a connection pool. Closing it explicitly when done prevents resource leaks, especially in long-running scripts or applications.
Frequently Asked Questions
Do I need to manage embeddings myself?
Not necessarily. Free vector databases with built-in vectorizer modules can call embedding APIs (OpenAI, Cohere, HuggingFace) or run local models on your behalf. If you prefer to use your own model, set the vectorizer to none and pass pre-computed vectors at insert and query time.
What is the fastest way to insert large datasets?
Use batch inserts rather than single-object inserts. Most Python clients provide a batch context manager that buffers objects and sends them in bulk over gRPC, which is orders of magnitude faster than inserting one at a time over REST.
Can I use a free vector database without running Docker?
Yes. Free cloud sandboxes are available with no infrastructure setup — sign up, get a URL and API key, and connect from Python in seconds.