MCPcopy Create free account
hub / github.com/AsyncFuncAI/deepwiki-open / __call__

Method __call__

api/dashscope_client.py:844–926  ·  view source on GitHub ↗

Process list of documents, generating embedding vectors for each document Args: input: List of input documents Returns: List of documents containing embedding vectors

(self, input: List[Document])

Source from the content-addressed store, hash-verified

842 self.force_recreate_db = force_recreate_db
843
844 def __call__(self, input: List[Document]) -> List[Document]:
845 """
846 Process list of documents, generating embedding vectors for each document
847
848 Args:
849 input: List of input documents
850
851 Returns:
852 List of documents containing embedding vectors
853 """
854 output = deepcopy(input)
855
856 # Convert to text list
857 embedder_input: List[str] = [chunk.text for chunk in output]
858
859 log.info(f"Starting to process embeddings for {len(embedder_input)} documents")
860
861 # Batch process embeddings
862 outputs: List[EmbedderOutput] = self.batch_embedder(
863 input=embedder_input,
864 force_recreate=self.force_recreate_db
865 )
866
867 # Validate output
868 total_embeddings = 0
869 error_batches = 0
870
871 for batch_output in outputs:
872 if batch_output.error:
873 error_batches += 1
874 log.error(f"Found error batch: {batch_output.error}")
875 elif batch_output.data:
876 total_embeddings += len(batch_output.data)
877
878 log.info(f"Embedding statistics: total {total_embeddings} valid embeddings, {error_batches} error batches")
879
880 # Assign embedding vectors back to documents
881 doc_idx = 0
882 for batch_idx, batch_output in tqdm(
883 enumerate(outputs),
884 desc="Assigning embedding vectors to documents",
885 disable=False
886 ):
887 if batch_output.error:
888 # Create empty vectors for documents in error batches
889 batch_size_actual = min(self.batch_size, len(output) - doc_idx)
890 log.warning(f"Creating empty vectors for {batch_size_actual} documents in batch {batch_idx}")
891
892 for i in range(batch_size_actual):
893 if doc_idx < len(output):
894 output[doc_idx].vector = []
895 doc_idx += 1
896 else:
897 # Assign normal embedding vectors
898 for embedding in batch_output.data:
899 if doc_idx < len(output):
900 if hasattr(embedding, 'embedding'):
901 output[doc_idx].vector = embedding.embedding

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected