-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvectorstore_cloud.py
More file actions
28 lines (25 loc) · 828 Bytes
/
Copy pathvectorstore_cloud.py
File metadata and controls
28 lines (25 loc) · 828 Bytes
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
# vectorstore_cloud.py
from pymongo import MongoClient
import json
def _load_config():
with open("config.json", "r", encoding="utf-8") as f:
return json.load(f)
def _get_collection():
cfg = _load_config()
if not cfg["cloud"]["enabled"]:
return None
client = MongoClient(cfg["cloud"]["mongo_uri"])
db = client[cfg["cloud"]["db_name"]]
return db[cfg["cloud"]["collection"]]
def cloud_upsert_chunks(chunks):
"""
chunks: list of dicts: {id, text, meta}
(we do not store raw embeddings in cloud here; just the text + meta for sync)
"""
col = _get_collection()
if col is None:
return
for ch in chunks:
col.update_one({"_id": ch["id"]},
{"$set": {"text": ch["text"], "meta": ch["meta"]}},
upsert=True)