[Feature Request]: Add a pgvector search enrichment handler for Postgres, AlloyDB and Cloud SQL in ml.rag

オープン
#41,713 コメント 2 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@karthik-0306 がすでに取り組んでいます。

2026年11月27日 から。

  • #41722 @karthik-0306 による — オープン

評価

この issue はまだ評価されていません。

説明

new feature P2 python
What would you like to happen?

apache_beam.ml.rag can write embeddings to Postgres, AlloyDB and Cloud SQL for PostgreSQL (ml/rag/ingestion/postgres.py, alloydb.py, cloudsql.py), but it can't search them. The search handlers in ml/rag/enrichment/ cover BigQuery, Milvus and Qdrant only. A pipeline that stores its vectors with pgvector has no built-in way to do the retrieval step.

CloudSQLEnrichmentHandler with a CustomQueryConfig doesn't fill the gap. _process_single_request keeps only result.first(), so a top-k query returns just the nearest row and drops the rest without an error:

query_config = CustomQueryConfig(
    query_fn=lambda row: 'SELECT id, content FROM docs ORDER BY dist LIMIT 3')
# The query returns rows a, b and c; the handler returns only:
# (Row(id='q1', ...), Row(id='a', content='first'))

Proposal: a PostgresVectorSearchEnrichmentHandler in ml/rag/enrichment/postgres_search.py, used with Enrichment like the other search handlers:

  • Parameters: table name, embedding column, columns to return, neighbor_count, distance metric (cosine <=>, L2 <->, inner product <#>), and an optional filter.
  • Queries are parameterized, and table and column names are quoted, so no input text reaches the SQL as-is.
  • Each input gets its k nearest neighbors, added to the item in the same way as the existing search handlers.
  • Connections work for plain Postgres, AlloyDB and Cloud SQL.
  • Vectors are passed as pgvector text literals, so no new Python dependency is needed.
  • Unit tests, plus an integration test on the pgvector/pgvector image with testcontainers, so it can run without a cloud database.

Questions before I start:

  1. Is a Postgres search handler something you'd accept in ml.rag?
  2. Should it share connection settings with CloudSQLEnrichmentHandler, or with the ingestion configs?
  3. Should batched requests be in the first PR, or come as a follow-up?

I'm willing to work on this and open a PR once the design is agreed.

Version: master at 0c549fa6c8 (2.79.0.dev)

Issue Priority

Priority: 2 (default / most feature requests should be filed as P2)

Issue Components
  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam YAML
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Infrastructure
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Prism Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner
主要言語
Java
スター
8.7k
フォーク
4.8k
平均マージ
3日 16時間
マージ済み PR(30日)
445

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/beam のほかの issue

apache/beam の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。