Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Add Tokenizer documentation

davidmezzettia6c64a69447b
diff --git a/docs/embeddings/configuration/scoring.md b/docs/embeddings/configuration/scoring.md
index 2b4eef25..46a7dfb7 100644
--- a/docs/embeddings/configuration/scoring.md
+++ b/docs/embeddings/configuration/scoring.md
@@ -82,3 +82,10 @@ normalize: boolean
```
Enables normalized scoring (ranging from 0 to 1). When enabled, statistics from the index will be used to calculate normalized scores.
+
+## tokenizer
+```yaml
+tokenizer: dict
+```
+
+Set tokenization rules. Passes these arguments to the underlying [Tokenization pipeline](../../../pipeline/data/tokenizer#txtai.pipeline.Tokenizer.__init__).
diff --git a/docs/pipeline/data/tokenizer.md b/docs/pipeline/data/tokenizer.md
new file mode 100644
index 00000000..a449e181
--- /dev/null
+++ b/docs/pipeline/data/tokenizer.md
@@ -0,0 +1,72 @@
+# Tokenizer
+
+![pipeline](../../images/pipeline.png#only-light)
+![pipeline](../../images/pipeline-dark.png#only-dark)
+
+The Tokenizer pipeline splits text into tokens. This is primarily used for keyword / term indexing.
+
+_Note: Transformers-based models have their own tokenizers and this pipeline isn't designed for working with Transformers models._
+
+## Example
+
+The following shows a simple example using this pipeline.
+
+```python
+from txtai.pipeline import Tokenizer
+
+# Create and run pipeline
+tokenizer = Tokenizer()
+tokenizer("text to tokenize")
+
+# Whitespace tokenization
+tokenizer = Tokenizer(whitespace=True)
+tokenizer("text to tokenize")
+
+# Tokenize using a regular expression
+tokenizer = Tokenizer(regexp=r"\w{5,}")
+tokenizer("text to tokenize")
+```
+
+## Configuration-driven example
+
+Pipelines are run with Python or configuration. Pipelines can be instantiated in [configuration](../../../api/configuration/#pipeline) using the lower case name of the pipeline. Configuration-driven pipelines are run with [workflows](../../../workflow/#configuration-driven-example) or the [API](../../../api#local-instance).
+
+### config.yml
+```yaml
+# Create pipeline using lower case class name
+tokenizer:
+
+# Run pipeline with workflow
+workflow:
+ tokenizer:
+ tasks:
+ - action: tokenizer
+```
+
+### Run with Workflows
+
+```python
+from txtai import Application
+
+# Create and run pipeline with workflow
+app = Application("config.yml")
+list(app.workflow("tokenizer", ["text to tokenize"]))
+```
+
+### Run with API
+
+```bash
+CONFIG=config.yml uvicorn "txtai.api:app" &
+
+curl \
+ -X POST "http://localhost:8000/workflow" \
+ -H "Content-Type: application/json" \
+ -d '{"name":"tokenizer", "elements":["text"]}'
+```
+
+## Methods
+
+Python documentation for the pipeline.
+
+### ::: txtai.pipeline.Tokenizer.__init__
+### ::: txtai.pipeline.Tokenizer.__call__
diff --git a/docs/pipeline/index.md b/docs/pipeline/index.md
index 859eb2dd..6e146b45 100644
--- a/docs/pipeline/index.md
+++ b/docs/pipeline/index.md
@@ -26,6 +26,7 @@ The `LLM` and `RAG` pipelines also have integrations for [llama.cpp](https://git
- [Segmentation](data/segmentation)
- [Tabular](data/tabular)
- [Text extraction](data/textractor)
+ - [Tokenizer](data/tokenizer)
- Image
- [Caption](image/caption)
- [Image Hash](image/imagehash)
diff --git a/mkdocs.yml b/mkdocs.yml
index d577ccbe..4a0cf52b 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -91,6 +91,7 @@ nav:
- Segmentation: pipeline/data/segmentation.md
- Tabular: pipeline/data/tabular.md
- Textractor: pipeline/data/textractor.md
+ - Tokenizer: pipeline/data/tokenizer.md
- Image:
- Caption: pipeline/image/caption.md
- Image Hash: pipeline/image/imagehash.md