Spaces:
Sleeping
Sleeping
Update src/core/PineconeManager.py
Browse files- src/core/PineconeManager.py +30 -1
src/core/PineconeManager.py
CHANGED
|
@@ -70,4 +70,33 @@ class PineconeManager:
|
|
| 70 |
index.delete(filter={"source": filename}, namespace=namespace)
|
| 71 |
return True, f"Deleted vectors for {filename}"
|
| 72 |
except Exception as e:
|
| 73 |
-
return False, str(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
index.delete(filter={"source": filename}, namespace=namespace)
|
| 71 |
return True, f"Deleted vectors for {filename}"
|
| 72 |
except Exception as e:
|
| 73 |
+
return False, str(e)
|
| 74 |
+
|
| 75 |
+
def get_all_ids(self, index_name: str, namespace: str):
|
| 76 |
+
"""
|
| 77 |
+
Fetches all vector IDs for a user.
|
| 78 |
+
NOTE: This works best on Pinecone Serverless indexes.
|
| 79 |
+
"""
|
| 80 |
+
try:
|
| 81 |
+
idx = self.pc.Index(index_name)
|
| 82 |
+
results = []
|
| 83 |
+
# .list() returns a generator that yields lists of IDs
|
| 84 |
+
for ids in idx.list(namespace=namespace):
|
| 85 |
+
results.extend(ids)
|
| 86 |
+
return results
|
| 87 |
+
except Exception as e:
|
| 88 |
+
logger.error(f"Error listing IDs: {e}")
|
| 89 |
+
return []
|
| 90 |
+
|
| 91 |
+
def fetch_vectors(self, index_name: str, ids: list, namespace: str):
|
| 92 |
+
"""
|
| 93 |
+
Retrieves the actual data (metadata + text) for a list of IDs.
|
| 94 |
+
"""
|
| 95 |
+
try:
|
| 96 |
+
idx = self.pc.Index(index_name)
|
| 97 |
+
# Fetch has a limit of 1000 items per call usually, so we batch if needed
|
| 98 |
+
# For simplicity in this specific app, simple fetch is okay for now
|
| 99 |
+
return idx.fetch(ids=ids, namespace=namespace)
|
| 100 |
+
except Exception as e:
|
| 101 |
+
logger.error(f"Error fetching vectors: {e}")
|
| 102 |
+
return {}
|