MCPcopy Create free account
hub / github.com/cosdata/cosdata / _batch

Function _batch

tests/test_hybrid.py:830–866  ·  view source on GitHub ↗
(batch_indices, batch_index)

Source from the content-addressed store, hash-verified

828 qps_tracker = QPSTracker()
829
830 def _batch(batch_indices, batch_index):
831 batch_start_time = time.time()
832 failed_count = 0
833
834 try:
835 batch_dense = [dense_query_vectors[i].tolist() for i in batch_indices]
836 batch_text = [text_queries[i] for i in batch_indices]
837
838 # Use batch_hybrid for better performance
839 batch_results = collection.search.batch_hybrid(
840 dense_queries=batch_dense,
841 sparse_queries=batch_text,
842 top_k=top_k,
843 dense_weight=0.5,
844 sparse_weight=0.5,
845 )
846
847 # Format results consistently
848 formatted_results = []
849 for result in batch_results:
850 if isinstance(result, dict) and "results" in result:
851 formatted = [
852 {"id": r["id"], "score": r["score"]}
853 for r in result["results"]
854 ]
855 else:
856 formatted = [{"id": r["id"], "score": r["score"]} for r in result]
857 formatted_results.append(formatted)
858
859 except Exception as e:
860 print(f"Batch hybrid search failed: {e}")
861 failed_count = len(batch_indices)
862 formatted_results = [[]] * len(batch_indices)
863
864 batch_duration = time.time() - batch_start_time
865 qps_tracker.record_query_batch(len(batch_indices), batch_duration, failed_count)
866 return formatted_results
867
868 # Prepare batches
869 batches = []

Callers

nothing calls this directly

Calls 2

record_query_batchMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected