Find answers from the community

Updated 11 months ago

can i use llama_index.schema.Document as

can i use llama_index.schema.Document as part of other pydantic model? like this:
Plain Text
from llama_index.schema import Document
from datetime import datetime
from pydantic import BaseModel, Field
from typing import Optional
import uuid

class DocumentObject(BaseModel):
    id: str = Field(default_factory=lambda: str(uuid.uuid4()), alias="_id")
    knowledgeBaseId: str = Field(...)
    document : Document
    createdAt: Optional[datetime] = None 
    updatedAt: Optional[datetime] = None
    deletedAt: Optional[datetime] = None
L
R
8 comments
Yea you should be able to
Document is a pydantic object
ok, i'm get this error :
Plain Text
   162 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    163 __tracebackhide__ = True
--> 164 __pydantic_self__.__pydantic_validator__.validate_python(data, self_instance=__pydantic_self__)

TypeError: BaseModel.validate() takes 2 positional arguments but 3 were given
when i try this:
Plain Text
doc = Document(text="This is a test document")

document = DocumentObject( knowledgeBaseId="123", document=doc)
uhhhh No sure on that one. Let me take a stab
ahhh I know why
we still use pydantic v1 under the hood πŸ˜…

Change your code to use from pydantic.v1 import BaseModel, Field
works! thank you so much
Add a reply
Sign up and join the conversation on Discord