Apache Answer Plugin: pgvector Vector Search

This plugin enables semantic/vector search in Apache Answer using PostgreSQL with the pgvector extension.

Prerequisites

  • PostgreSQL 12+ with the pgvector extension installed
  • An OpenAI-compatible embedding API (e.g., OpenAI, Azure OpenAI, or any compatible provider)

Installation

Build Apache Answer with this plugin:

./answer build --with github.com/apache/answer-plugins/vector-search-pgvector

Configuration

After enabling the plugin in the Admin UI (Admin > Plugins > Vector Search), configure the following fields:

FieldDescriptionExample
DSNPostgreSQL connection stringpostgres://user:pass@localhost:5432/answer?sslmode=disable
Embedding API HostOpenAI-compatible API base URLhttps://api.openai.com
Embedding API KeyAPI key for the embedding servicesk-...
Embedding ModelModel name for generating embeddingstext-embedding-3-small
Embedding Levelquestion embeds question + all answers + comments together; answer embeds each answer separatelyquestion
Similarity ThresholdMinimum cosine similarity score (0-1). Default 0 means no filtering0.5

How It Works

  • Embedding dimensions are auto-detected from the configured model. No manual dimension configuration is needed.
  • On first configuration, the plugin creates a table answer_vector_embeddings with a vector column matching the detected dimensions.
  • If the embedding model changes and produces different dimensions, the table is automatically dropped and recreated.
  • Uses cosine similarity (<=> operator) for vector search.
  • A full sync of all questions/answers is triggered when the plugin starts.

Database Setup

Ensure the pgvector extension is installed in your PostgreSQL database:

CREATE EXTENSION IF NOT EXISTS vector;

License

Apache License 2.0