Repository navigation
Expand file tree
/
Copy pathqdrant_server_mode.patch
More file actions
61 lines (59 loc) · 2.64 KB
/
Copy pathqdrant_server_mode.patch
File metadata and controls
61 lines (59 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
--- a/mcp_server/utils/semantic_indexer.py
+++ b/mcp_server/utils/semantic_indexer.py
@@ -75,17 +75,46 @@ class SemanticIndexer:
self.metadata_file = ".index_metadata.json"
self.path_resolver = path_resolver or PathResolver()
- # Support both memory and HTTP URLs
- if qdrant_path.startswith("http"):
- # For HTTP URLs, parse properly
- self.qdrant = QdrantClient(url=qdrant_path)
- elif qdrant_path == ":memory:":
- # Memory mode
- self.qdrant = QdrantClient(location=":memory:")
- else:
- # Local file path - use path parameter to avoid IDNA issues
- self.qdrant = QdrantClient(path=qdrant_path)
+ # Initialize Qdrant client with server mode preference
+ self.qdrant = self._init_qdrant_client(qdrant_path)
self.wrapper = TreeSitterWrapper()
+
+ def _init_qdrant_client(self, qdrant_path: str) -> QdrantClient:
+ """Initialize Qdrant client with server mode preference."""
+ # First, try server mode (recommended for concurrent access)
+ server_url = os.environ.get("QDRANT_URL", "http://localhost:6333")
+
+ if os.environ.get("QDRANT_USE_SERVER", "true").lower() == "true":
+ try:
+ # Try connecting to Qdrant server
+ client = QdrantClient(url=server_url, timeout=5)
+ # Test connection
+ client.get_collections()
+ logger.info(f"Connected to Qdrant server at {server_url}")
+ return client
+ except Exception as e:
+ logger.warning(f"Qdrant server not available at {server_url}: {e}")
+
+ # Support explicit HTTP URLs
+ if qdrant_path.startswith("http"):
+ return QdrantClient(url=qdrant_path)
+
+ # Memory mode
+ if qdrant_path == ":memory:":
+ return QdrantClient(location=":memory:")
+
+ # Local file path with lock cleanup
+ try:
+ # Clean up any stale locks
+ lock_file = Path(qdrant_path) / ".lock"
+ if lock_file.exists():
+ logger.warning(f"Removing stale Qdrant lock file: {lock_file}")
+ lock_file.unlink()
+
+ client = QdrantClient(path=qdrant_path)
+ logger.info(f"Using file-based Qdrant at {qdrant_path}")
+ return client
+ except Exception as e:
+ logger.error(f"Failed to initialize Qdrant: {e}")
+ raise
# Initialize Voyage AI client with proper API key handling
api_key = os.environ.get("VOYAGE_API_KEY") or os.environ.get(