> ## Documentation Index
> Fetch the complete documentation index at: https://docs.knowledgestack.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Chunk Neighbors Handler

> Get neighboring siblings by traversing the sibling linked list.

Walks the sibling chain backward (prev) and forward (next) from the
anchor chunk. Returns sections and chunks in sibling order within the
same parent.

When ``chunks_only=true``, the traversal stops at the first non-CHUNK
sibling in each direction, returning only chunk neighbors.



## OpenAPI

````yaml /openapi.yaml get /v1/chunks/{chunk_id}/neighbors
openapi: 3.1.0
info:
  title: Knowledge Stack API
  description: Knowledge Stack backend API for authentication and knowledge management
  version: 0.1.0
servers:
  - url: http://localhost:8000
    description: Knowledge Stack API local dev server
security: []
tags:
  - name: auth
    description: Authentication and identity management
  - name: users
    description: User accounts
  - name: tenants
    description: Tenant management
  - name: invites
    description: Tenant invitations
  - name: folders
    description: Folder management
  - name: documents
    description: Document management
  - name: document-versions
    description: Document version management
  - name: sections
    description: Document sections
  - name: chunks
    description: Chunk CRUD and semantic search
  - name: chunk-lineages
    description: Chunk lineage tracking
  - name: tags
    description: Tag management
  - name: path-parts
    description: Path part traversal and tagging
  - name: Threads
    description: Thread conversations
  - name: Thread Messages
    description: Thread message management
  - name: user-permissions
    description: User path permissions
  - name: workflows
    description: Ingestion workflows
paths:
  /v1/chunks/{chunk_id}/neighbors:
    get:
      tags:
        - chunks
      summary: Get Chunk Neighbors Handler
      description: |-
        Get neighboring siblings by traversing the sibling linked list.

        Walks the sibling chain backward (prev) and forward (next) from the
        anchor chunk. Returns sections and chunks in sibling order within the
        same parent.

        When ``chunks_only=true``, the traversal stops at the first non-CHUNK
        sibling in each direction, returning only chunk neighbors.
      operationId: get_chunk_neighbors
      parameters:
        - name: chunk_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: Chunk Id
        - name: prev
          in: query
          required: false
          schema:
            type: integer
            maximum: 20
            minimum: 0
            description: Number of preceding siblings to include
            default: 1
            title: Prev
          description: Number of preceding siblings to include
        - name: next
          in: query
          required: false
          schema:
            type: integer
            maximum: 20
            minimum: 0
            description: Number of succeeding siblings to include
            default: 1
            title: Next
          description: Number of succeeding siblings to include
        - name: chunks_only
          in: query
          required: false
          schema:
            type: boolean
            description: 'When true, stop traversal at non-CHUNK siblings (default: false)'
            default: false
            title: Chunks Only
          description: 'When true, stop traversal at non-CHUNK siblings (default: false)'
        - name: authorization
          in: header
          required: false
          schema:
            type: string
            nullable: true
            title: Authorization
        - name: ks_uat
          in: cookie
          required: false
          schema:
            type: string
            nullable: true
            title: Ks Uat
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChunkNeighborsResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    ChunkNeighborsResponse:
      properties:
        items:
          items:
            $ref: '#/components/schemas/SectionContentItemOrChunkContentItem'
          type: array
          title: Items
          description: 'Ordered siblings: preceding → anchor → succeeding'
        anchor_index:
          type: integer
          title: Anchor Index
          description: Index of the anchor chunk in items
      additionalProperties: false
      type: object
      required:
        - items
        - anchor_index
      title: ChunkNeighborsResponse
      description: |-
        Response for chunk neighbor traversal.

        Returns items in the same ``SectionOrChunkItem`` discriminated union
        format used by the document version contents endpoint.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    SectionContentItemOrChunkContentItem:
      oneOf:
        - $ref: '#/components/schemas/SectionContentItem'
        - $ref: '#/components/schemas/ChunkContentItem'
      discriminator:
        propertyName: part_type
        mapping:
          CHUNK:
            $ref: '#/components/schemas/ChunkContentItem'
          SECTION:
            $ref: '#/components/schemas/SectionContentItem'
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    SectionContentItem:
      properties:
        part_type:
          type: string
          title: Part Type
          description: Path part type
          enum:
            - SECTION
        path_part_id:
          type: string
          format: uuid
          title: Path Part Id
          description: PathPart ID
        name:
          type: string
          title: Name
          description: PathPart name
        parent_path_id:
          type: string
          format: uuid
          title: Parent Path Id
          description: Parent PathPart ID
        metadata_obj_id:
          type: string
          format: uuid
          title: Metadata Obj Id
          description: Section ID
        depth:
          type: integer
          title: Depth
          description: Depth relative to document version root
        page_number:
          type: integer
          nullable: true
          title: Page Number
          description: Section page number
        materialized_path:
          type: string
          title: Materialized Path
          description: Full materialized path from root
        system_managed:
          type: boolean
          title: System Managed
          description: Whether this item is system-managed
        created_at:
          type: string
          format: date-time
          title: Created At
          description: Creation timestamp
        updated_at:
          type: string
          format: date-time
          title: Updated At
          description: Last update timestamp
      additionalProperties: false
      type: object
      required:
        - part_type
        - path_part_id
        - name
        - parent_path_id
        - metadata_obj_id
        - depth
        - materialized_path
        - system_managed
        - created_at
        - updated_at
      title: SectionContentItem
      description: Response model for a section item in document version contents.
    ChunkContentItem:
      properties:
        part_type:
          type: string
          title: Part Type
          description: Path part type
          enum:
            - CHUNK
        path_part_id:
          type: string
          format: uuid
          title: Path Part Id
          description: PathPart ID
        name:
          type: string
          title: Name
          description: PathPart name
        parent_path_id:
          type: string
          format: uuid
          title: Parent Path Id
          description: Parent PathPart ID
        metadata_obj_id:
          type: string
          format: uuid
          title: Metadata Obj Id
          description: Chunk ID
        depth:
          type: integer
          title: Depth
          description: Depth relative to document version root
        content:
          type: string
          nullable: true
          title: Content
          description: Chunk content
        chunk_type:
          $ref: '#/components/schemas/ChunkType'
          nullable: true
          description: Chunk type
        chunk_metadata:
          $ref: '#/components/schemas/ChunkMetadata-Output'
          nullable: true
          description: Chunk metadata
        materialized_path:
          type: string
          title: Materialized Path
          description: Full materialized path from root
        system_managed:
          type: boolean
          title: System Managed
          description: Whether this item is system-managed
        created_at:
          type: string
          format: date-time
          title: Created At
          description: Creation timestamp
        updated_at:
          type: string
          format: date-time
          title: Updated At
          description: Last update timestamp
      additionalProperties: false
      type: object
      required:
        - part_type
        - path_part_id
        - name
        - parent_path_id
        - metadata_obj_id
        - depth
        - materialized_path
        - system_managed
        - created_at
        - updated_at
      title: ChunkContentItem
      description: Response model for a chunk item in document version contents.
    ChunkType:
      type: string
      enum:
        - TEXT
        - TABLE
        - IMAGE
        - HTML
        - UNKNOWN
      title: ChunkType
      description: Type of chunk content.
    ChunkMetadata-Output:
      properties:
        polygons:
          items:
            $ref: '#/components/schemas/PolygonReference'
          type: array
          title: Polygons
          description: >-
            List of bounding boxes in the source document for the chunk,
            potentially from multiple areas of multiple pages.
        s3_urls:
          items:
            type: string
          type: array
          title: S3 Urls
          description: >-
            Ordered s3:// URIs to visual assets for this chunk. Single-element
            for standard IMAGE/TABLE/HTML chunks, multi-element for multi-page
            single-chunk ingestion.
        summary:
          type: string
          nullable: true
          title: Summary
          description: >-
            LLM-generated summary of the chunk content. Used for TABLE and HTML
            chunks to enrich embedding text.
        extracted_text_s3_uri:
          type: string
          nullable: true
          title: Extracted Text S3 Uri
          description: >-
            S3 URI to extracted PDF text used for LLM grounding during
            enrichment
        secondary_taxonomy:
          $ref: '#/components/schemas/ImageTaxonomy'
          nullable: true
          description: >-
            Sub-classification within a primary chunk type. For IMAGE chunks:
            'flowchart' (Mermaid extraction) or 'picture' (image description).
            None when not applicable. Will expand to cover TABLE sub-types in
            the future.
        sheet_name:
          type: string
          nullable: true
          title: Sheet Name
          description: Worksheet name this chunk was extracted from (XLSX only)
        block_type:
          type: string
          nullable: true
          title: Block Type
          description: XLSXParser block type (e.g. table, calculation_block, chart_anchor)
        source_uri:
          type: string
          nullable: true
          title: Source Uri
          description: Cell range URI reference in the source workbook (XLSX only)
        enriched_html:
          type: string
          nullable: true
          title: Enriched Html
          description: >-
            Rendered HTML for non-table XLSX chunks (tables use render_html as
            content)
        cell_range:
          type: string
          nullable: true
          title: Cell Range
          description: Cell address range, e.g. 'A1:D10' (XLSX only)
        dependency_summary:
          additionalProperties: true
          type: object
          nullable: true
          title: Dependency Summary
          description: >-
            Upstream/downstream/cross-sheet cell references for audit reasoning
            (XLSX only)
        formulas:
          items:
            additionalProperties:
              type: string
            type: object
          type: array
          nullable: true
          title: Formulas
          description: >-
            Formula cells in this chunk as [{address, formula, value}] (XLSX
            only)
        key_cells:
          items:
            additionalProperties: true
            type: object
          type: array
          nullable: true
          title: Key Cells
          description: Notable output/header cells for quick identification (XLSX only)
        named_ranges:
          items:
            additionalProperties: true
            type: object
          type: array
          nullable: true
          title: Named Ranges
          description: Named ranges overlapping this chunk (XLSX only)
      type: object
      title: ChunkMetadata
      description: Metadata for a chunk including source document references.
    PolygonReference:
      properties:
        page:
          type: integer
          title: Page
          description: The page number of the source document where the polygon is located.
        polygon:
          $ref: '#/components/schemas/Polygon'
          description: The bounding box of the polygon.
      type: object
      required:
        - page
        - polygon
      title: PolygonReference
      description: Reference to a polygon on a specific page.
    ImageTaxonomy:
      type: string
      enum:
        - picture
        - flowchart
      title: ImageTaxonomy
      description: Image classification taxonomy with prompt descriptions.
    Polygon:
      properties:
        x:
          type: integer
          title: X
          description: The x-coordinate of the top-left corner of the bounding box.
        'y':
          type: integer
          title: 'Y'
          description: The y-coordinate of the top-left corner of the bounding box.
        width:
          type: integer
          title: Width
          description: The width of the bounding box.
        height:
          type: integer
          title: Height
          description: The height of the bounding box.
      type: object
      required:
        - x
        - 'y'
        - width
        - height
      title: Polygon
      description: Bounding box polygon.

````