Jarvis2345 commited on
Commit
97cf7fe
·
verified ·
1 Parent(s): 8ac0a58

deploy(S4): Blender headless pipeline + WebAR client + backend fixes

Browse files
Files changed (1) hide show
  1. backend/memory/episodic_memory.py +25 -5
backend/memory/episodic_memory.py CHANGED
@@ -18,21 +18,41 @@ try:
18
  except ImportError:
19
  pass
20
 
 
 
 
 
 
 
 
 
 
 
 
21
  async def embed(text: str) -> list[float]:
22
  """Generates an embedding for the given text using Gemini."""
23
  try:
24
  def _get_embedding():
25
  result = genai.embed_content(
26
- model="models/embedding-001",
27
  content=text,
28
  task_type="retrieval_document",
 
29
  )
30
  return result['embedding']
31
-
32
- return await asyncio.to_thread(_get_embedding)
 
 
 
33
  except Exception as e:
34
- logging.error(f"Embedding failed: {e}")
35
- return [0.0] * 768
 
 
 
 
 
36
 
37
  class EpisodicMemory:
38
  def __init__(self, persist_dir: str):
 
18
  except ImportError:
19
  pass
20
 
21
+ # "models/embedding-001" was RETIRED — it 404s ("not found for API version
22
+ # v1beta"), which meant every embed() call fell through to the zero-vector
23
+ # fallback below. That failed silently and is worse than an outright error:
24
+ # identical all-zero vectors make every document equidistant, so semantic
25
+ # retrieval returns essentially arbitrary results while still "working".
26
+ # Verified live against this key — the only models exposing embedContent are
27
+ # gemini-embedding-001, gemini-embedding-2 and gemini-embedding-2-preview.
28
+ EMBED_MODEL = "models/gemini-embedding-001"
29
+ EMBED_DIM = 768 # keep in step with the existing persona_* collections
30
+
31
+
32
  async def embed(text: str) -> list[float]:
33
  """Generates an embedding for the given text using Gemini."""
34
  try:
35
  def _get_embedding():
36
  result = genai.embed_content(
37
+ model=EMBED_MODEL,
38
  content=text,
39
  task_type="retrieval_document",
40
+ output_dimensionality=EMBED_DIM,
41
  )
42
  return result['embedding']
43
+
44
+ vec = await asyncio.to_thread(_get_embedding)
45
+ if not vec:
46
+ raise ValueError("empty embedding returned")
47
+ return vec
48
  except Exception as e:
49
+ # Loud, not silent: a zero vector destroys ranking, so make it obvious
50
+ # in the logs that retrieval quality is degraded rather than fine.
51
+ logging.error(
52
+ f"Embedding failed via {EMBED_MODEL} ({e}); returning a ZERO vector — "
53
+ "semantic ranking is degraded until this is resolved."
54
+ )
55
+ return [0.0] * EMBED_DIM
56
 
57
  class EpisodicMemory:
58
  def __init__(self, persist_dir: str):