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

# Get Chunks

> ### Description
Get chunks from a knowledge base using chunk IDs or a matching metadata field. This API will query from the Vector Database using
the passed in filters and optionally can return the embeddings.

    ### Details
    This API can be used to get a list of chunks from a knowledge base. Given a chunk id,             a metadata field and value, or both, matching chunks are searched for in the knowledge base             given by knowledge base id.



## OpenAPI

````yaml https://app.stainlessapi.com/api/spec/documented/sgp/openapi.yml get /v4/knowledge-bases/{knowledge_base_id}/chunks
openapi: 3.1.0
info:
  title: EGP API V4
  description: >-
    This is the parent API for all EGP APIs. If you are looking for the EGP API,
    please go to https://api.egp.scale.com/docs.
  contact:
    name: Scale Generative AI Platform
    url: https://scale.com/genai-platform
  version: 0.1.0
servers:
  - url: https://api.egp.scale.com
security: []
tags:
  - name: Models
    description: Model API.
paths:
  /v4/knowledge-bases/{knowledge_base_id}/chunks:
    get:
      tags:
        - Knowledge Bases
      summary: Get Chunks
      description: >-
        ### Description

        Get chunks from a knowledge base using chunk IDs or a matching metadata
        field. This API will query from the Vector Database using

        the passed in filters and optionally can return the embeddings.

            ### Details
            This API can be used to get a list of chunks from a knowledge base. Given a chunk id,             a metadata field and value, or both, matching chunks are searched for in the knowledge base             given by knowledge base id.
      operationId: GET-V4-/v2/knowledge-bases/{knowledge_base_id}/chunks
      parameters:
        - name: knowledge_base_id
          in: path
          required: true
          schema:
            type: string
            title: Knowledge Base Id
        - name: chunk_id
          in: query
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: Optional search by chunk_id
            title: Chunk Id
          description: Optional search by chunk_id
        - name: metadata_filters
          in: query
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: Optional search by metadata fields, encoded as a JSON object
            title: Metadata Filters
          description: Optional search by metadata fields, encoded as a JSON object
        - name: max_chunks
          in: query
          required: false
          schema:
            type: integer
            maximum: 2000
            minimum: 1
            description: >-
              Maximum number of chunks returned by the get_chunks endpoint.
              Defaults to 10 and cannot be greater than 2000.
            default: 10
            title: Max Chunks
          description: >-
            Maximum number of chunks returned by the get_chunks endpoint.
            Defaults to 10 and cannot be greater than 2000.
        - name: x-selected-account-id
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Account ID Header
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetChunksResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
      x-codeSamples:
        - lang: Python
          source: |-
            import os
            from scale_gp import SGPClient

            client = SGPClient(
                api_key=os.environ.get("SGP_API_KEY"),  # This is the default and can be omitted
            )
            page = client.knowledge_bases.chunks.list(
                knowledge_base_id="knowledge_base_id",
            )
            page = page.chunks[0]
            print(page.chunk_id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/stainless-sdks/sgp-go\"\n\t\"github.com/stainless-sdks/sgp-go/option\"\n)\n\nfunc main() {\n\tclient := sgp.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tpage, err := client.KnowledgeBases.Chunks.List(\n\t\tcontext.TODO(),\n\t\t\"knowledge_base_id\",\n\t\tsgp.KnowledgeBaseChunkListParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", page)\n}\n"
components:
  schemas:
    GetChunksResponse:
      properties:
        chunks:
          items:
            $ref: '#/components/schemas/ChunkV2WithoutScore'
          type: array
          title: Chunks
          description: List of chunks that match the chunk_id and metadata filters
      type: object
      required:
        - chunks
      title: GetChunksResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ChunkV2WithoutScore:
      properties:
        chunk_id:
          type: string
          title: Chunk Id
          description: The unique ID of the chunk with embedding
        text:
          type: string
          title: Text
          description: The text associated with the chunk
        embedding:
          title: Embedding
          description: The vector embedding of the text associated with the chunk
          items:
            type: number
          type: array
        metadata:
          title: Metadata
          description: >-
            Any additional key value pairs of information stored by you on the
            chunk with embedding
          default: {}
          additionalProperties: true
          type: object
        user_supplied_metadata:
          title: User Supplied Metadata
          description: >-
            Any additional key value pairs of information returned from the
            custom chunking.
          default: {}
          additionalProperties: true
          type: object
        attachment_url:
          title: Attachment Url
          description: Original attachment URL from which this chunk got its data from
          type: string
        title:
          title: Title
          description: Title for this chunk, for example the file name
          type: string
      type: object
      required:
        - chunk_id
        - text
      title: ChunkV2WithoutScore
    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
          additionalProperties: true
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: x-api-key

````