Skip to content

Search API

The Search API enables vector and full-text search across the Unique AI knowledge base for Retrieval-Augmented Generation (RAG).

Overview

Perform semantic search with support for:

  • Vector search
  • Combined vector + full-text search
  • Metadata filtering with UniqueQL
  • Reranking
  • Score thresholds
  • Multi-scope search

Methods

unique_sdk.Search.create - Search the knowledge base

Search the knowledge base with various filtering and ranking options.

Search Types:

  • VECTOR - Semantic vector search
  • FULL_TEXT- Full text search in elastic search (BM25)
  • POSTGRES_FULL_TEXT - Full text search in elastic search (BM25)
  • COMBINED - Vector + full-text search for enhanced precision

Parameters:

  • searchString (str, required) - Query text to search for
  • searchType (Literal["VECTOR","FULL_TEXT", "POSTGRES_FULL_TEXT", "COMBINED" ], required) - Search mode
  • chatId (str, optional) - Include chat documents in search scope
  • scopeIds (List[str], optional) - List of scope IDs to search within
  • chatOnly (bool, optional) - Restrict search to chat documents only
  • limit (int, optional) - Maximum number of results (default: 20, max: 1000)
  • page (int, optional) - Page number for pagination (default: 1)
  • scoreThreshold (float, optional) - Minimum similarity score (recommended: 0)
  • language (str, optional) - Language for full-text search (e.g., "English")
  • reranker (Dict[str, Any], optional) - Reranker configuration (e.g., {"deploymentName": "my_deployment"})
  • metaDataFilter (Dict[str, Any], optional) - UniqueQL metadata filter
  • contentIds (List[str], optional) - Filter search to specific content IDs
  • qdrantParams (QdrantSearchParams, optional) - Qdrant search parameters for fine-tuning vector search behavior

Returns:

Returns a list of Search objects.

Example - Basic Search:

search = unique_sdk.Search.create(
    user_id=user_id,
    company_id=company_id,
    chatId=chat_id,
    searchString="What is the meaning of life?",
    searchType="VECTOR",
    limit=20,
    scoreThreshold=0
)

Example - Combined Search with Filtering:

search = unique_sdk.Search.create(
    user_id=user_id,
    company_id=company_id,
    searchString="quarterly financial performance",
    searchType="COMBINED",
    scopeIds=["scope_abc123", "scope_def456"],
    language="English",
    limit=50,
    page=1,
    scoreThreshold=0.7,
    reranker={"deploymentName": "my_deployment"}
)

Example - Search with Metadata Filter:

from unique_sdk import UQLOperator, UQLCombinator

search = unique_sdk.Search.create(
    user_id=user_id,
    company_id=company_id,
    searchString="project updates",
    searchType="COMBINED",
    metaDataFilter={
        UQLCombinator.AND: [
            {
                "path": ["year"],
                "operator": UQLOperator.EQUALS,
                "value": "2024"
            },
            {
                "path": ["department"],
                "operator": UQLOperator.CONTAINS,
                "value": "engineering"
            }
        ]
    },
    limit=30
)

Example - Chat-Only Search:

# Search only within uploaded chat documents
search = unique_sdk.Search.create(
    user_id=user_id,
    company_id=company_id,
    chatId=chat_id,
    searchString="contract terms",
    searchType="VECTOR",
    chatOnly=True,
    limit=10
)

Example - Search with Qdrant Parameters:

# Use exact search for deterministic results (brute-force, no HNSW)
search = unique_sdk.Search.create(
    user_id=user_id,
    company_id=company_id,
    searchString="quarterly report",
    searchType="VECTOR",
    qdrantParams={
        "exact": True,
    }
)

# Or tune HNSW for higher accuracy (hnsw_ef must be >= limit to take effect)
search = unique_sdk.Search.create(
    user_id=user_id,
    company_id=company_id,
    searchString="quarterly report",
    searchType="VECTOR",
    limit=50,
    qdrantParams={
        "hnsw_ef": 128,  # effective because 128 >= 50
    }
)

Return Types

The Search object represents a single search result

Fields:

  • id (str) - Unique search result identifier
  • chunkId (str) - Chunk identifier within the document
  • text (str) - Chunk text content
  • createdAt (str) - Creation timestamp (ISO 8601)
  • updatedAt (str) - Last update timestamp (ISO 8601)
  • url (str | None) - Content URL
  • title (str | None) - Document title
  • key (str | None) - File key/name with page numbers (e.g., "document.pdf : 5,6,7")
  • order (int) - Chunk order in document
  • startPage (int) - Starting page number
  • endPage (int) - Ending page number
  • metadata (Dict[str, Any] | None) - Custom metadata dictionary
  • score (float, optional) - Similarity score (may be present in API response)

Returned by: Search.create()

QdrantSearchParams

Qdrant search parameters for fine-tuning vector search behavior

Fields:

  • hnsw_ef (int | None) - Custom HNSW ef parameter (minimum: 1). Higher values improve accuracy at the cost of speed. Note: If limit exceeds hnsw_ef, Qdrant uses limit as the effective ef value, making your hnsw_ef setting irrelevant. For example, hnsw_ef=128 with limit=200 behaves as if ef=200.
  • exact (bool | None) - If true, performs exact brute-force search (no HNSW). Note that hnsw_ef is ignored when exact=True.
  • quantization (QdrantQuantizationParams | None) - Quantization settings
  • consistency (Literal["majority", "quorum", "all"] | int | None) - Read consistency level

Used by: Search.create() via qdrantParams parameter

QdrantQuantizationParams

Quantization parameters for Qdrant search

Fields:

  • ignore (bool | None) - If true, quantization is ignored during search
  • rescore (bool | None) - If true, original vectors are used for rescoring
  • oversampling (float | None) - Oversampling factor (minimum: 1). Higher values improve accuracy at the cost of speed

Used by: QdrantSearchParams.quantization

Best Practices

Use Combined Search for Better Results
# Combined search is usually better than vector-only
search = unique_sdk.Search.create(
    user_id=user_id,
    company_id=company_id,
    searchString=query,
    searchType="COMBINED",  # Recommended
    scoreThreshold=0  # Include all results, let score guide ranking
)
Enhance Queries with Context
# Use SearchString API to improve queries
from unique_sdk import SearchString

# Transform user query with chat context
enhanced = SearchString.create(
    user_id=user_id,
    company_id=company_id,
    prompt="Who is the author?",  # Vague query
    chat_id=chat_id  # Adds context from conversation
)

# Now search with enhanced query
search = unique_sdk.Search.create(
    user_id=user_id,
    company_id=company_id,
    searchString=enhanced.searchString,  # "Who is the author of Hitchhiker's Guide?"
    searchType="VECTOR"
)