41 lines
1.1 KiB
Python
Raw Normal View History

from typing import Any, Dict, List
from pydantic import BaseModel, Field
import numpy as np
Embedding = List[float] | List[List[float]] | np.ndarray
2024-12-30 11:46:42 -05:00
class DocumentChunk(BaseModel):
"""Represents a chunk stored in VectorStore"""
document_id: str # external_id of parent document
content: str
embedding: Embedding
2024-12-30 11:46:42 -05:00
chunk_number: int
# chunk-specific metadata
metadata: Dict[str, Any] = Field(default_factory=dict)
score: float = 0.0
model_config = {"arbitrary_types_allowed": True}
2024-12-30 11:46:42 -05:00
class Chunk(BaseModel):
"""Represents a chunk containing content and metadata"""
content: str
metadata: Dict[str, Any] = Field(default_factory=dict)
2024-12-30 11:46:42 -05:00
model_config = {"arbitrary_types_allowed": True}
2024-12-30 11:46:42 -05:00
def to_document_chunk(
self, document_id: str, chunk_number: int, embedding: Embedding
2024-12-30 11:46:42 -05:00
) -> DocumentChunk:
return DocumentChunk(
document_id=document_id,
content=self.content,
embedding=embedding,
chunk_number=chunk_number,
metadata=self.metadata,
)