You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
langchain/templates/self-query-qdrant/self_query_qdrant/helper.py

28 lines
664 B
Python

from string import Formatter
from typing import List
from langchain.schema import Document
document_template = """
PASSAGE: {page_content}
METADATA: {metadata}
"""
def combine_documents(documents: List[Document]) -> str:
"""
Combine a list of documents into a single string that might be passed further down
to a language model.
:param documents: list of documents to combine
:return:
"""
formatter = Formatter()
return "\n\n".join(
formatter.format(
document_template,
page_content=document.page_content,
metadata=document.metadata,
)
for document in documents
)