Skip to content

[Enhancement] Support multi-domain metadata filtering in PgVector vector store queries #5720

@sachin-gupta99

Description

@sachin-gupta99

Summary

When using spring-ai-starter-vector-store-pgvector to store embeddings from multiple domains (e.g., activities, nutrition, user profiles) in a single vector store, there is no first-class support for domain-level filtering during similarity search.

Current behavior

Documents can be stored with metadata, and SearchRequest supports a FilterExpression. However, filtering by a custom domain field requires manually constructing filter expressions, and the ergonomics could be improved for multi-domain RAG use cases.

Use case

In my fitness tracking microservice, I store embeddings from three domains in a single PgVector table:

  • domain: "activity" — workout/exercise data
  • domain: "nutrition" — food/calorie entries
  • domain: "user" — user profile context

When the AI chat endpoint performs RAG, I need to retrieve documents across all three domains with the ability to:

  1. Filter by specific domain(s) — e.g., only activity + nutrition for a calories question
  2. Weight domains differently in relevance scoring
  3. Set per-domain result limits (e.g., max 5 activities, max 3 nutrition entries)

Proposal

  • Add a convenience method on SearchRequest for domain/namespace filtering (e.g., .withDomains("activity", "nutrition"))
  • Support per-domain topK limits in a single search call
  • Optionally, support domain-level boosting in similarity scoring

This would make multi-domain RAG architectures significantly easier to build with Spring AI.

Spring Boot version: 4.0.2
Spring AI version: 2.0.0-M2
Vector store: PgVector

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions