phaethon-order commited on
Commit
2837fde
·
unverified ·
1 Parent(s): b4d5d94
Files changed (1) hide show
  1. infrastructure/database.py +6 -3
infrastructure/database.py CHANGED
@@ -446,7 +446,8 @@ def add_document(*, sha256, title=None, source_path=None, doc_type=None, jurisdi
446
  raise
447
  else:
448
  raise
449
- return Document(doc_id=new_doc_id, **metadata)
 
450
 
451
  def add_chunk(doc_id: int, chunk_id: int, text: str, chunk_index: int, token_count: int | None = None,
452
  page_start: int | None = None, page_end: int | None = None, section_number: str | None = None,
@@ -471,8 +472,10 @@ def add_chunk(doc_id: int, chunk_id: int, text: str, chunk_index: int, token_cou
471
 
472
  _chunks_collection.add(ids=[str(chunk_id)], documents=[text], metadatas=[metadata])
473
  _logger.info("DB added chunk %s for doc_id=%s", chunk_id, doc_id)
474
-
475
- return Chunk(chunk_id=chunk_id, doc_id=doc_id, text=text, chunk_index=chunk_index, **metadata)
 
 
476
 
477
  def upsert_embedding(chunk_id: int, model: str, dim: int, vector_bytes: bytes):
478
  vector = np.frombuffer(vector_bytes, dtype=np.float32).tolist()
 
446
  raise
447
  else:
448
  raise
449
+ # Normalize return via from_chroma to ensure datetime fields are parsed
450
+ return Document.from_chroma(new_doc_id, dict(metadata))
451
 
452
  def add_chunk(doc_id: int, chunk_id: int, text: str, chunk_index: int, token_count: int | None = None,
453
  page_start: int | None = None, page_end: int | None = None, section_number: str | None = None,
 
472
 
473
  _chunks_collection.add(ids=[str(chunk_id)], documents=[text], metadatas=[metadata])
474
  _logger.info("DB added chunk %s for doc_id=%s", chunk_id, doc_id)
475
+
476
+ # Avoid passing duplicate values for parameters already provided explicitly
477
+ safe_meta = {k: v for k, v in metadata.items() if k not in {"doc_id", "chunk_index"}}
478
+ return Chunk(chunk_id=chunk_id, doc_id=doc_id, text=text, chunk_index=chunk_index, **safe_meta)
479
 
480
  def upsert_embedding(chunk_id: int, model: str, dim: int, vector_bytes: bytes):
481
  vector = np.frombuffer(vector_bytes, dtype=np.float32).tolist()