Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Update workflow documentation to note generator execution, closes #336

davidmezzetti8fd8e10eb407
diff --git a/docs/workflow/index.md b/docs/workflow/index.md
index 1815d0ef..0ec3bc20 100644
--- a/docs/workflow/index.md
+++ b/docs/workflow/index.md
@@ -14,7 +14,22 @@ workflow = Workflow([Task(lambda x: [y * 2 for y in x])])
list(workflow([1, 2, 3]))
```
-This example simply multiplies each input value and returns a outputs via a generator.
+This example multiplies each input value by 2 and returns transformed elements via a generator.
+
+Since workflows run as generators, output must be consumed for execution to occur. The following snippets show how output can be consumed.
+
+```python
+# Small dataset where output fits in memory
+list(workflow(elements))
+
+# Large dataset
+for output in workflow(elements):
+ function(output)
+
+# Large dataset where output is discarded
+for _ in workflow(elements):
+ pass
+```
Workflows are run with Python or configuration. Examples of both methods are shown below.
diff --git a/src/python/txtai/workflow/base.py b/src/python/txtai/workflow/base.py
index bc9eb285..45e39c59 100644
--- a/src/python/txtai/workflow/base.py
+++ b/src/python/txtai/workflow/base.py
@@ -49,13 +49,14 @@ class Workflow:
def __call__(self, elements):
"""
- Executes a workflow for input elements.
+ Executes a workflow for input elements. This method returns a generator that yields transformed
+ data elements.
Args:
elements: iterable data elements
Returns:
- transformed data elements
+ generator that yields transformed data elements
"""
# Create execute instance for this run