Skip to content

feat(ai): implement vector similarity search with spring ai and pgvector - #389

Merged
rashidi merged 4 commits into
masterfrom
ai/pgvector
Sep 5, 2026
Merged

rashidi merged 4 commits into
masterfrom
ai/pgvector

Conversation

@rashidi

@rashidi rashidi commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Overview

Adds a new tutorial module, ai-pgvector, demonstrating how to implement semantic vector similarity search in Spring Boot using Spring AI and PostgreSQL's pgvector extension.

Motivation & Architecture

Rather than introducing a dedicated, standalone vector database that complicates deployment and data synchronization, pgvector brings vector embeddings directly into PostgreSQL. This preserves ACID guarantees, simplifies backups and migrations, and allows combining semantic similarity search with relational filters.

Key Changes

  • Module Setup:
    • Added ai-pgvector submodule to settings.gradle.kts and root README.adoc.
    • Configured build.gradle.kts with spring-ai-starter-vector-store-pgvector, PostgreSQL driver, and Testcontainers dependencies.
  • Service Implementation (zin.rashidi.boot.ai.pgvector):
    • DocumentItem: Domain record for ingesting text content and metadata attributes.
    • SemanticSearchService: Encapsulates document ingestion and similarity search using Spring AI's VectorStore and SearchRequest.
    • Configured HNSW index and COSINE_DISTANCE metric in application.properties.
  • Testing with Testcontainers:
    • TestcontainersConfiguration: Configured an ephemeral pgvector/pgvector:pg16 container using @ServiceConnection.
    • SemanticSearchIntegrationTests: Implemented a deterministic, keyword-aware in-memory EmbeddingModel to ensure tests run hermetically in CI without external LLM API keys or network latency.
  • Documentation:
    • Added complete tutorial article in ai-pgvector/README.adoc.

Verification

  • Verified module build and tests locally:
    ./gradlew :ai-pgvector:build

@rashidi rashidi added the enhancement New feature or request label Sep 5, 2026
@rashidi
rashidi merged commit f85e37c into master Sep 5, 2026
4 checks passed
@rashidi
rashidi deleted the ai/pgvector branch September 5, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant