---
title: chunks | CodeWeaver Docs
description: API reference for codeweaver.core.chunks
url: "https://docs.knitli.com/api/core/chunks"
type: static
generatedAt: "2026-04-17T17:21:07.865Z"
---

# chunks
       [Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fchunks%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fchunks%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[View in Markdown](/codeweaver/api/core/chunks.md)       [Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fchunks%2F)[Share on X](https://x.com/intent/tweet?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fchunks%2F&text=chunks)[Share on Threads](https://threads.net/intent/post?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fchunks%2F&text=chunks)[Share on Bluesky](https://bsky.app/intent/compose?text=chunks%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fchunks%2F)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fchunks%2F)[Share on Reddit](https://reddit.com/submit?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fchunks%2F&title=chunks)[Share on Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fchunks%2F&t=chunks)[Share on Email](mailto:?subject=chunks&body=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fchunks%2F)[Share on WhatsApp](https://wa.me/?text=chunks%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fchunks%2F)[Share on Telegram](https://t.me/share/url?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fchunks%2F&text=chunks)
# `codeweaver.core.chunks`
[Section titled “codeweaver.core.chunks”](#codeweavercorechunks)
CodeWeaver Code Chunks and Search Results.

`CodeChunk` are the core building block of all CodeWeaver operations. They are the result of code parsing and chunking operations, and they contain the actual code content along with metadata such as file path, language, line ranges, and more. `SearchResult` is the output of a vector search operation — before it has been processed through CodeWeaver’s multi-layered reranking system.

## Class: `BatchKeys`
[Section titled “Class: BatchKeys”](#class-batchkeys)
Tuple representing batch keys for embedding operations.

## Class: `CodeChunk`
[Section titled “Class: CodeChunk”](#class-codechunk)
Represents a chunk of code or docs with metadata.

### Method: `chunkify`
[Section titled “Method: chunkify”](#method-chunkify)

**

```
chunkify()
```

Convert text to a CodeChunk.

### Method: `dechunkify`
[Section titled “Method: dechunkify”](#method-dechunkify)

**

```
dechunkify()
```

Convert a sequence of CodeChunks or mixed serialized and deserialized chunks back to json strings.

### Method: `from_file`
[Section titled “Method: from_file”](#method-from_file)

**

```
from_file()
```

Create a CodeChunk from a file. (This creates a chunk that consists of the entire file contents. To create smaller chunks, use a chunker.).

### Method: `serialize`
[Section titled “Method: serialize”](#method-serialize)

**

```
serialize()
```

Serialize the CodeChunk to a dictionary.

### Method: `serialize_for_cli`
[Section titled “Method: serialize_for_cli”](#method-serialize_for_cli)

**

```
serialize_for_cli()
```

Serialize the CodeChunk for CLI output.

### Method: `serialize_for_embedding`
[Section titled “Method: serialize_for_embedding”](#method-serialize_for_embedding)

**

```
serialize_for_embedding()
```

Serialize the CodeChunk for embedding.

Returns a JSON string containing the most relevant fields for semantic search.

### Method: `set_batch_keys`
[Section titled “Method: set_batch_keys”](#method-set_batch_keys)

**

```
set_batch_keys()
```

Set the batch keys for the code chunk.

Returns a new CodeChunk instance with updated batch keys. Explicitly copies metadata dict to prevent shared references between instances.

Args: batch_keys: The batch keys to set intent: The intent/name for this embedding (e.g., “primary”, “backup”, “sparse”). If None, infers from sparse flag and secondary parameter. secondary: Deprecated - use intent parameter instead. If True and intent is None, uses “backup” as intent.

Returns: New CodeChunk instance with batch keys set

### Method: `token_count`
[Section titled “Method: token_count”](#method-token_count)

**

```
token_count()
```

Return the token count for the chunk content.

## Class: `CodeChunkDict`
[Section titled “Class: CodeChunkDict”](#class-codechunkdict)
A python dictionary of a CodeChunk.

Primarily provides type hints and documentation for the expected structure of a CodeChunk when represented as a dictionary.