MCPcopy
hub / github.com/langroid/langroid / add_documents

Method add_documents

langroid/vector_store/postgres.py:338–364  ·  view source on GitHub ↗
(self, documents: Sequence[Document])

Source from the content-addressed store, hash-verified

336 return documents
337
338 def add_documents(self, documents: Sequence[Document]) -> None:
339 super().maybe_add_ids(documents)
340 for doc in documents:
341 doc.metadata.id = str(PostgresDB._id_to_uuid(doc.metadata.id, doc.metadata))
342
343 embeddings = self.embedding_fn([doc.content for doc in documents])
344
345 batch_size = self.config.batch_size
346 with self.SessionLocal() as session:
347 for i in range(0, len(documents), batch_size):
348 batch_docs = documents[i : i + batch_size]
349 batch_embeddings = embeddings[i : i + batch_size]
350
351 new_records = [
352 {
353 "id": doc.metadata.id,
354 "embedding": embedding,
355 "document": doc.content,
356 "cmetadata": doc.metadata.model_dump(),
357 }
358 for doc, embedding in zip(batch_docs, batch_embeddings)
359 ]
360
361 if new_records:
362 stmt = insert(self.embeddings_table).values(new_records)
363 session.execute(stmt)
364 session.commit()
365
366 @staticmethod
367 def _id_to_uuid(id: str, obj: object) -> str:

Callers 1

vecdbFunction · 0.95

Calls 3

maybe_add_idsMethod · 0.80
_id_to_uuidMethod · 0.80
embedding_fnMethod · 0.45

Tested by 1

vecdbFunction · 0.76