jeff3071 opened a new pull request, #71437:
URL: https://github.com/apache/airflow/pull/71437

   
    <!-- SPDX-License-Identifier: Apache-2.0
         https://www.apache.org/licenses/LICENSE-2.0 -->
   
   <!--
   Thank you for contributing!
   
   Please provide above a brief description of the changes made in this pull 
request.
   Write a good git commit message following this guide: 
https://chris.beams.io/posts/git-commit/
   
   Please make sure that your code changes are covered with tests.
   And in case of new features or big changes remember to adjust the 
documentation.
   
   For user-facing UI changes, please attach before/after screenshots (or a 
short
   screen recording) so reviewers can assess the visual impact.
   
   Feel free to ping (in general) for the review if you do not see reaction for 
a few days
   (72 Hours is the minimum reaction time you can expect from volunteers) - we 
sometimes miss notifications.
   
   In case of an existing issue, reference it using one of the following:
   
   * closes: #ISSUE
   * related: #ISSUE
   -->
   
   ## Why
   
   `PydanticAIHook` supports Airflow-managed credentials and custom base URLs 
for LLMs, including OpenAI-compatible self-hosted endpoints, but it does not 
expose pydantic-ai's embedding API. Users cannot create a pydantic-ai 
`Embedder`.
   
   ## What
   
   - Add `embed_model_id` and `extra["embed_model"]` resolution to 
`PydanticAIHook`.
   - Add a cached `get_embedder()` that returns a pydantic-ai `Embedder` 
configured with the connection's credentials and base URL.
   - Share provider-factory creation between LLM and embedding model resolution 
so provider-specific hooks keep their existing authentication mapping.
   
   
   ## Testing
   
   - Manual Airflow UI verification against a vLLM-hosted 
`Qwen/Qwen3-Embedding-0.6B` OpenAI-compatible endpoint:
     - one query vector and two document vectors returned;
     - all vectors dimension is 1024;
   
   `serve command`
   ```bash
   vllm serve Qwen/Qwen3-Embedding-0.6B     --runner pooling     --host 0.0.0.0 
    --port 8000     --api-key EMPTY     --max-model-len 1024 
--gpu-memory-utilization 0.8
   ```
   
   <!-- Attach the Airflow task success/XCom screenshot here. -->
   
   <img width="905" height="313" alt="test" 
src="https://github.com/user-attachments/assets/9c989f8c-1496-4560-9a8b-78e3e92cd4ee";
 />
   
   
   test dag
   ```python
   from __future__ import annotations
   
   import math
   
   from airflow.providers.common.ai.hooks.pydantic_ai import PydanticAIHook
   from airflow.sdk import dag, task
   
   CONN_ID = "pydanticai_qwen_embedding"
   EXPECTED_DIMENSION = 1024
   
   @dag(
       dag_id="qwen3_self_hosted_embedding",
       schedule=None,
       catchup=False,
       tags=["manual", "pydantic-ai", "embedding", "self-hosted"],
   )
   def qwen3_self_hosted_embedding():
       @task
       def verify_embedding() -> dict[str, int | str | bool]:
           hook = PydanticAIHook(llm_conn_id=CONN_ID)
           embedder = hook.get_embedder()
   
           query_result = embedder.embed_query_sync("How does Apache Airflow 
orchestrate workflows?")
           document_result = embedder.embed_documents_sync(
               [
                   "Apache Airflow is a platform for developing and monitoring 
batch workflows.",
                   "Qwen3 Embedding converts text into dense vector 
representations.",
               ]
           )
   
           if len(query_result.embeddings) != 1 or 
len(document_result.embeddings) != 2:
               raise ValueError(
                   "Unexpected vector count: "
                   f"query={len(query_result.embeddings)}, 
documents={len(document_result.embeddings)}"
               )
   
           vectors = [*query_result.embeddings, *document_result.embeddings]
           dimensions = {len(vector) for vector in vectors}
           if dimensions != {EXPECTED_DIMENSION}:
               raise ValueError(f"Expected {EXPECTED_DIMENSION}-dimension 
vectors, got {sorted(dimensions)}")
           if not all(math.isfinite(value) for vector in vectors for value in 
vector):
               raise ValueError("Embedding response contains non-finite 
values.")
   
           return {
               "model": query_result.model_name,
               "provider": query_result.provider_name,
               "dimension": next(iter(dimensions)),
               "query_vectors": len(query_result.embeddings),
               "document_vectors": len(document_result.embeddings),
               "embedder_cached": embedder is hook.get_embedder(),
           }
   
       verify_embedding()
   
   
   qwen3_self_hosted_embedding()
   ```
   
   `log`
   ```
   
/root/airflow/logs/dag_id=qwen3_self_hosted_embedding/run_id=manual__2026-08-11T12:49:12.574
   572+00:00/task_id=verify_embedding/attempt=1.log
   ::endgroup::
   [2026-08-11T12:49:13.311809Z] INFO - ::group::Pre Execute
   Task Identity ti_id=019ff0de-ab8f-7043-84dc-098e5407c3c5 
dag_id=qwen3_self_hosted_embedding task_id=verify_embedding 
run_id=manual__2026-08-11T12:49:12.574572+00:00 try_number=1 map_index=-1
   [2026-08-11T12:49:13.363284Z] INFO - DAG bundles loaded: dags-folder
   [2026-08-11T12:49:13.365408Z] INFO - Filling up the DagBag from 
/files/dags/manual_qwen3_self_hosted_embedding.py
   [2026-08-11T12:49:15.292911Z] INFO - Worker startup parse complete 
bundle_name=dags-folder  bundle_version=null  
dag_file=manual_qwen3_self_hosted_embedding.py  bundle_prepare_ms=3  
dag_file_parse_ms=1928 
   [2026-08-11T12:49:15.326585Z] INFO - ::endgroup::
   [2026-08-11T12:49:15.352060Z] INFO - Using explicit credentials for provider 
with embedding model 'openai:Qwen/Qwen3-Embedding-0.6B': ['api_key', 'base_url']
   [2026-08-11T12:49:17.976642Z] INFO - Done. Returned value was: {'model': 
'Qwen/Qwen3-Embedding-0.6B', 'provider': 'openai', 'dimension': 1024, 
'query_vectors': 1, 'document_vectors': 2, 'embedder_cached': True}
   [2026-08-11T12:49:17.976832Z] INFO - ::group::Post Execute
   [2026-08-11T12:49:17.976973Z] INFO - Pushing xcom 
ti=RuntimeTaskInstance(id=UUID('019ff0de-ab8f-7043-84dc-098e5407c3c5'), 
task_id='verify_embedding', dag_id='qwen3_self_hosted_embedding', 
run_id='manual__2026-08-11T12:49:12.574572+00:00', try_number=1, 
dag_version_id=UUID('019ff0dd-ef97-7b8e-9edb-36664c8c2b3a'), map_index=-1, 
hostname='86afabd35b10', context_carrier={'traceparent': 
'00-a5a16744aec0bf462e7b31c73faa796d-b98449d8ef65dcfd-00'}, queue='default', 
task=<Task(_PythonDecoratedOperator): verify_embedding>, 
bundle_instance=LocalDagBundle(name=dags-folder), max_tries=0, 
start_date=datetime.datetime(2026, 8, 11, 12, 49, 13, 344044, 
tzinfo=datetime.timezone.utc), end_date=None, state=<TaskInstanceState.RUNNING: 
'running'>, is_mapped=False, rendered_map_index=None, sentry_integration='') 
   [2026-08-11T12:49:18.094619Z] INFO - ::endgroup::
   ```
   
   ---
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, 
please
   change below checkbox to `[X]` followed by the name of the tool, uncomment 
the "Generated-by".
   -->
   
   
   - [X] Yes — Codex (GPT-5.6-sol)
   Generated-by: Codex (GPT-5.6-sol) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   <!--
   Generated-by: [Tool Name] following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   -->
   
   ---
   
   * Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information. Note: commit author/co-author name and email in commits 
become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License 
Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: 
`{pr_number}.significant.rst`, in 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
 You can add this file in a follow-up commit after the PR is created so you 
know the PR number.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to