GuglielmoTor commited on
Commit
917a83b
·
verified ·
1 Parent(s): ba2acc2

Update eb_agent_module.py

Browse files
Files changed (1) hide show
  1. eb_agent_module.py +27 -24
eb_agent_module.py CHANGED
@@ -174,38 +174,41 @@ class AdvancedRAGSystem:
174
  return None
175
 
176
  try:
177
- # Standard google-generativeai call:
178
- # embedding_response = genai.embed_content(
179
- # model=self.embedding_model_name, # e.g., "models/text-embedding-004"
180
- # content=text,
181
- # task_type="RETRIEVAL_DOCUMENT" # or "SEMANTIC_SIMILARITY"
182
- # )
183
- # return np.array(embedding_response['embedding'])
184
-
185
- # Using the provided client.models.embed_content structure:
186
- # This might require specific types for config.
187
  embed_config_payload = None
188
- if GENAI_AVAILABLE and hasattr(types, 'EmbedContentConfig'): # Assuming types.EmbedContentConfig is relevant
189
- # The task_type for EmbedContentConfig might differ, e.g., "SEMANTIC_SIMILARITY" or "RETRIEVAL_DOCUMENT"
190
  embed_config_payload = types.EmbedContentConfig(task_type="RETRIEVAL_DOCUMENT")
191
-
192
-
193
- response = client.models.embed_content( # This is the user's original call structure
194
  model=f"models/{self.embedding_model_name}" if not self.embedding_model_name.startswith("models/") else self.embedding_model_name,
195
- contents=text, # Original used 'contents', genai.embed_content uses 'content'
196
- config=embed_config_payload # Original passed 'config'
197
  )
198
 
199
- # Adapt response parsing based on actual client.models.embed_content behavior
 
 
 
200
  if hasattr(response, 'embeddings') and isinstance(response.embeddings, list) and len(response.embeddings) > 0:
201
- # This structure `response.embeddings[0]` seems specific.
202
- # Standard genai.embed_content returns a dict `{'embedding': [values]}`
203
- return np.array(response.embeddings[0])
204
- elif hasattr(response, 'embedding'): # Common for genai.embed_content
205
- return np.array(response.embedding)
 
 
 
 
 
 
 
 
 
 
 
206
  else:
207
- logging.error(f"Unexpected embedding response format: {response}")
208
  return None
 
209
  except Exception as e:
210
  logging.error(f"Error in _embed_single_document_sync for text '{text[:50]}...': {e}", exc_info=True)
211
  raise
 
174
  return None
175
 
176
  try:
 
 
 
 
 
 
 
 
 
 
177
  embed_config_payload = None
178
+ if GENAI_AVAILABLE and hasattr(types, 'EmbedContentConfig'):
 
179
  embed_config_payload = types.EmbedContentConfig(task_type="RETRIEVAL_DOCUMENT")
180
+
181
+ response = client.models.embed_content(
 
182
  model=f"models/{self.embedding_model_name}" if not self.embedding_model_name.startswith("models/") else self.embedding_model_name,
183
+ contents=text,
184
+ config=embed_config_payload
185
  )
186
 
187
+ # Debug logging to understand the response structure
188
+ logging.info(f"Embedding response type: {type(response)}")
189
+ logging.info(f"Response attributes: {dir(response)}")
190
+
191
  if hasattr(response, 'embeddings') and isinstance(response.embeddings, list) and len(response.embeddings) > 0:
192
+ embedding_obj = response.embeddings[0]
193
+ logging.info(f"Embedding object type: {type(embedding_obj)}")
194
+ logging.info(f"Embedding object attributes: {dir(embedding_obj)}")
195
+
196
+ # Try to extract values
197
+ if hasattr(embedding_obj, 'values'):
198
+ logging.info(f"Found 'values' attribute with type: {type(embedding_obj.values)}")
199
+ return np.array(embedding_obj.values)
200
+ elif hasattr(embedding_obj, 'embedding'):
201
+ logging.info(f"Found 'embedding' attribute with type: {type(embedding_obj.embedding)}")
202
+ return np.array(embedding_obj.embedding)
203
+ else:
204
+ logging.error(f"ContentEmbedding object has no 'values' or 'embedding' attribute")
205
+ logging.error(f"Available attributes: {[attr for attr in dir(embedding_obj) if not attr.startswith('_')]}")
206
+ return None
207
+
208
  else:
209
+ logging.error(f"Unexpected response structure")
210
  return None
211
+
212
  except Exception as e:
213
  logging.error(f"Error in _embed_single_document_sync for text '{text[:50]}...': {e}", exc_info=True)
214
  raise