Skip to main content

DB2VectorSearchTool

Description

Perform semantic vector similarity searches against IBM Db2 tables using the native VECTOR_DISTANCE function. Supports configurable distance metrics, OpenAI or custom embeddings, metadata filtering, and result shaping.

Installation

Or with uv:

Environment Variables

Basic Usage

Full Semantic Search Workflow

Tool Parameters

Supported Distance Metrics

The following values map directly to the Db2 VECTOR_DISTANCE function:
  • COSINE
  • EUCLIDEAN
  • EUCLIDEAN_SQUARED
  • DOT
  • HAMMING
  • MANHATTAN
Reference: IBM Db2 VECTOR_DISTANCE documentation

Schema Parameters (per query)

Return Format

On error:

Metadata Filtering

filter_by and filter_value must always be provided together. Providing only one raises a validation error.

Custom Embeddings

Use any embedding model by supplying a custom_embedding_fn:
When custom_embedding_fn is provided, OPENAI_API_KEY is not required.

Security Features

  • SQL identifier validation (table, column names must match ^[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z][A-Za-z0-9_]*)?$)
  • Parameterised SQL queries — values never interpolated into SQL strings
  • Distance metric whitelist — only valid Db2 metric names accepted