broadfield-dev commited on
Commit
f65bd99
·
verified ·
1 Parent(s): 4eddf44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -52,21 +52,18 @@ def init_db():
52
  except Exception as e:
53
  print(f"Cloud sync error: {e}")
54
 
55
- # 2. Initialize Memvid
56
  try:
57
- # Step 1: Initialize the handle (This works, but defaults to ReadOnly)
58
- db = Memvid(DB_PATH)
59
 
60
- # Step 2: Explicitly switch to Write Mode using instance methods
61
- # Based on dir(db) showing 'create' and 'open'
62
  if os.path.exists(DB_PATH):
63
- print(f"📂 File exists. Calling db.open() to enable write access...")
64
- if hasattr(db, 'open'):
65
- db.open()
66
  else:
67
- print(f"✨ New file. Calling db.create() to initialize...")
68
- if hasattr(db, 'create'):
69
- db.create()
70
 
71
  print("✅ Database initialized.")
72
 
@@ -111,7 +108,7 @@ def add_memory():
111
  return jsonify({"error": "No content provided"}), 400
112
 
113
  try:
114
- # FIX: Payload must be a DICT (Solved 'str' cannot be converted to 'PyDict')
115
  payload = {
116
  "text": content,
117
  "title": "User Memory",
@@ -145,8 +142,7 @@ def search_memory():
145
  return jsonify({"error": "No query provided"}), 400
146
 
147
  try:
148
- # FIX: query must be STRING (Solved 'dict' cannot be converted to 'PyString')
149
- # Use .find() based on your logs
150
  results = db.find(query, top_k=5)
151
 
152
  formatted_results = []
 
52
  except Exception as e:
53
  print(f"Cloud sync error: {e}")
54
 
55
+ # 2. Initialize Memvid - FIX: No parameters in constructor
56
  try:
57
+ # Step 1: Initialize the handle without parameters
58
+ db = Memvid()
59
 
60
+ # Step 2: Open or create the database file
 
61
  if os.path.exists(DB_PATH):
62
+ print(f"📂 File exists. Opening database at {DB_PATH}...")
63
+ db.open(DB_PATH)
 
64
  else:
65
+ print(f"✨ New file. Creating database at {DB_PATH}...")
66
+ db.create(DB_PATH)
 
67
 
68
  print("✅ Database initialized.")
69
 
 
108
  return jsonify({"error": "No content provided"}), 400
109
 
110
  try:
111
+ # Payload must be a dict
112
  payload = {
113
  "text": content,
114
  "title": "User Memory",
 
142
  return jsonify({"error": "No query provided"}), 400
143
 
144
  try:
145
+ # Query must be a string
 
146
  results = db.find(query, top_k=5)
147
 
148
  formatted_results = []