jeff3071 commented on code in PR #71437:
URL: https://github.com/apache/airflow/pull/71437#discussion_r4109990866
##########
providers/common/ai/docs/hooks/pydantic_ai.rst:
##########
@@ -57,7 +58,46 @@ The model can be specified at three levels (highest priority
first):
# Override with a specific model
hook = PydanticAIHook(llm_conn_id="my_llm",
model_id="anthropic:claude-sonnet-5")
-Structured output
+Embedding Models
+----------------
+
+Set ``embed_model_id`` on the hook or ``embed_model`` in the connection's
extra JSON,
+then call ``get_embedder()``. ``embed_conn_id`` defaults to ``llm_conn_id``.
Different
+LLM and embedding providers require separate connections when the shared
connection
+produces explicit configuration for the embedding provider, so those values
cannot be
+reused for the wrong provider. They can share a connection when no embedding
provider
+configuration can be built from it; pydantic-ai then resolves the embedding
provider
+independently, for example from environment variables, even if the LLM uses
configuration
+from the connection. Equivalent OpenAI and Azure chat/response prefixes can
share their
+provider's embedding connection. Local
+``sentence-transformers:`` embeddings can also share the LLM connection
because they
+do not use provider credentials. The resolved ``Embedder`` is cached on the
hook instance.
+
+.. code-block:: python
+
+ hook = PydanticAIHook(
+ llm_conn_id="my_llm",
+ embed_conn_id="my_embeddings",
+ embed_model_id="openai:text-embedding-3-small",
+ )
+ embedder = hook.get_embedder()
+ result = embedder.embed_query_sync("Apache Airflow orchestrates
workflows.")
+ embedding = result.embeddings[0]
+
+Keyword arguments accepted by pydantic-ai's `Embedder constructor
+<https://ai.pydantic.dev/api/embeddings/#pydantic_ai.embeddings.Embedder.__init__>`__
+can be passed directly to ``get_embedder()``. These currently include
``settings`` and ``instrument``. Caller-supplied ``instrument`` takes
Review Comment:
Updated
--
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]