Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion docs/src/content/docs/ops/text.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ Languages with syntax-aware (tree-sitter) splitting — splits at logical bounda
| JSON | `"json"` | `.json`, `.jsonl`, `.geojson` |
| Julia | `"julia"` | `.jl` |
| Kotlin | `"kotlin"` | `.kt`, `.kts`, `.ktm` |
| Lua | `"lua"` | `.lua`, `.nse`, `.p8`, `.pd_lua`, `.rbxs`, `.rockspec`, `.wlua` |
| Markdown | `"markdown"` | `.md`, `.markdown`, `.mdx` |
| Pascal / Delphi | `"pascal"` | `.pas`, `.dpr`, `.lpr`, `.dfm` |
| PHP | `"php"` | `.php` |
Expand All @@ -176,7 +177,7 @@ Languages with syntax-aware (tree-sitter) splitting — splits at logical bounda

Note that `.h` maps to C++, not C — the C++ grammar also parses C headers. Pass `language="c"` explicitly to force the C grammar.

Over 110 additional languages use separator-based splitting (e.g. `"elixir"`, `"erlang"`, `"haskell"`, `"lua"`, `"nix"`, `"perl"`, `"powershell"`, `"proto"`, `"zig"`, and more). A `language=` value that matches no known language also falls back to separator-based splitting rather than raising.
110 additional languages use separator-based splitting (e.g. `"elixir"`, `"erlang"`, `"haskell"`, `"nix"`, `"perl"`, `"powershell"`, `"proto"`, `"zig"`, and more). A `language=` value that matches no known language also falls back to separator-based splitting rather than raising.

### `CustomLanguageConfig`

Expand Down
11 changes: 11 additions & 0 deletions examples/rust/amazon_s3_embedding/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/rust/code_embedding/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/rust/code_embedding_lancedb/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/rust/gdrive_text_embedding/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/rust/oci_object_storage_embedding/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/rust/paper_metadata/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/rust/pdf_embedding/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/rust/text_embedding/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/rust/text_embedding_lancedb/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/rust/text_embedding_qdrant/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/rust/text_embedding_turbopuffer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions python/tests/ops/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def test_detect_code_language_known_extensions() -> None:
assert detect_code_language(filename="App.vue") == "vue"
assert detect_code_language(filename="script.jl") == "julia"
assert detect_code_language(filename="main.dart") == "dart"
assert detect_code_language(filename="init.lua") == "lua"
assert detect_code_language(filename="Main.elm") == "elm"
assert detect_code_language(filename="index.astro") == "astro"
assert detect_code_language(filename="deploy.sh") == "bash"
Expand Down Expand Up @@ -229,6 +230,54 @@ def test_recursive_splitter_with_dart() -> None:
assert all(isinstance(c, Chunk) for c in chunks)


def test_recursive_splitter_with_lua() -> None:
"""Lua splitting is syntax-aware, not separator-based.

The sample is one line, so separators give the fallback path no function
boundaries at all. Only the grammar can find them.
"""
splitter = RecursiveSplitter()
code = (
"local function f(a) return a+1 end "
"local function g(b) return b*2 end "
"local function h(c) return c-3 end"
)
chunks = splitter.split(code, chunk_size=45, min_chunk_size=10, language="lua")

assert len(chunks) > 1, "sample must split for the check below to mean anything"
assert all(isinstance(c, Chunk) for c in chunks)
for chunk in chunks:
text = chunk.text.strip()
assert text.startswith("local function") and text.endswith("end"), (
f"chunk straddles a function boundary: {text!r}"
)


def test_recursive_splitter_lua_keeps_table_constructor_whole() -> None:
"""A Lua table constructor is not severed at a comma between its fields.

Separator fallback cuts `{ x = x, y = y }` at the comma, because a comma is
a separator to it and a table field to the grammar. A constructor longer
than `chunk_size` is still split, here as in every other grammar-backed
language.
"""
splitter = RecursiveSplitter()
code = (
"local function clamp(v, lo, hi) return math.min(math.max(v, lo), hi) end\n"
"local Point = {}\n"
"Point.__index = Point\n"
"function Point.new(x, y) return setmetatable({ x = x, y = y }, Point) end\n"
"function Point:norm() return math.sqrt(self.x * self.x + self.y * self.y) end\n"
"return Point\n"
)
chunks = splitter.split(code, chunk_size=60, min_chunk_size=10, language="lua")

assert len(chunks) > 1, "sample must split for the check below to mean anything"
assert any("setmetatable({ x = x, y = y }, Point)" in c.text for c in chunks), (
"table constructor was severed across chunks"
)


def test_recursive_splitter_with_vue() -> None:
"""Test RecursiveSplitter with Vue syntax-aware splitting."""
splitter = RecursiveSplitter()
Expand Down
1 change: 1 addition & 0 deletions rust/code_ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tree-sitter-json = "0.24.8"
tree-sitter-julia = "0.23.1"
# The other more popular crate tree-sitter-kotlin requires tree-sitter < 0.23 for now
tree-sitter-kotlin-ng = "1.1.0"
tree-sitter-lua = "0.5.0"
tree-sitter-md = "0.5.3"
tree-sitter-pascal = "0.10.2"
tree-sitter-php = "0.23.11"
Expand Down
Loading
Loading