Skip to main content

A decentralized & distributed vector database network

Project description

Vectrs - Decentralized & Distributed Vector Database Downloads

Overview

Vectrs is a decentralized & distributed vector database designed for efficient storage and retrieval of vector embeddings. It combines P2P networking with advanced vector operations, RAG capabilities, and graph-based relationships, making it ideal for AI-powered distributed applications.

Features

  • Distributed Architecture

    • P2P network with load balancing
    • Data replication for fault tolerance
    • Horizontal scalability
  • Vector Operations

    • Multiple similarity metrics (L2, cosine, etc.)
    • Different index types (HNSW, Graphine)
    • Batch vector operations
    • Vector metadata support
  • Graph Capabilities

    • Vector relationships management
    • Graph-based queries
    • Customizable relationship types
  • AI Integration

    • RAG (Retrieval-Augmented Generation) workflow
    • Custom agent creation and management
    • Task analysis capabilities

Installation

pip install vectrs

Usage

Basic Operations

  1. Initialize and Start a Node
import asyncio
from vectrs.network import KademliaNode
from vectrs.database import VectorDBManager

async def start_node():
    # Initialize node
    node = KademliaNode(host='127.0.0.1', port=8468)
    db_manager = VectorDBManager()
    node.set_local_db_manager(db_manager)
    
    # Start node
    await node.start()
    
    # Optional: Connect to existing network
    await node.bootstrap('bootstrap_host', 8468)
    return node

# Run the node
node = asyncio.run(start_node())
  1. Create Database
async def create_database(node):
    db_manager = VectorDBManager()
    # Create database with HNSW index
    db_id = db_manager.create_database(
        dim=1024,
        space=SimilarityMetric.L2,
        max_elements=10000,
        index_type=IndexType.HNSW
    )
    return db_id

db_id = asyncio.run(create_database(node))
  1. Vector Operations
import numpy as np

async def vector_operations(node, db_id):
    # Add vector
    vector = np.random.rand(1024).astype(np.float32)
    metadata = {"description": "example vector"}
    await node.add_vector(db_id, "vector1", vector, metadata)

    # Query vector
    results = await node.query_vector(db_id, "vector1", k=10)
    
    # Batch add vectors
    vectors = {
        "vec1": np.random.rand(1024).astype(np.float32),
        "vec2": np.random.rand(1024).astype(np.float32)
    }
    metadata_list = [{"desc": "vec1"}, {"desc": "vec2"}]
    await node.batch_add_vectors(db_id, vectors, metadata_list)
    
    # Update vector
    new_vector = np.random.rand(1024).astype(np.float32)
    await node.update_vector(db_id, "vector1", new_vector, {"updated": True})
    
    # Delete vector
    await node.delete_vector(db_id, "vector1")

asyncio.run(vector_operations(node, db_id))

Graph Operations

async def graph_operations(node, db_id):
    # Add relationship between vectors
    await node.add_relationship(
        db_id, 
        "vector1", 
        "vector2", 
        relationship_type="similar_to"
    )
    
    # Get relationships
    relationships = await node.get_relationships(db_id, "vector1")
    
    # Graph-based query
    results = await node.query_with_graph(
        db_id,
        "vector1",
        k=10,
        max_depth=2
    )

asyncio.run(graph_operations(node, db_id))

AI and RAG Features

from vectrs.swarm import Swarm

async def ai_operations(node):
    # Initialize Swarm
    swarm = Swarm(node.db_manager, host='127.0.0.1', port=8468)
    await swarm.initialize()
    
    # Run RAG workflow
    result = await swarm.run_rag_workflow(
        query="What is the relationship between these vectors?"
    )
    
    # Create and manage AI agent
    agent = await swarm.create_custom_agent(
        agent_type="analyzer",
        agent_id="agent1"
    )
    
    # Check agent status
    status = await swarm.get_agent_status("agent1")
    
    # Analyze task
    analysis = await swarm.analyze_task({
        "type": "vector_analysis",
        "data": "Sample data"
    })

asyncio.run(ai_operations(node))

Advanced Features

Graphine Search

async def graphine_search(node, db_id):
    results = await node.graphine_search(
        db_id=db_id,
        vector_id="vector1",
        k=10,
        ef=50
    )
    return results

asyncio.run(graphine_search(node, db_id))

API Reference

For detailed API documentation and advanced usage, visit our documentation.

Contributing

Contributions are welcome! Please check our contribution guidelines.

License

Apache License 2.0. See LICENSE for details.

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vectrs-0.3.0.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vectrs-0.3.0-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file vectrs-0.3.0.tar.gz.

File metadata

  • Download URL: vectrs-0.3.0.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.5

File hashes

Hashes for vectrs-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b9b317ab271f7670a34ae4d5ccf4d7729c3478c9fb5a978074851576e4f0fe21
MD5 35ab32041e2f653bf9892c148eb46c0a
BLAKE2b-256 1d6f5a24906ac603e28f3ff7d1c6f83b4ac92af9e6601ec1432656eacba82996

See more details on using hashes here.

File details

Details for the file vectrs-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: vectrs-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.5

File hashes

Hashes for vectrs-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b3ee22caeec5b6716cb0887889c3605d97d62cecf473849922a19612d2589f6
MD5 aa5e2fcd1946bd107eca1014237e41e9
BLAKE2b-256 239411b82a01ced2b0e395525769b62760b5cdc8c57e4fc5b83435bcb664c1f1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page