@@ -59,7 +59,8 @@ def format_entry(self, entry: Entry) -> str:
59
59
Feel free to override this method in your subclass to customize the format of the entry.
60
60
"""
61
61
entry_metadata = json .dumps (entry .metadata ) if entry .metadata else ""
62
- return f"<entry><content>{ entry .content } </content><metadata>{ entry_metadata } </metadata></entry>"
62
+ entry_id = f"<id>{ entry .id } </id>" if entry .id else ""
63
+ return f"<entry>{ entry_id } <content>{ entry .content } </content><metadata>{ entry_metadata } </metadata></entry>"
63
64
64
65
def setup_tools (self ):
65
66
"""
@@ -68,6 +69,10 @@ def setup_tools(self):
68
69
69
70
async def store (
70
71
ctx : Context ,
72
+ id : Annotated [
73
+ str | None ,
74
+ Field (description = "Point ID. If omitted, a new point is created." ),
75
+ ],
71
76
information : Annotated [str , Field (description = "Text to store" )],
72
77
collection_name : Annotated [
73
78
str , Field (description = "The collection to store the information in" )
@@ -93,7 +98,7 @@ async def store(
93
98
"""
94
99
await ctx .debug (f"Storing information { information } in Qdrant" )
95
100
96
- entry = Entry (content = information , metadata = metadata )
101
+ entry = Entry (content = information , metadata = metadata , id = id )
97
102
98
103
await self .qdrant_connector .store (entry , collection_name = collection_name )
99
104
if collection_name :
@@ -160,16 +165,147 @@ async def find(
160
165
store_foo , {"collection_name" : self .qdrant_settings .collection_name }
161
166
)
162
167
168
+ # Add new tools for point operations
169
+ async def get_point (
170
+ ctx : Context ,
171
+ point_id : Annotated [
172
+ str , Field (description = "The ID of the point to retrieve" )
173
+ ],
174
+ collection_name : Annotated [
175
+ str , Field (description = "The collection to get the point from" )
176
+ ],
177
+ ) -> str :
178
+ """
179
+ Get a specific point by its ID.
180
+ :param ctx: The context for the request.
181
+ :param point_id: The ID of the point to retrieve.
182
+ :param collection_name: The name of the collection to get the point from.
183
+ :return: The point information or error message.
184
+ """
185
+ await ctx .debug (
186
+ f"Getting point { point_id } from collection { collection_name } "
187
+ )
188
+
189
+ entry = await self .qdrant_connector .get_point_by_id (
190
+ point_id , collection_name = collection_name
191
+ )
192
+
193
+ if entry :
194
+ return self .format_entry (entry )
195
+ else :
196
+ return f"Point with ID { point_id } not found in collection { collection_name } "
197
+
198
+ async def delete_point (
199
+ ctx : Context ,
200
+ point_id : Annotated [
201
+ str , Field (description = "The ID of the point to delete" )
202
+ ],
203
+ collection_name : Annotated [
204
+ str , Field (description = "The collection to delete the point from" )
205
+ ],
206
+ ) -> str :
207
+ """
208
+ Delete a specific point by its ID.
209
+ :param ctx: The context for the request.
210
+ :param point_id: The ID of the point to delete.
211
+ :param collection_name: The name of the collection to delete the point from.
212
+ :return: Success or error message.
213
+ """
214
+ await ctx .debug (
215
+ f"Deleting point { point_id } from collection { collection_name } "
216
+ )
217
+
218
+ success = await self .qdrant_connector .delete_point_by_id (
219
+ point_id , collection_name = collection_name
220
+ )
221
+
222
+ if success :
223
+ return f"Successfully deleted point { point_id } from collection { collection_name } "
224
+ else :
225
+ return f"Failed to delete point { point_id } - point not found or collection doesn't exist"
226
+
227
+ async def update_point_payload (
228
+ ctx : Context ,
229
+ point_id : Annotated [
230
+ str , Field (description = "The ID of the point to update" )
231
+ ],
232
+ collection_name : Annotated [
233
+ str , Field (description = "The collection containing the point" )
234
+ ],
235
+ metadata : Annotated [
236
+ Metadata ,
237
+ Field (
238
+ description = "New metadata to set for the point. Any json is accepted."
239
+ ),
240
+ ],
241
+ ) -> str :
242
+ """
243
+ Update the payload (metadata) of a specific point by its ID.
244
+ :param ctx: The context for the request.
245
+ :param point_id: The ID of the point to update.
246
+ :param collection_name: The name of the collection containing the point.
247
+ :param metadata: New metadata to set for the point.
248
+ :return: Success or error message.
249
+ """
250
+ await ctx .debug (
251
+ f"Updating payload for point { point_id } in collection { collection_name } "
252
+ )
253
+
254
+ success = await self .qdrant_connector .update_point_payload (
255
+ point_id , metadata , collection_name = collection_name
256
+ )
257
+
258
+ if success :
259
+ return f"Successfully updated payload for point { point_id } in collection { collection_name } "
260
+ else :
261
+ return f"Failed to update payload for point { point_id } - point not found or collection doesn't exist"
262
+
263
+ # Apply collection name defaults to new tools
264
+ get_point_foo = get_point
265
+ delete_point_foo = delete_point
266
+ update_point_payload_foo = update_point_payload
267
+
268
+ if self .qdrant_settings .collection_name :
269
+ get_point_foo = make_partial_function (
270
+ get_point_foo , {"collection_name" : self .qdrant_settings .collection_name }
271
+ )
272
+ delete_point_foo = make_partial_function (
273
+ delete_point_foo ,
274
+ {"collection_name" : self .qdrant_settings .collection_name },
275
+ )
276
+ update_point_payload_foo = make_partial_function (
277
+ update_point_payload_foo ,
278
+ {"collection_name" : self .qdrant_settings .collection_name },
279
+ )
280
+
163
281
self .tool (
164
282
find_foo ,
165
283
name = "qdrant-find" ,
166
284
description = self .tool_settings .tool_find_description ,
167
285
)
168
286
287
+ self .tool (
288
+ get_point_foo ,
289
+ name = "qdrant-get-point" ,
290
+ description = "Get a specific point by its ID from a Qdrant collection." ,
291
+ )
292
+
169
293
if not self .qdrant_settings .read_only :
170
294
# Those methods can modify the database
171
295
self .tool (
172
296
store_foo ,
173
297
name = "qdrant-store" ,
174
298
description = self .tool_settings .tool_store_description ,
175
299
)
300
+
301
+ self .tool (
302
+ delete_point_foo ,
303
+ name = "qdrant-delete-point" ,
304
+ description = "Delete a specific point by its ID from a Qdrant collection." ,
305
+ )
306
+
307
+ self .tool (
308
+ update_point_payload_foo ,
309
+ name = "qdrant-update-point-payload" ,
310
+ description = "Update the payload (metadata) of a specific point by its ID." ,
311
+ )
0 commit comments