💡 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
Move limit method to API, default limit in Application #233
davidmezzetti04d5b1d14eed
diff --git a/src/python/txtai/api/base.py b/src/python/txtai/api/base.pyindex b1b99ee9..a5f4490a 100644--- a/src/python/txtai/api/base.py+++ b/src/python/txtai/api/base.py@@ -105,3 +105,17 @@ class API(Application):return self.cluster.count()return super().count()++ def limit(self, limit):+ """+ Parses the number of results to return from the request. Allows range of 1-250, with a default of 10.++ Args:+ limit: limit parameter++ Returns:+ bounded limit+ """++ # Return between 1 and 250 results, defaults to 10+ return max(1, min(250, int(limit) if limit else 10))diff --git a/src/python/txtai/app/base.py b/src/python/txtai/app/base.pyindex 5fdf0cfb..760eb3d8 100644--- a/src/python/txtai/app/base.py+++ b/src/python/txtai/app/base.py@@ -209,21 +209,7 @@ class Application:# Attempt to resolve action as a callable functionreturn PipelineFactory.create({}, function)- def limit(self, limit):- """- Parses the number of results to return from the request. Allows range of 1-250, with a default of 10.-- Args:- limit: limit parameter-- Returns:- bounded limit- """-- # Return between 1 and 250 results, defaults to 10- return max(1, min(250, int(limit) if limit else 10))-- def search(self, query, limit=None):+ def search(self, query, limit=10):"""Finds documents in the embeddings model most similar to the input query. Returnsa list of {id: value, score: value} sorted by highest score, where id is the@@ -245,7 +231,7 @@ class Application:return None- def batchsearch(self, queries, limit=None):+ def batchsearch(self, queries, limit=10):"""Finds documents in the embeddings model most similar to the input queries. Returnsa list of {id: value, score: value} sorted by highest score per query, where id is@@ -261,7 +247,7 @@ class Application:if self.embeddings:with self.lock:- search = self.embeddings.batchsearch(queries, self.limit(limit))+ search = self.embeddings.batchsearch(queries, limit)results = []for result in search: