Qdrant Manager
Module for managing Qdrant vector database collections.
logger
module-attribute
logger = getLogger(__name__)
HTTP_NOT_FOUND
module-attribute
HTTP_NOT_FOUND = 404
QdrantManager
Manages interactions with a Qdrant vector database collection.
Handles initialization, adding/upserting points (vectors + payload), searching, and retrieving points based on IDs or filters. Uses an AsyncQdrantClient for non-blocking operations.
Source code in src/codemap/processor/vector/qdrant_manager.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 |
|
value_error_msg
class-attribute
instance-attribute
value_error_msg = "Filter condition cannot be None if point_ids are not provided"
__init__
__init__(
config_loader: ConfigLoader,
collection_name: str | None = None,
dim: int | None = None,
distance: Distance | None = None,
api_key: str | None = None,
url: str | None = None,
prefer_grpc: bool | None = None,
timeout: float | None = None,
) -> None
Initialize the QdrantManager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_loader
|
ConfigLoader
|
Configuration loader instance. |
required |
location
|
Path for local storage or ":memory:". Ignored if url is provided. |
required | |
collection_name
|
str | None
|
Name of the Qdrant collection to use. |
None
|
dim
|
int | None
|
Dimension of the vectors. |
None
|
distance
|
Distance | None
|
Distance metric for vector comparison. |
None
|
api_key
|
str | None
|
API key for Qdrant Cloud authentication. |
None
|
url
|
str | None
|
URL for connecting to a remote Qdrant instance (overrides location). |
None
|
prefer_grpc
|
bool | None
|
Whether to prefer gRPC over REST. |
None
|
timeout
|
float | None
|
Connection timeout in seconds. |
None
|
Source code in src/codemap/processor/vector/qdrant_manager.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
config_loader
instance-attribute
config_loader = config_loader
collection_name
instance-attribute
collection_name = collection_name or 'codemap_vectors'
dim
instance-attribute
dim = dim or dimension
distance
instance-attribute
distance = distance or default_distance
client_args
instance-attribute
client_args = {k: _efor (k, v) in items() if v is not None}
client
instance-attribute
client: AsyncQdrantClient | None = None
is_initialized
instance-attribute
is_initialized = False
initialize
async
initialize() -> None
Asynchronously initialize the Qdrant client and ensure the collection exists.
Source code in src/codemap/processor/vector/qdrant_manager.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
upsert_points
async
upsert_points(points: list[PointStruct]) -> None
Add or update points (vectors and payloads) in the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
list[PointStruct]
|
A list of Qdrant PointStruct objects. Each payload should be a dict matching ChunkMetadataSchema. |
required |
Source code in src/codemap/processor/vector/qdrant_manager.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
delete_points
async
delete_points(point_ids: list[str]) -> None
Delete points from the collection by their IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point_ids
|
list[str]
|
A list of point IDs to delete. |
required |
Source code in src/codemap/processor/vector/qdrant_manager.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|
delete_points_by_filter
async
delete_points_by_filter(qdrant_filter: Filter) -> None
Delete points from the collection based on a filter condition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qdrant_filter
|
Filter
|
A Qdrant Filter object specifying the points to delete. |
required |
Source code in src/codemap/processor/vector/qdrant_manager.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
search
async
search(
query_vector: list[float],
k: int = 5,
query_filter: Filter | None = None,
) -> list[ScoredPoint]
Perform a vector search with optional filtering.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_vector
|
list[float]
|
The vector to search for. |
required |
k
|
int
|
The number of nearest neighbors to return. |
5
|
query_filter
|
Filter | None
|
Optional Qdrant filter conditions. |
None
|
Returns:
Type | Description |
---|---|
list[ScoredPoint]
|
A list of ScoredPoint objects, including ID, score, and payload. |
Source code in src/codemap/processor/vector/qdrant_manager.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
get_all_point_ids_with_filter
async
get_all_point_ids_with_filter(
query_filter: Filter | None = None,
) -> list[str | int | UUID]
Retrieves all point IDs currently in the collection, optionally filtered.
Uses scrolling API to handle potentially large collections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_filter
|
Filter | None
|
Optional Qdrant filter to apply. |
None
|
Returns:
Type | Description |
---|---|
list[str | int | UUID]
|
A list of all point IDs matching the filter. |
Source code in src/codemap/processor/vector/qdrant_manager.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
|
get_payloads_by_ids
async
get_payloads_by_ids(
point_ids: list[str | int | UUID],
) -> dict[str, dict[str, Any]]
Retrieves payloads for specific point IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point_ids
|
list[str | int | UUID]
|
List of point IDs to fetch payloads for. |
required |
Returns:
Type | Description |
---|---|
dict[str, dict[str, Any]]
|
A dictionary mapping point IDs (as strings) to their payloads (as dicts matching ChunkMetadataSchema). |
Source code in src/codemap/processor/vector/qdrant_manager.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
|
close
async
close() -> None
Close the AsyncQdrantClient connection.
Source code in src/codemap/processor/vector/qdrant_manager.py
451 452 453 454 455 456 457 458 459 460 461 |
|
__aenter__
async
__aenter__() -> QdrantManager
Enter the async context manager, initializing the Qdrant client.
Source code in src/codemap/processor/vector/qdrant_manager.py
463 464 465 466 |
|
__aexit__
async
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Exit the async context manager, closing the Qdrant client.
Source code in src/codemap/processor/vector/qdrant_manager.py
468 469 470 471 472 |
|
set_payload
async
set_payload(
filter_condition: Filter,
payload: dict[str, Any],
point_ids: list[str | int | UUID] | None = None,
key: str | None = None,
) -> None
Set specific payload fields for points without overwriting existing fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
payload
|
dict[str, Any]
|
Dictionary of payload fields to set |
required |
point_ids
|
list[str | int | UUID] | None
|
Optional list of point IDs to update |
None
|
filter_condition
|
Filter
|
Optional filter to select points |
required |
key
|
str | None
|
Optional specific payload key path to modify |
None
|
Source code in src/codemap/processor/vector/qdrant_manager.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
|
overwrite_payload
async
overwrite_payload(
payload: dict[str, Any],
point_ids: list[str | int | UUID] | None = None,
filter_condition: Filter | None = None,
) -> None
Completely replace the payload for points with the new payload.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
payload
|
dict[str, Any]
|
Dictionary of payload fields to set |
required |
point_ids
|
list[str | int | UUID] | None
|
Optional list of point IDs to update |
None
|
filter_condition
|
Filter | None
|
Optional filter to select points |
None
|
Source code in src/codemap/processor/vector/qdrant_manager.py
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
|
clear_payload
async
clear_payload(
point_ids: list[str | int | UUID] | None = None,
filter_condition: Filter | None = None,
) -> None
Remove all payload fields from points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point_ids
|
list[str | int | UUID] | None
|
Optional list of point IDs to update |
None
|
filter_condition
|
Filter | None
|
Optional filter to select points |
None
|
Source code in src/codemap/processor/vector/qdrant_manager.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 |
|
delete_payload_keys
async
delete_payload_keys(
keys: list[str],
point_ids: list[str | int | UUID] | None = None,
filter_condition: Filter | None = None,
) -> None
Delete specific payload fields from points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
list[str]
|
List of payload field keys to delete |
required |
point_ids
|
list[str | int | UUID] | None
|
Optional list of point IDs to update |
None
|
filter_condition
|
Filter | None
|
Optional filter to select points |
None
|
Source code in src/codemap/processor/vector/qdrant_manager.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 |
|
get_all_chunks_content_hashes
async
get_all_chunks_content_hashes() -> set[str]
Retrieves all content hashes of chunks in the collection.
Used for deduplication when syncing.
Returns:
Type | Description |
---|---|
set[str]
|
A set of combined content_hash:file_content_hash strings for all chunks in the collection. |
Source code in src/codemap/processor/vector/qdrant_manager.py
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 |
|
create_qdrant_point
create_qdrant_point(
chunk_id: str,
vector: list[float],
payload: dict[str, Any],
) -> PointStruct
Helper function to create a Qdrant PointStruct.
Ensures the ID is treated appropriately (UUIDs if possible).
Source code in src/codemap/processor/vector/qdrant_manager.py
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 |
|