💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Resolve application references in pipelines, closes #441
davidmezzetti472ef5495c1a
diff --git a/src/python/txtai/app/base.py b/src/python/txtai/app/base.pyindex 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 parametersif 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 thedocument id in the embeddings model.- Downstream applications can override this method to provide enriched search results.-Args:query: query textlimit: 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.pyindex 41102699..056a7568 100644--- a/test/python/testapp.py+++ b/test/python/testapp.py@@ -5,6 +5,7 @@ Application module testsimport unittestfrom txtai.app import Application+from txtai.pipeline import Pipelineclass 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