Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Resolve application references in pipelines, closes #441

davidmezzetti472ef5495c1a
diff --git a/src/python/txtai/app/base.py b/src/python/txtai/app/base.py
index 3fd52a60..47eab9f8 100644
--- a/src/python/txtai/app/base.py
+++ b/src/python/txtai/app/base.py
@@ -107,6 +107,10 @@ class Application:
if pipeline in self.config:
config = self.config[pipeline] if self.config[pipeline] else {}
+ # Add application reference, if requested
+ if "application" in config:
+ config["application"] = self
+
# Custom pipeline parameters
if pipeline == "extractor":
config["similarity"] = self.embeddings
@@ -273,8 +277,6 @@ class Application:
a list of {id: value, score: value} sorted by highest score, where id is the
document id in the embeddings model.
- Downstream applications can override this method to provide enriched search results.
-
Args:
query: query text
limit: maximum results, used if request is None
@@ -322,8 +324,6 @@ class Application:
"""
Adds a batch of documents for indexing.
- Downstream applications can override this method to also store full documents in an external system.
-
Args:
documents: list of {id: value, text: value, tags: value}
diff --git a/test/python/testapp.py b/test/python/testapp.py
index 41102699..056a7568 100644
--- a/test/python/testapp.py
+++ b/test/python/testapp.py
@@ -5,6 +5,7 @@ Application module tests
import unittest
from txtai.app import Application
+from txtai.pipeline import Pipeline
class TestApp(unittest.TestCase):
@@ -19,3 +20,27 @@ class TestApp(unittest.TestCase):
with self.assertRaises(FileNotFoundError):
Application.read("No file here")
+
+ def testParameter(self):
+ """
+ Test resolving application parameter
+ """
+
+ app = Application(
+ """
+ testapp.TestPipeline:
+ application:
+ """
+ )
+
+ # Check that application instance is not None
+ self.assertIsNotNone(app.pipelines["testapp.TestPipeline"].application)
+
+
+class TestPipeline(Pipeline):
+ """
+ Test pipeline with an application parameter.
+ """
+
+ def __init__(self, application):
+ self.application = application