Skip to content

Latest commit

 

History

History
103 lines (86 loc) · 3.24 KB

File metadata and controls

103 lines (86 loc) · 3.24 KB
title batch_get_chunks
description Retrieve specific chunks by their document ID and chunk number
```python def batch_get_chunks( sources: List[Union[ChunkSource, Dict[str, Any]]], folder_name: Optional[Union[str, List[str]]] = None, use_colpali: bool = True, output_format: Optional[str] = None, ) -> List[FinalChunkResult] ``` ```python async def batch_get_chunks( sources: List[Union[ChunkSource, Dict[str, Any]]], folder_name: Optional[Union[str, List[str]]] = None, use_colpali: bool = True, output_format: Optional[str] = None, ) -> List[FinalChunkResult] ```

Parameters

  • sources (List[Union[ChunkSource, Dict[str, Any]]]): List of ChunkSource objects or dictionaries with document_id and chunk_number
  • folder_name (str | List[str], optional): Optional folder scope. Accepts canonical paths or a list of paths/names.
  • use_colpali (bool, optional): Whether to request multimodal chunks when available. Defaults to True.
  • output_format (str, optional): Controls how image chunks are returned. Set to "url" to receive presigned URLs; omit or set to "base64" (default) to receive base64 content.

Returns

  • List[FinalChunkResult]: List of chunk results

Examples

```python from morphik import Morphik from morphik.models import ChunkSource
db = Morphik()

# Using dictionaries
sources = [
    {"document_id": "doc_123", "chunk_number": 0},
    {"document_id": "doc_456", "chunk_number": 2}
]

# Or using ChunkSource objects
sources = [
    ChunkSource(document_id="doc_123", chunk_number=0),
    ChunkSource(document_id="doc_456", chunk_number=2)
]

chunks = db.batch_get_chunks(sources)
for chunk in chunks:
    print(f"Chunk from {chunk.document_id}, number {chunk.chunk_number}: {chunk.content[:50]}...")
```
```python from morphik import AsyncMorphik from morphik.models import ChunkSource
async with AsyncMorphik() as db:
    # Using dictionaries
    sources = [
        {"document_id": "doc_123", "chunk_number": 0},
        {"document_id": "doc_456", "chunk_number": 2}
    ]
    
    # Or using ChunkSource objects
    sources = [
        ChunkSource(document_id="doc_123", chunk_number=0),
        ChunkSource(document_id="doc_456", chunk_number=2)
    ]
    
    chunks = await db.batch_get_chunks(sources)
    for chunk in chunks:
        print(f"Chunk from {chunk.document_id}, number {chunk.chunk_number}: {chunk.content[:50]}...")
```

FinalChunkResult Properties

Each FinalChunkResult object in the returned list has the following properties:

  • content (str | PILImage): Chunk content (text or image)
  • score (float): Relevance score
  • document_id (str): Parent document ID
  • chunk_number (int): Chunk sequence number
  • metadata (Dict[str, Any]): Document metadata
  • content_type (str): Content type
  • filename (Optional[str]): Original filename
  • download_url (Optional[str]): URL to download full document