Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 58 |
-
db = Memvid(
|
| 59 |
|
| 60 |
-
# Step 2:
|
| 61 |
-
# Based on dir(db) showing 'create' and 'open'
|
| 62 |
if os.path.exists(DB_PATH):
|
| 63 |
-
print(f"📂 File exists.
|
| 64 |
-
|
| 65 |
-
db.open()
|
| 66 |
else:
|
| 67 |
-
print(f"✨ New file.
|
| 68 |
-
|
| 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 |
-
#
|
| 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 |
-
#
|
| 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 = []
|