routeur_ia_api / services /retrieval /document_mapper.py
Cyril Dupland
Update dependencies and enhance agent functionality: upgrade LangChain to v1.2.x, adjust retrieval tools for improved pagination and filtering, and implement new project ID checks. Modify settings for RAG top-k and add support for custom state management in agents. Enhance documentation for streaming SSE client and tools policy, ensuring clarity on usage and constraints.
7c43c4c
raw
history blame
978 Bytes
"""Map Supabase RPC rows to LangChain Document objects."""
from __future__ import annotations
from typing import Any, Dict
from langchain_core.documents import Document
def row_to_document(row: Dict[str, Any]) -> Document:
"""Convert a match_documents_v2_full row into a LangChain Document.
Hoists top-level RPC columns into metadata for clearer agent consumption.
"""
raw_meta = row.get("metadata")
meta: Dict[str, Any] = dict(raw_meta) if isinstance(raw_meta, dict) else {}
if row.get("id") is not None:
meta.setdefault("id", row["id"])
for key in ("name", "slug"):
if row.get(key) is not None:
meta.setdefault(key, row[key])
sim = row.get("similarity")
if sim is not None:
try:
meta["similarity"] = float(sim)
except (TypeError, ValueError):
meta["similarity"] = 0.0
content = row.get("content") or ""
return Document(page_content=content, metadata=meta)