Format documents from Snowflake Cortex Search for RAG usage.
This function extracts content from Cortex Search documents and formats them into a single string suitable for use as context in RAG applications.
format_cortex_search_documents(
docs: List[Document],
content_field: str = 'TRANSCRIPT_TEXT',
join_separator: str = '\n\n',
fallback_to_page_content: bool = True
) -> strExample:
from langchain_snowflake import SnowflakeCortexSearchRetriever, format_cortex_search_documents retriever = SnowflakeCortexSearchRetriever(...) docs = retriever.get_relevant_documents("query") context = format_cortex_search_documents(docs, content_field="CONTENT")
| Name | Type | Description |
|---|---|---|
docs* | List[Document] | List of Document objects from Cortex Search |
content_field | str | Default: 'TRANSCRIPT_TEXT'Metadata field containing the main content |
join_separator | str | Default: '\n\n'String used to join multiple documents |
fallback_to_page_content | bool | Default: TrueWhether to use page_content if content_field is missing |