kotaemon/knowledgehub/documents/base.py
ian_Cin 08b6e5d3fb [AUR-390] Add prompt template and prompt component (#24)
* Export pipeline to config

* Export the input to config

* Preliminary creating UI dynamically

* Add test for config export

* Try out prompt UI

* Add example projects

* Fix test errors

* Standardize interface for retrieval

* Finalize the UI demo

* Update README.md

* Update README

* Refactor according to main

* Fix typing issue

* Add openai key to git-secret

* Add prompt template and prompt component

* Update test

* update tests

* revert docstring

---------

Co-authored-by: trducng <trungduc1992@gmail.com>
Co-authored-by: Nguyen Trung Duc (john) <john@cinnamon.is>
2023-09-25 14:38:22 +07:00

41 lines
1.3 KiB
Python

from haystack.schema import Document as HaystackDocument
from llama_index.bridge.pydantic import Field
from llama_index.schema import Document as BaseDocument
SAMPLE_TEXT = "A sample Document from kotaemon"
class Document(BaseDocument):
"""Base document class, mostly inherited from Document class from llama-index"""
@classmethod
def example(cls) -> "Document":
document = Document(
text=SAMPLE_TEXT,
metadata={"filename": "README.md", "category": "codebase"},
)
return document
def to_haystack_format(self) -> "HaystackDocument":
"""Convert struct to Haystack document format."""
metadata = self.metadata or {}
text = self.text
return HaystackDocument(content=text, meta=metadata)
def __str__(self):
return self.text
class RetrievedDocument(Document):
"""Subclass of Document with retrieval-related information
Attributes:
score (float): score of the document (from 0.0 to 1.0)
retrieval_metadata (dict): metadata from the retrieval process, can be used
by different components in a retrieved pipeline to communicate with each
other
"""
score: float = Field(default=0.0)
retrieval_metadata: dict = Field(default={})