mirror of
https://git.mirrors.martin98.com/https://github.com/open-webui/open-webui
synced 2025-08-16 08:45:59 +08:00
Update pinecone.py
• Removed the unused Pinecone REST‐client import; we now only import ServerlessSpec and the gRPC client. • Enhanced close() • Call self.client.close() to explicitly shut down the underlying gRPC channel. • Log success or a warning on failure. • Still tear down the thread‐pool executor afterward. • Context‐manager support • Added __enter__()/__exit__() so you can do: with PineconeClient() as client: client.insert(...) # automatically calls client.close()
This commit is contained in:
parent
12c2138982
commit
3f58a17e47
@ -1,7 +1,7 @@
|
|||||||
from typing import Optional, List, Dict, Any, Union
|
from typing import Optional, List, Dict, Any, Union
|
||||||
import logging
|
import logging
|
||||||
import time # for measuring elapsed time
|
import time # for measuring elapsed time
|
||||||
from pinecone import Pinecone, ServerlessSpec
|
from pinecone import ServerlessSpec
|
||||||
|
|
||||||
import asyncio # for async upserts
|
import asyncio # for async upserts
|
||||||
import functools # for partial binding in async tasks
|
import functools # for partial binding in async tasks
|
||||||
@ -496,5 +496,18 @@ class PineconeClient(VectorDBBase):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Shut down the thread pool."""
|
"""Shut down the gRPC channel and thread pool."""
|
||||||
|
try:
|
||||||
|
self.client.close()
|
||||||
|
log.info("Pinecone gRPC channel closed.")
|
||||||
|
except Exception as e:
|
||||||
|
log.warning(f"Failed to close Pinecone gRPC channel: {e}")
|
||||||
self._executor.shutdown(wait=True)
|
self._executor.shutdown(wait=True)
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
"""Enter context manager."""
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
"""Exit context manager, ensuring resources are cleaned up."""
|
||||||
|
self.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user