Fix: Prevent Qdrant 404 errors in CI by handling missing collections gracefully#9
Conversation
Reviewer's GuideAdds graceful handling for missing Qdrant collections by refactoring the collection-initialization logic and injecting existence checks across all vector operations to eliminate 404 failures in CI. Sequence diagram for Qdrant operation with collection existence checksequenceDiagram
participant Client
participant QdrantStore
participant Qdrant
Client->>QdrantStore: upsert(collection_name, ...)
QdrantStore->>QdrantStore: check if collection exists
alt Collection does not exist
QdrantStore->>QdrantStore: _ensure_collections(collection_name)
QdrantStore->>Qdrant: create_collection
QdrantStore->>Qdrant: create_payload_index (user_id, type, tags)
end
QdrantStore->>Qdrant: upsert
Client->>QdrantStore: search(collection_name, ...)
QdrantStore->>QdrantStore: check if collection exists
alt Collection does not exist
QdrantStore->>Client: return []
else Collection exists
QdrantStore->>Qdrant: search
Qdrant->>QdrantStore: results
QdrantStore->>Client: results
end
Class diagram for updated QdrantStore methodsclassDiagram
class QdrantStore {
- client
- collection_facts
- collection_prefs
- dimension
- hnsw_m
- ef_construction
+ _ensure_collections(collection_name: Optional[str] = None)
+ upsert(collection_name: str, id: str, vector: np.ndarray, payload: Dict[str, Any])
+ search(collection_name: str, ...): List[Dict[str, Any]]
+ scroll(collection_name: str, ...): List[Dict[str, Any]]
+ delete(collection_name: str, ids: List[str])
+ get(collection_name: str, id: str): Optional[Dict[str, Any]]
+ update(collection_name: str, id: str, payload: Dict[str, Any]): bool
}
QdrantStore --> QdrantClient : uses
QdrantStore --> VectorParams
QdrantStore --> HnswConfigDiff
QdrantStore --> OptimizersConfigDiff
Flow diagram for QdrantStore operation handling missing collectionsflowchart TD
A["Operation called (search, upsert, scroll, get, delete, update)"] --> B{Does collection exist?}
B -- No --> C["For upsert: create collection via _ensure_collections"]
B -- No --> D["For read ops: return empty/None/False"]
B -- Yes --> E["Proceed with Qdrant operation"]
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
@rexdivakar Check if its fine now? |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Consider consolidating the repeated collection-exists checks into a decorator or shared helper to reduce code duplication across methods.
- Logging missing collections as warnings for expected control flow may clutter logs—consider using debug-level logging or adding a metric instead.
- Multiple client.collection_exists calls per operation could introduce latency; you might cache collection existence state or batch-check to improve performance.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider consolidating the repeated collection-exists checks into a decorator or shared helper to reduce code duplication across methods.
- Logging missing collections as warnings for expected control flow may clutter logs—consider using debug-level logging or adding a metric instead.
- Multiple client.collection_exists calls per operation could introduce latency; you might cache collection existence state or batch-check to improve performance.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
|
@rexdivakar Let me know if anything else is required |
- Use exception handling (EAFP) instead of preemptive checks in search() and scroll() - Eliminates extra network call (collection_exists) in common case - Avoid race conditions in _ensure_collections using try-except - More Pythonic and efficient approach - Improves performance by removing unnecessary checks
There was a problem hiding this comment.
Pull Request Overview
This PR fixes Qdrant 404 errors in CI by adding collection existence checks to all database operations. The changes implement Command-Query Separation where read operations return empty/default values when collections don't exist, while write operations (upsert) create collections lazily.
Key Changes:
- Added collection existence checks to read operations (
search,scroll,get,delete,update) to handle missing collections gracefully - Modified
upsertto create collections lazily if they don't exist - Parameterized
_ensure_collectionsto support creating individual collections on-demand
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Will do a full validation and merge the changes. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sure.. |
Summary
Fixes #7 - Resolves Qdrant 404 errors in CI tests when collections don't exist.
Problem
The CI pipeline fails on tests like
test_batch_add_memoriesandtest_batch_delete_memoriesdue toUnexpectedResponse: 404 (Not Found)when running inside GitHub Actions. This happens because tests callquery_points()orscroll()before creating the collection.Solution
Added collection existence checks to all Qdrant operations following Command-Query Separation principle:
Read Operations (no side effects)
search()- returns empty list if collection doesn't existscroll()- returns empty list if collection doesn't existget()- returns None if collection doesn't existdelete()- gracefully skips if collection doesn't existupdate()- returns False if collection doesn't existWrite Operations (can have side effects)
upsert()- creates collection if it doesn't existBenefits
Testing
Summary by Sourcery
Prevent Qdrant 404 errors in CI by gracefully handling missing collections in QdrantStore
Bug Fixes:
Enhancements: