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

# Knowledge SDK Reference

> SDK reference for the Knowledge API, available in Node.js and Python.

## Knowledge

### List Knowledge

Returns a list of your knowledge bases. The knowledge bases are returned sorted by creation date, with the most recent knowledge bases appearing first

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.list(limit=25)

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.list({});

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "starting_after": Optional[str],
        "ending_before": Optional[str],
        "limit": Optional[int],
        "search": Optional[str],
        "updated_by": Optional[str],
        "type": Optional[Literal["internal", "external"]],
        "project_id": Optional[str],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      startingAfter?: string;
      endingBefore?: string;
      limit?: number;
      search?: string;
      updatedBy?: string;
      type?: string;
      projectId?: string;
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "object": Literal["list"],
        "data": Union[Data1, Data2],
        "has_more": bool,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      object: string;
      data: string;
      hasMore: boolean;
    }
    ```
  </CodeGroup>
</Expandable>

### Create a Knowledge

Create a knowledge

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.create(request={
          "type": "internal",
          "key": "<key>",
          "embedding_model": "<value>",
          "path": "Default",
      })

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.create({
      type: "internal",
      key: "<key>",
      embeddingModel: "<value>",
      path: "Default",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "type": Optional[Literal["internal"]],
        "key": str,  # required
        "description": Optional[str],
        "embedding_model": str,  # required
        "retrieval_settings": {  # optional
            "retrieval_type": Optional[Literal["vector_search", "keyword_search", "hybrid_search"]],
            "top_k": Optional[int],
            "threshold": Optional[float],
            "rerank_config": {  # optional
                "top_k": Optional[int],
                "rerank_threshold": Optional[float],
                "rerank_model": str,  # required
            },
            "agentic_rag_config": {  # optional
                "model": str,  # required
            },
        },
        "path": str,  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      type?: "internal" | undefined;
      key: string;  // required
      description?: string | undefined;
      embedding_model: string;  // required
      retrieval_settings?: {
        retrieval_type?: "vector_search" | "keyword_search" | "hybrid_search" | undefined;
        top_k?: number | undefined;
        threshold?: number | undefined;
        rerank_config?: {
          top_k?: number | undefined;
          rerank_threshold?: number | undefined;
          rerank_model: string;  // required
        };
        agentic_rag_config?: {
          model: string;  // required
        };
      };
      path: string;  // required
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "id": str,
        "created": str,
        "description": OptionalNullable[str],
        "key": str,
        "domain_id": str,
        "path": Optional[str],
        "created_by_id": OptionalNullable[str],
        "updated_by_id": OptionalNullable[str],
        "updated": str,
        "type": Optional[Literal["internal"]],
        "retrieval_settings": {  # optional
            "retrieval_type": Optional[Literal["vector_search", "keyword_search", "hybrid_search"]],
            "top_k": Optional[int],
            "threshold": Optional[float],
            "rerank_config": {  # optional
                "top_k": Optional[int],
                "rerank_threshold": Optional[float],
                "rerank_model": str,
            },
            "agentic_rag_config": {  # optional
                "model": str,
            },
        },
        "model": str,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      id: string;
      created: string;
      description?: string | null | undefined;
      key: string;
      domain_id: string;
      path?: string | undefined;
      created_by_id?: string | null | undefined;
      updated_by_id?: string | null | undefined;
      updated: string;
      type?: "internal" | undefined;
      retrieval_settings?: {
        retrieval_type?: "vector_search" | "keyword_search" | "hybrid_search" | undefined;
        top_k?: number | undefined;
        threshold?: number | undefined;
        rerank_config?: {
          top_k?: number | undefined;
          rerank_threshold?: number | undefined;
          rerank_model: string;
        };
        agentic_rag_config?: {
          model: string;
        };
      };
      model: string;
    }
    ```
  </CodeGroup>
</Expandable>

### Retrieve a Knowledge

Retrieve a knowledge base with the settings.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.retrieve(knowledge_id="<id>")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.retrieve({
      knowledgeId: "<id>",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "id": str,
        "created": str,
        "description": OptionalNullable[str],
        "key": str,
        "domain_id": str,
        "path": Optional[str],
        "created_by_id": OptionalNullable[str],
        "updated_by_id": OptionalNullable[str],
        "updated": str,
        "type": Optional[Literal["internal"]],
        "retrieval_settings": {  # optional
            "retrieval_type": Optional[Literal["vector_search", "keyword_search", "hybrid_search"]],
            "top_k": Optional[int],
            "threshold": Optional[float],
            "rerank_config": {  # optional
                "top_k": Optional[int],
                "rerank_threshold": Optional[float],
                "rerank_model": str,
            },
            "agentic_rag_config": {  # optional
                "model": str,
            },
        },
        "model": str,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      id: string;
      created: string;
      description?: string | null | undefined;
      key: string;
      domain_id: string;
      path?: string | undefined;
      created_by_id?: string | null | undefined;
      updated_by_id?: string | null | undefined;
      updated: string;
      type?: "internal" | undefined;
      retrieval_settings?: {
        retrieval_type?: "vector_search" | "keyword_search" | "hybrid_search" | undefined;
        top_k?: number | undefined;
        threshold?: number | undefined;
        rerank_config?: {
          top_k?: number | undefined;
          rerank_threshold?: number | undefined;
          rerank_model: string;
        };
        agentic_rag_config?: {
          model: string;
        };
      };
      model: string;
    }
    ```
  </CodeGroup>
</Expandable>

### Update a Knowledge

Updates a knowledge

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.update(knowledge_id="<id>", request_body={
          "path": "Default",
          "type": "external",
      })

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.update({
      knowledgeId: "<id>",
      requestBody: {
        path: "Default",
        type: "external",
      },
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
        "request_body": Union[UpdateKnowledgeRequestBody1, UpdateKnowledgeRequestBody2],  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
      requestBody: string;  // required
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "id": str,
        "created": str,
        "description": OptionalNullable[str],
        "key": str,
        "domain_id": str,
        "path": Optional[str],
        "created_by_id": OptionalNullable[str],
        "updated_by_id": OptionalNullable[str],
        "updated": str,
        "type": Optional[Literal["internal"]],
        "retrieval_settings": {  # optional
            "retrieval_type": Optional[Literal["vector_search", "keyword_search", "hybrid_search"]],
            "top_k": Optional[int],
            "threshold": Optional[float],
            "rerank_config": {  # optional
                "top_k": Optional[int],
                "rerank_threshold": Optional[float],
                "rerank_model": str,
            },
            "agentic_rag_config": {  # optional
                "model": str,
            },
        },
        "model": str,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      id: string;
      created: string;
      description?: string | null | undefined;
      key: string;
      domain_id: string;
      path?: string | undefined;
      created_by_id?: string | null | undefined;
      updated_by_id?: string | null | undefined;
      updated: string;
      type?: "internal" | undefined;
      retrieval_settings?: {
        retrieval_type?: "vector_search" | "keyword_search" | "hybrid_search" | undefined;
        top_k?: number | undefined;
        threshold?: number | undefined;
        rerank_config?: {
          top_k?: number | undefined;
          rerank_threshold?: number | undefined;
          rerank_model: string;
        };
        agentic_rag_config?: {
          model: string;
        };
      };
      model: string;
    }
    ```
  </CodeGroup>
</Expandable>

### Delete a Knowledge

Deletes a knowledge base. Deleting a knowledge base will delete all the datasources and chunks associated with it.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      orq.knowledge.delete(knowledge_id="<id>")

      # Use the SDK ...

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    await orq.knowledge.delete({
      knowledgeId: "<id>",
    });

  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
    }
    ```
  </CodeGroup>
</Expandable>

### Search Knowledge

Search a Knowledge Base and return the most similar chunks, along with their search and rerank scores. Note that all configuration changes made in the API will override the settings in the UI.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.search(knowledge_id="<id>", query="<value>", search_type="hybrid_search", rerank_config={
          "model": "cohere/rerank-multilingual-v3.0",
      })

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.search({
      knowledgeId: "<id>",
      requestBody: {
        query: "<value>",
        rerankConfig: {
          model: "cohere/rerank-multilingual-v3.0",
        },
      },
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
        "query": str,  # required
        "top_k": Optional[int],
        "threshold": Optional[float],
        "search_type": Optional[Literal["vector_search", "keyword_search", "hybrid_search"]],
        "filter_by": Union[Dict[str, FilterBy1], FilterByAnd, FilterByOr],
        "search_options": {  # optional
            "include_vectors": Optional[bool],
            "include_metadata": Optional[bool],
            "include_scores": Optional[bool],
        },
        "rerank_config": {  # optional
            "model": str,  # required
            "threshold": Optional[float],
            "top_k": Optional[int],
        },
        "agentic_rag_config": {  # optional
            "model": str,  # required
        },
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
      requestBody?: {
        query: string;  // required
        topK?: number;
        threshold?: number;
        searchType?: string;
        filterBy?: string;
        searchOptions?: {
          includeVectors?: boolean;
          includeMetadata?: boolean;
          includeScores?: boolean;
        };
        rerankConfig?: {
          model: string;  // required
          threshold?: number;
          topK?: number;
        };
        agenticRagConfig?: {
          model: string;  // required
        };
      };
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "matches": {
            "id": str,
            "text": str,
            "vector": List[float],
            "metadata": Dict[str, Any],
            "scores": {  # optional
                "rerank_score": Optional[float],
                "search_score": Optional[float],
            },
        },
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      matches: {
        id: string;
        text: string;
        vector?: number[];
        metadata?: Record<string, any>;
        scores?: {
          rerankScore?: number;
          searchScore?: number;
        };
      };
    }
    ```
  </CodeGroup>
</Expandable>

### List Datasources

List all datasources

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.list_datasources(knowledge_id="<id>", limit=50, status=[
          "completed",
          "failed",
      ])

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.listDatasources({
      knowledgeId: "<id>",
      status: [
        "completed",
        "failed",
      ],
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
        "starting_after": Optional[str],
        "ending_before": Optional[str],
        "q": Optional[str],
        "limit": Optional[float],
        "status": Union[List[str], str],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
      startingAfter?: string;
      endingBefore?: string;
      q?: string;
      limit?: number;
      status?: string[] | string;
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "object": Literal["list"],
        "data": {
            "id": Optional[str],
            "display_name": str,
            "description": OptionalNullable[str],
            "status": Literal["pending", "processing", "completed", "failed", "queued"],
            "file_id": OptionalNullable[str],
            "created": str,
            "updated": str,
            "created_by_id": OptionalNullable[str],
            "update_by_id": OptionalNullable[str],
            "knowledge_id": str,
            "chunks_count": float,
        },
        "has_more": bool,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      object: string;
      data: {
        id?: string;
        displayName: string;
        description?: string;
        status: string;
        fileId?: string;
        created: string;
        updated: string;
        createdById?: string;
        updateById?: string;
        knowledgeId: string;
        chunksCount: number;
      };
      hasMore: boolean;
    }
    ```
  </CodeGroup>
</Expandable>

### Create Datasource

Create a new datasource

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.create_datasource(knowledge_id="<id>")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.createDatasource({
      knowledgeId: "<id>",
      requestBody: {},
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
        "display_name": Optional[str],
        "description": OptionalNullable[str],
        "file_id": Optional[str],
        "chunking_options": {  # optional
            "chunking_configuration": Union[ChunkingConfiguration1, ChunkingConfiguration2],
            "chunking_cleanup_options": {  # optional
                "delete_emails": Optional[bool],
                "delete_credit_cards": Optional[bool],
                "delete_phone_numbers": Optional[bool],
                "clean_bullet_points": Optional[bool],
                "clean_numbered_list": Optional[bool],
                "clean_unicode": Optional[bool],
                "clean_dashes": Optional[bool],
                "clean_whitespaces": Optional[bool],
            },
        },
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
      requestBody: {  // required
        displayName?: string;
        description?: string;
        fileId?: string;
        chunkingOptions?: {
          chunkingConfiguration?: string;
          chunkingCleanupOptions?: {
            deleteEmails?: boolean;
            deleteCreditCards?: boolean;
            deletePhoneNumbers?: boolean;
            cleanBulletPoints?: boolean;
            cleanNumberedList?: boolean;
            cleanUnicode?: boolean;
            cleanDashes?: boolean;
            cleanWhitespaces?: boolean;
          };
        };
      };
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "id": Optional[str],
        "display_name": str,
        "description": OptionalNullable[str],
        "status": Literal["pending", "processing", "completed", "failed", "queued"],
        "file_id": OptionalNullable[str],
        "created": str,
        "updated": str,
        "created_by_id": OptionalNullable[str],
        "update_by_id": OptionalNullable[str],
        "knowledge_id": str,
        "chunks_count": float,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      id?: string;
      displayName: string;
      description?: string;
      status: string;
      fileId?: string;
      created: string;
      updated: string;
      createdById?: string;
      updateById?: string;
      knowledgeId: string;
      chunksCount: number;
    }
    ```
  </CodeGroup>
</Expandable>

### Retrieve Datasource

Retrieve a datasource

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.retrieve_datasource(knowledge_id="<id>", datasource_id="<id>")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.retrieveDatasource({
      knowledgeId: "<id>",
      datasourceId: "<id>",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
        "datasource_id": str,  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
      datasourceId: string;  // required
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "id": Optional[str],
        "display_name": str,
        "description": OptionalNullable[str],
        "status": Literal["pending", "processing", "completed", "failed", "queued"],
        "file_id": OptionalNullable[str],
        "created": str,
        "updated": str,
        "created_by_id": OptionalNullable[str],
        "update_by_id": OptionalNullable[str],
        "knowledge_id": str,
        "chunks_count": float,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      id?: string;
      displayName: string;
      description?: string;
      status: string;
      fileId?: string;
      created: string;
      updated: string;
      createdById?: string;
      updateById?: string;
      knowledgeId: string;
      chunksCount: number;
    }
    ```
  </CodeGroup>
</Expandable>

### Delete Datasource

Deletes a datasource from a knowledge base. Deleting a datasource will remove it from the knowledge base and all associated chunks. This action is irreversible and cannot be undone.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      orq.knowledge.delete_datasource(knowledge_id="<id>", datasource_id="<id>")

      # Use the SDK ...

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    await orq.knowledge.deleteDatasource({
      knowledgeId: "<id>",
      datasourceId: "<id>",
    });

  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
        "datasource_id": str,  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
      datasourceId: string;  // required
    }
    ```
  </CodeGroup>
</Expandable>

### Update Datasource

Update a datasource

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.update_datasource(knowledge_id="<id>", datasource_id="<id>", display_name="Tony_Roberts")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.updateDatasource({
      knowledgeId: "<id>",
      datasourceId: "<id>",
      requestBody: {
        displayName: "Tony_Roberts",
      },
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
        "datasource_id": str,  # required
        "display_name": str,  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
      datasourceId: string;  // required
      requestBody: {  // required
        displayName: string;  // required
      };
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "id": Optional[str],
        "display_name": str,
        "description": OptionalNullable[str],
        "status": Literal["pending", "processing", "completed", "failed", "queued"],
        "file_id": OptionalNullable[str],
        "created": str,
        "updated": str,
        "created_by_id": OptionalNullable[str],
        "update_by_id": OptionalNullable[str],
        "knowledge_id": str,
        "chunks_count": float,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      id?: string;
      displayName: string;
      description?: string;
      status: string;
      fileId?: string;
      created: string;
      updated: string;
      createdById?: string;
      updateById?: string;
      knowledgeId: string;
      chunksCount: number;
    }
    ```
  </CodeGroup>
</Expandable>

### Create Chunks

Create chunks for a datasource

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.create_chunks(knowledge_id="<id>", datasource_id="<id>")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.createChunks({
      knowledgeId: "<id>",
      datasourceId: "<id>",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
        "datasource_id": str,  # required
        "request_body": {  # optional
            "text": str,  # required
            "embedding": List[float],
            "metadata": Union[str, float, bool],
        },
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
      datasourceId: string;  // required
      requestBody?: {
        text: string;  // required
        embedding?: number[];
        metadata?: string;
      };
    }
    ```
  </CodeGroup>
</Expandable>

### List Chunks

List all chunks for a datasource

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.list_chunks(knowledge_id="<id>", datasource_id="<id>", limit=10, status=[
          "completed",
          "failed",
      ])

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.listChunks({
      knowledgeId: "<id>",
      datasourceId: "<id>",
      status: [
        "completed",
        "failed",
      ],
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
        "datasource_id": str,  # required
        "limit": Optional[int],
        "starting_after": Optional[str],
        "ending_before": Optional[str],
        "q": Optional[str],
        "status": Union[List[QueryParam1], QueryParam2],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
      datasourceId: string;  // required
      limit?: number;
      startingAfter?: string;
      endingBefore?: string;
      q?: string;
      status?: string;
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "object": Literal["list"],
        "data": {
            "id": str,
            "text": str,
            "metadata": Union[str, float, bool],
            "enabled": bool,
            "status": Literal["pending", "processing", "completed", "failed", "queued"],
            "created": str,
            "updated": str,
            "created_by_id": OptionalNullable[str],
            "update_by_id": OptionalNullable[str],
        },
        "has_more": bool,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      object: string;
      data: {
        id: string;
        text: string;
        metadata?: string;
        enabled: boolean;
        status: string;
        created: string;
        updated: string;
        createdById?: string;
        updateById?: string;
      };
      hasMore: boolean;
    }
    ```
  </CodeGroup>
</Expandable>

### Delete Chunks

Delete multiple chunks

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.delete_chunks(knowledge_id="<id>", datasource_id="<id>", chunk_ids=[
          "<value 1>",
          "<value 2>",
      ])

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.deleteChunks({
      knowledgeId: "<id>",
      datasourceId: "<id>",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
        "datasource_id": str,  # required
        "chunk_ids": List[str],  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
      datasourceId: string;  // required
      requestBody?: {
        chunkIds: string[];  // required
      };
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "deleted_count": float,
        "failed_ids": List[str],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      deletedCount: number;
      failedIds?: string[];
    }
    ```
  </CodeGroup>
</Expandable>

### List Chunks Paginated

List chunks with offset-based pagination

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.list_chunks_paginated(knowledge_id="<id>", datasource_id="<id>", q="", limit=100, page=1)

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.listChunksPaginated({
      knowledgeId: "<id>",
      datasourceId: "<id>",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
        "datasource_id": str,  # required
        "q": Optional[str],
        "enabled": Optional[bool],
        "status": Optional[Literal["pending", "processing", "completed", "failed", "queued"]],
        "limit": Optional[int],
        "page": Optional[int],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
      datasourceId: string;  // required
      requestBody?: {
        q?: string;
        enabled?: boolean;
        status?: string;
        limit?: number;
        page?: number;
      };
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "object": Literal["list"],
        "data": {
            "id": str,
            "text": str,
            "metadata": Union[str, float, bool],
            "enabled": bool,
            "status": Literal["pending", "processing", "completed", "failed", "queued"],
            "created": str,
            "updated": str,
            "created_by_id": OptionalNullable[str],
            "update_by_id": OptionalNullable[str],
        },
        "has_more": bool,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      object: string;
      data: {
        id: string;
        text: string;
        metadata?: string;
        enabled: boolean;
        status: string;
        created: string;
        updated: string;
        createdById?: string;
        updateById?: string;
      };
      hasMore: boolean;
    }
    ```
  </CodeGroup>
</Expandable>

### Get Chunks Count

Returns the total count of chunks in a datasource. When `q` is provided, the count reflects indexed chunks only: recently created chunks may not be counted until embedding completes.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.get_chunks_count(knowledge_id="<id>", datasource_id="<id>", q="")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.getChunksCount({
      knowledgeId: "<id>",
      datasourceId: "<id>",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "knowledge_id": str,  # required
        "datasource_id": str,  # required
        "q": Optional[str],
        "enabled": Optional[bool],
        "status": Optional[Literal["pending", "processing", "completed", "failed", "queued"]],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      knowledgeId: string;  // required
      datasourceId: string;  // required
      requestBody?: {
        q?: string;
        enabled?: boolean;
        status?: string;
      };
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "count": float,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      count: number;
    }
    ```
  </CodeGroup>
</Expandable>

### Update Chunk

Update a chunk

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.update_chunk(chunk_id="<id>", datasource_id="<id>", knowledge_id="<id>")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.updateChunk({
      chunkId: "<id>",
      datasourceId: "<id>",
      knowledgeId: "<id>",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "chunk_id": str,  # required
        "datasource_id": str,  # required
        "knowledge_id": str,  # required
        "text": Optional[str],
        "embedding": List[float],
        "metadata": Union[str, float, bool],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      chunkId: string;  // required
      datasourceId: string;  // required
      knowledgeId: string;  // required
      requestBody?: {
        text?: string;
        embedding?: number[];
        metadata?: string;
      };
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "id": str,
        "text": str,
        "metadata": Union[str, float, bool],
        "enabled": bool,
        "status": Literal["pending", "processing", "completed", "failed", "queued"],
        "created": str,
        "updated": str,
        "created_by_id": OptionalNullable[str],
        "update_by_id": OptionalNullable[str],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      id: string;
      text: string;
      metadata?: string;
      enabled: boolean;
      status: string;
      created: string;
      updated: string;
      createdById?: string;
      updateById?: string;
    }
    ```
  </CodeGroup>
</Expandable>

### Delete Chunk

Delete a chunk

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      orq.knowledge.delete_chunk(chunk_id="<id>", datasource_id="<id>", knowledge_id="<id>")

      # Use the SDK ...

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    await orq.knowledge.deleteChunk({
      chunkId: "<id>",
      datasourceId: "<id>",
      knowledgeId: "<id>",
    });

  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "chunk_id": str,  # required
        "datasource_id": str,  # required
        "knowledge_id": str,  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      chunkId: string;  // required
      datasourceId: string;  // required
      knowledgeId: string;  // required
    }
    ```
  </CodeGroup>
</Expandable>

### Retrieve Chunk

Retrieve a chunk

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.knowledge.retrieve_chunk(chunk_id="<id>", datasource_id="<id>", knowledge_id="<id>")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.knowledge.retrieveChunk({
      chunkId: "<id>",
      datasourceId: "<id>",
      knowledgeId: "<id>",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "chunk_id": str,  # required
        "datasource_id": str,  # required
        "knowledge_id": str,  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      chunkId: string;  // required
      datasourceId: string;  // required
      knowledgeId: string;  // required
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "id": str,
        "text": str,
        "metadata": Union[str, float, bool],
        "enabled": bool,
        "status": Literal["pending", "processing", "completed", "failed", "queued"],
        "created": str,
        "updated": str,
        "created_by_id": OptionalNullable[str],
        "update_by_id": OptionalNullable[str],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      id: string;
      text: string;
      metadata?: string;
      enabled: boolean;
      status: string;
      created: string;
      updated: string;
      createdById?: string;
      updateById?: string;
    }
    ```
  </CodeGroup>
</Expandable>
