Skip to main content
Should filters match results where at least one condition is true. Use should filters to broaden search scope while maintaining control over result types, such as searching across multiple categories.
Before you begin, make sure you have a running VectorAI DB instance and a products collection with 128-dimensional vectors and payload fields: category (string) and price (float).
from actian_vectorai import VectorAIClient, FilterBuilder, Field
import random

# Connect to VectorAI DB server
with VectorAIClient("localhost:50051") as client:
    # Generate query vector
    query_vector = [random.gauss(0, 1) for _ in range(128)]
    
    # Filter: category should be electronics OR books OR clothing
    filter = FilterBuilder()\
        .should(Field("category").eq("electronics"))\
        .should(Field("category").eq("books"))\
        .should(Field("category").eq("clothing"))\
        .build()
    
    # Search with filter
    results = client.points.search(
        "products",  # Collection name
        vector=query_vector,  # Query vector
        limit=10,  # Maximum results
        filter=filter  # Apply filter
    )
    
    # Display results
    for result in results:
        print(f"ID: {result.id}")
        print(f"Category: {result.payload['category']}")
        print(f"Price: ${result.payload['price']}")
        print("-" * 50)
Each result includes these fields:
  • id: The unique identifier of the matching point.
  • score: Similarity score based on vector distance.
  • payload: Full metadata dictionary for the matching point.