Skip to content

Commit

Permalink
add cloud document converter (#14608)
Browse files Browse the repository at this point in the history
* cr

* cr
  • Loading branch information
jerryjliu authored Jul 7, 2024
1 parent 8adfd61 commit 8cfae0b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions llama-index-core/llama_index/core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from haystack.schema import Document as HaystackDocument
from llama_index.core.bridge.langchain import Document as LCDocument
from semantic_kernel.memory.memory_record import MemoryRecord
from llama_cloud.types.cloud_document import CloudDocument


DEFAULT_TEXT_NODE_TMPL = "{metadata_str}\n\n{content}"
Expand Down Expand Up @@ -762,6 +763,32 @@ def example(cls) -> "Document":
def class_name(cls) -> str:
return "Document"

def to_cloud_document(self) -> "CloudDocument":
"""Convert to LlamaCloud document type."""
from llama_cloud.types.cloud_document import CloudDocument

return CloudDocument(
text=self.text,
metadata=self.metadata,
excluded_embed_metadata_keys=self.excluded_embed_metadata_keys,
excluded_llm_metadata_keys=self.excluded_llm_metadata_keys,
id=self.id_,
)

@classmethod
def from_cloud_document(
cls,
doc: "CloudDocument",
) -> "Document":
"""Convert from LlamaCloud document type."""
return Document(
text=doc.text,
metadata=doc.metadata,
excluded_embed_metadata_keys=doc.excluded_embed_metadata_keys,
excluded_llm_metadata_keys=doc.excluded_llm_metadata_keys,
id_=doc.id,
)


class ImageDocument(Document, ImageNode):
"""Data document containing an image."""
Expand Down

0 comments on commit 8cfae0b

Please sign in to comment.