Skip to main content

Async client for Vector Store API with comprehensive JSON-RPC support

Project description

Vector Store Client

Python 3.8+ License: MIT PyPI version

Async client for Vector Store API with comprehensive JSON-RPC support. Provides high-level interface for all vector store operations including chunk creation, search, deletion, and system management.

Features

  • Fully Async: Built with asyncio and httpx for high-performance async operations
  • JSON-RPC 2.0: Complete support for JSON-RPC 2.0 protocol
  • Type Safety: Full type hints and Pydantic models for data validation
  • Comprehensive API: Support for all Vector Store operations
  • Error Handling: Detailed exception hierarchy with meaningful error messages
  • Batch Operations: Efficient batch processing for large datasets
  • Connection Management: Automatic connection pooling and retry logic
  • Logging: Built-in logging for debugging and monitoring

Installation

pip install vector-store-client

Quick Start

import asyncio
from vector_store_client import VectorStoreClient, SemanticChunk, ChunkType, LanguageEnum

async def main():
    # Create client
    client = await VectorStoreClient.create("http://localhost:8007")
    
    # Check server health
    health = await client.health_check()
    print(f"Server status: {health.status}")
    
    # Create a chunk
    chunk = SemanticChunk(
        body="Python is a high-level programming language.",
        text="Python is a high-level programming language.",
        type=ChunkType.DOC_BLOCK,
        language=LanguageEnum.EN,
        title="Python Introduction"
    )
    
    result = await client.create_chunks([chunk])
    print(f"Created chunk: {result.uuids[0]}")
    
    # Search chunks
    results = await client.search_chunks("programming language", limit=5)
    for chunk in results:
        print(f"Found: {chunk.title}")
    
    await client.close()

asyncio.run(main())

API Reference

Client Creation

# Factory method (recommended)
client = await VectorStoreClient.create("http://localhost:8007")

# Direct instantiation
client = VectorStoreClient("http://localhost:8007")

Health and System

# Check server health
health = await client.health_check()

# Get help information
help_info = await client.get_help()

# Get/set configuration
config = await client.get_config("server.version")
await client.set_config("search.limit", 50)

Chunk Operations

# Create chunks
chunks = [
    SemanticChunk(
        body="Your text content here",
        text="Your text content here",
        type=ChunkType.DOC_BLOCK,
        language=LanguageEnum.EN
    )
]
result = await client.create_chunks(chunks)

# Search chunks
results = await client.search_chunks(
    search_str="your search query",
    metadata_filter={"category": "articles"},
    limit=10
)

# Delete chunks
await client.delete_chunks({"type": "temporary"})

Utility Methods

# Create single text chunk
uuid = await client.create_text_chunk(
    text="Simple text content",
    chunk_type=ChunkType.DOC_BLOCK
)

# Search by text (simplified interface)
results = await client.search_by_text("query", limit=5)

# Find duplicate UUIDs
duplicates = await client.find_duplicate_uuids()

# Force delete by UUIDs
await client.force_delete_by_uuids(["uuid1", "uuid2"])

Data Models

SemanticChunk

The main data model for chunks with comprehensive metadata:

chunk = SemanticChunk(
    # Required fields
    body="Original text content",
    text="Normalized text for search",
    
    # Auto-generated fields
    uuid="auto-generated-uuid",
    source_id="auto-generated-source-id",
    language=LanguageEnum.EN,
    type=ChunkType.DOC_BLOCK,
    sha256="auto-generated-hash",
    created_at="auto-generated-timestamp",
    embedding=[0.1, 0.2, ...],  # 384-dimensional vector
    
    # Optional fields
    title="Chunk title",
    category="Business category",
    tags=["tag1", "tag2"],
    session_id="session-uuid",
    message_id="message-uuid",
    summary="Auto-generated summary",
    status=ChunkStatus.ACTIVE,
    metadata={"custom": "data"}
)

SearchResult

Search results with relevance information:

result = SearchResult(
    chunk=SemanticChunk(...),
    relevance_score=0.95,
    distance=0.05,
    rank=1,
    highlight="...highlighted text...",
    metadata={"search_metadata": "value"}
)

Error Handling

The client provides a comprehensive exception hierarchy:

from vector_store_client.exceptions import (
    VectorStoreError,      # Base exception
    ConnectionError,       # Network/connection issues
    ValidationError,       # Data validation failures
    JsonRpcError,         # JSON-RPC protocol errors
    ServerError,          # Server-side errors
    NotFoundError,        # Resource not found
    DuplicateError        # Duplicate resource errors
)

try:
    await client.create_chunks(chunks)
except ValidationError as e:
    print(f"Validation failed: {e.field_errors}")
except ConnectionError as e:
    print(f"Connection failed: {e}")
except ServerError as e:
    print(f"Server error: {e.server_message}")

Configuration

Logging

import logging
from vector_store_client.utils import setup_logging

# Setup logging
logger = setup_logging(
    level="INFO",
    format_string="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    log_file="vector_store.log"
)

# Use with client
client = VectorStoreClient("http://localhost:8007", logger=logger)

Timeouts and Retries

# Custom timeout
client = await VectorStoreClient.create(
    "http://localhost:8007",
    timeout=60.0
)

# Retry logic is built-in for connection errors
# Custom retry can be implemented using utils.retry_with_backoff

Examples

See the examples/ directory for usage examples:

  • simple_example.py - Basic operations (recommended for beginners)
  • working_api_example.py - Complete API demonstration with real methods
  • advanced_usage.py - Advanced features and patterns
  • comprehensive_api_example.py - Legacy example (may contain non-working methods)

Development

Installation

git clone https://github.com/vasilyvz/vector_store_client.git
cd vector_store_client
pip install -e .

Testing

# Run tests
pytest

# Run with coverage
pytest --cov=vector_store_client

# Run specific test file
pytest tests/test_client.py

Code Quality

# Format code
black vector_store_client/

# Sort imports
isort vector_store_client/

# Type checking
mypy vector_store_client/

# Linting
flake8 vector_store_client/

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Vasily Zdanovskiy

Changelog

See CHANGELOG.md for a list of changes and version history.

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

vector_store_client-2.0.0.0.tar.gz (322.7 kB view details)

Uploaded Source

Built Distribution

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

vector_store_client-2.0.0.0-py3-none-any.whl (166.1 kB view details)

Uploaded Python 3

File details

Details for the file vector_store_client-2.0.0.0.tar.gz.

File metadata

  • Download URL: vector_store_client-2.0.0.0.tar.gz
  • Upload date:
  • Size: 322.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for vector_store_client-2.0.0.0.tar.gz
Algorithm Hash digest
SHA256 d13c367fe3f58e69837b42f8491a402cd60780242250d11d8193ddc42de6a72d
MD5 a2e7bc5a4f0c54245550f7d812546ec7
BLAKE2b-256 e84a92519b57e44f160eec391374a69c1f33ae239ccface881e2507ade2b8f4a

See more details on using hashes here.

File details

Details for the file vector_store_client-2.0.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vector_store_client-2.0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b23cc0200478f2044132b6cf55882e7628f96d188fa2bd6ae19608afffd5b6f
MD5 9a3744ed378db86a73e6efcfeb4afab9
BLAKE2b-256 174ff2dfd80803f5adf638d6d1b332e6b8e7837b151c13c92443f9f209069f2d

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