@@ -166,7 +166,12 @@ def get_tool_description(self):
166166 "context_length" : {
167167 "type" : "integer" ,
168168 "description" : "How much context to return around the matching string (default: 100)" ,
169- "default" : 100 ,
169+ "default" : 100
170+ },
171+ "limit" : {
172+ "type" : "integer" ,
173+ "description" : "How many contexts to return at most (default: 100)" ,
174+ "default" : 100
170175 },
171176 },
172177 "required" : ["query" ],
@@ -180,14 +185,20 @@ def run_tool(
180185 raise RuntimeError ("query argument missing in arguments" )
181186
182187 context_length = args .get ("context_length" , 100 )
183-
188+ limit = args .get ("limit" , 100 )
189+
184190 api = obsidian .Obsidian (api_key = api_key , host = obsidian_host )
185- results = api .search (args ["query" ], context_length )
186-
191+ results = api .search (args ["query" ], context_length , limit )
192+
187193 formatted_results = []
194+ total_results = 0
188195 for result in results :
196+ if total_results >= limit :
197+ break
189198 formatted_matches = []
190199 for match in result .get ("matches" , []):
200+ if total_results >= limit :
201+ break
191202 context = match .get ("context" , "" )
192203 match_pos = match .get ("match" , {})
193204 start = match_pos .get ("start" , 0 )
@@ -196,6 +207,7 @@ def run_tool(
196207 formatted_matches .append (
197208 {"context" : context , "match_position" : {"start" : start , "end" : end }}
198209 )
210+ total_results = total_results + 1
199211
200212 formatted_results .append (
201213 {
0 commit comments