Introduction to Vector Databases and Generative AI
Demo Setting up a Vector Database
Guide to running Qdrant locally with Docker and Jupyter, using Python client to create collections, insert embeddings, and perform basic vector similarity queries.
Welcome! This walkthrough demonstrates how simple it is to run a vector database locally using Qdrant and connect to it from a Jupyter Notebook with the official Python client. We’ll cover a minimal local setup (Docker), a ready-to-run container image that bundles Qdrant + Jupyter, and example Python snippets to create collections, insert embeddings, and run basic queries.This guide is ideal for developers experimenting with embeddings, similarity search, or building retrieval-augmented generation (RAG) prototypes.
Add at minimum the following to your requirements.txt:
qdrant-clientnotebookjupyterlab
You can extend this list with your favorite embedding libraries (Transformers, sentence-transformers, OpenAI client, etc.) depending on how you generate embeddings.
Define a collection to store vectors and recreate it (note: this deletes an existing collection with the same name before creating a new one). Use VectorParams to set the vector dimensionality and distance metric:
from qdrant_client.models import Distance, VectorParamsclient.recreate_collection( collection_name="demo_collection", vectors_config=VectorParams(size=4, distance=Distance.COSINE),)print("Recreated collection: demo_collection")
recreate_collection will delete an existing collection with the same name. Use with caution in production environments to avoid accidental data loss.
A vector is a list of numeric values (floats) representing an embedding for a piece of data (text, image, etc.). The vector dimensionality must match the size specified in VectorParams. Vector similarity search (nearest-neighbor search) is based on distance metrics such as cosine or euclidean.