Quick Start

Get up and running with Feather in under 5 minutes. This guide will walk you through creating your first vector database.

Step 1: Create a Database

Start by creating a new Feather database. You need to specify the dimension of your vectors:

Python
from feather import DB

# Create a database for 384-dimensional vectors
# (common for sentence transformers)
db = DB.open("embeddings.feather", dim=384)

Step 2: Add Vectors

Add vectors to your database. Each vector needs a unique ID:

Python
import numpy as np

# Generate or load your vectors
vectors = [
    np.random.rand(384).astype(np.float32) for _ in range(1000)
]

# Add vectors with IDs
for i, vector in enumerate(vectors):
    db.add(i, vector)

print(f"Added {len(vectors)} vectors")

Step 3: Build Index

Build the HNSW index for fast similarity search:

Python
# Build the index (optional - auto-built on first search)
db.build_index()

# Or build with custom parameters
db.build_index(M=16, ef_construction=200)

Step 4: Search

Search for similar vectors:

Python
# Create a query vector
query = np.random.rand(384).astype(np.float32)

# Search for top 5 most similar vectors
results = db.search(query, k=5)

# Results are (id, distance) tuples
for vector_id, distance in results:
    print(f"ID: {vector_id}, Distance: {distance:.4f}")

Step 5: Save

Save your database to disk:

Python
# Save to disk
db.save()

# Database is now persisted in "embeddings.feather"
# You can load it later with:
# db = DB.open("embeddings.feather", dim=384)

Complete Example

Here's a complete example using sentence embeddings:

Python
from feather import DB
from sentence_transformers import SentenceTransformer
import numpy as np

# Load embedding model
model = SentenceTransformer('all-MiniLM-L6-v2')

# Create database
db = DB.open("docs.feather", dim=384)

# Add documents
documents = [
    "Feather is the SQLite for vectors",
    "Vector search so light, it runs in your pocket",
    "Embed vector search in any app"
]

for i, doc in enumerate(documents):
    embedding = model.encode(doc).astype(np.float32)
    db.add(i, embedding)

# Save
db.save()

# Search
query = "What is Feather?"
query_embedding = model.encode(query).astype(np.float32)
results = db.search(query_embedding, k=2)

for id, dist in results:
    print(f"Found: {documents[id]} (distance: {dist:.4f})")