@@ -269,7 +269,6 @@ def __init__(self, search_text, vector_queries: Optional[list[VectorQuery]]):
269
269
]
270
270
]
271
271
elif search_text == "hydrated" :
272
- # Mock search results for hydration testing with complete data
273
272
self .data = [
274
273
[
275
274
{
@@ -287,7 +286,6 @@ def __init__(self, search_text, vector_queries: Optional[list[VectorQuery]]):
287
286
]
288
287
]
289
288
elif search_text == "hydrated_multi" :
290
- # Mock search results for multiple document hydration
291
289
self .data = [
292
290
[
293
291
{
@@ -315,7 +313,6 @@ def __init__(self, search_text, vector_queries: Optional[list[VectorQuery]]):
315
313
]
316
314
]
317
315
elif search_text == "hydrated_single" :
318
- # Mock search results for single document hydration
319
316
self .data = [
320
317
[
321
318
{
@@ -458,6 +455,186 @@ def mock_retrieval_response():
458
455
)
459
456
460
457
458
+ def mock_retrieval_response_with_sorting ():
459
+ """Mock response with multiple references for testing sorting"""
460
+ return KnowledgeAgentRetrievalResponse (
461
+ response = [
462
+ KnowledgeAgentMessage (
463
+ role = "assistant" ,
464
+ content = [KnowledgeAgentMessageTextContent (text = "Test response" )],
465
+ )
466
+ ],
467
+ activity = [
468
+ KnowledgeAgentSearchActivityRecord (
469
+ id = 1 ,
470
+ target_index = "index" ,
471
+ query = KnowledgeAgentSearchActivityRecordQuery (search = "first query" ),
472
+ count = 10 ,
473
+ elapsed_ms = 50 ,
474
+ ),
475
+ KnowledgeAgentSearchActivityRecord (
476
+ id = 2 ,
477
+ target_index = "index" ,
478
+ query = KnowledgeAgentSearchActivityRecordQuery (search = "second query" ),
479
+ count = 10 ,
480
+ elapsed_ms = 50 ,
481
+ ),
482
+ ],
483
+ references = [
484
+ KnowledgeAgentAzureSearchDocReference (
485
+ id = "2" , # Higher ID for testing interleaved sorting
486
+ activity_source = 2 ,
487
+ doc_key = "doc2" ,
488
+ source_data = {"content" : "Content 2" , "sourcepage" : "page2.pdf" },
489
+ ),
490
+ KnowledgeAgentAzureSearchDocReference (
491
+ id = "1" , # Lower ID for testing interleaved sorting
492
+ activity_source = 1 ,
493
+ doc_key = "doc1" ,
494
+ source_data = {"content" : "Content 1" , "sourcepage" : "page1.pdf" },
495
+ ),
496
+ ],
497
+ )
498
+
499
+
500
+ def mock_retrieval_response_with_duplicates ():
501
+ """Mock response with duplicate doc_keys for testing deduplication"""
502
+ return KnowledgeAgentRetrievalResponse (
503
+ response = [
504
+ KnowledgeAgentMessage (
505
+ role = "assistant" ,
506
+ content = [KnowledgeAgentMessageTextContent (text = "Test response" )],
507
+ )
508
+ ],
509
+ activity = [
510
+ KnowledgeAgentSearchActivityRecord (
511
+ id = 1 ,
512
+ target_index = "index" ,
513
+ query = KnowledgeAgentSearchActivityRecordQuery (search = "query for doc1" ),
514
+ count = 10 ,
515
+ elapsed_ms = 50 ,
516
+ ),
517
+ KnowledgeAgentSearchActivityRecord (
518
+ id = 2 ,
519
+ target_index = "index" ,
520
+ query = KnowledgeAgentSearchActivityRecordQuery (search = "another query for doc1" ),
521
+ count = 10 ,
522
+ elapsed_ms = 50 ,
523
+ ),
524
+ ],
525
+ references = [
526
+ KnowledgeAgentAzureSearchDocReference (
527
+ id = "1" ,
528
+ activity_source = 1 ,
529
+ doc_key = "doc1" , # Same doc_key
530
+ source_data = {"content" : "Content 1" , "sourcepage" : "page1.pdf" },
531
+ ),
532
+ KnowledgeAgentAzureSearchDocReference (
533
+ id = "2" ,
534
+ activity_source = 2 ,
535
+ doc_key = "doc1" , # Duplicate doc_key
536
+ source_data = {"content" : "Content 1" , "sourcepage" : "page1.pdf" },
537
+ ),
538
+ KnowledgeAgentAzureSearchDocReference (
539
+ id = "3" ,
540
+ activity_source = 1 ,
541
+ doc_key = "doc2" , # Different doc_key
542
+ source_data = {"content" : "Content 2" , "sourcepage" : "page2.pdf" },
543
+ ),
544
+ ],
545
+ )
546
+
547
+
548
+ async def mock_search_for_hydration (* args , ** kwargs ):
549
+ """Mock search that returns documents matching the filter"""
550
+ filter_param = kwargs .get ("filter" , "" )
551
+
552
+ # Create documents based on filter - use search_text to distinguish different calls
553
+ search_text = ""
554
+ if "doc1" in filter_param and "doc2" in filter_param :
555
+ search_text = "hydrated_multi"
556
+ elif "doc1" in filter_param :
557
+ search_text = "hydrated_single"
558
+ else :
559
+ search_text = "hydrated_empty"
560
+
561
+ return MockAsyncSearchResultsIterator (search_text , None )
562
+
563
+
564
+ def mock_retrieval_response_with_missing_doc_key ():
565
+ """Mock response with missing doc_key to test continue condition"""
566
+ return KnowledgeAgentRetrievalResponse (
567
+ response = [
568
+ KnowledgeAgentMessage (
569
+ role = "assistant" ,
570
+ content = [KnowledgeAgentMessageTextContent (text = "Test response" )],
571
+ )
572
+ ],
573
+ activity = [
574
+ KnowledgeAgentSearchActivityRecord (
575
+ id = 1 ,
576
+ target_index = "index" ,
577
+ query = KnowledgeAgentSearchActivityRecordQuery (search = "query" ),
578
+ count = 10 ,
579
+ elapsed_ms = 50 ,
580
+ ),
581
+ ],
582
+ references = [
583
+ KnowledgeAgentAzureSearchDocReference (
584
+ id = "1" ,
585
+ activity_source = 1 ,
586
+ doc_key = None , # Missing doc_key
587
+ source_data = {"content" : "Content 1" , "sourcepage" : "page1.pdf" },
588
+ ),
589
+ KnowledgeAgentAzureSearchDocReference (
590
+ id = "2" ,
591
+ activity_source = 1 ,
592
+ doc_key = "" , # Empty doc_key
593
+ source_data = {"content" : "Content 2" , "sourcepage" : "page2.pdf" },
594
+ ),
595
+ KnowledgeAgentAzureSearchDocReference (
596
+ id = "3" ,
597
+ activity_source = 1 ,
598
+ doc_key = "doc3" , # Valid doc_key
599
+ source_data = {"content" : "Content 3" , "sourcepage" : "page3.pdf" },
600
+ ),
601
+ ],
602
+ )
603
+
604
+
605
+ def mock_retrieval_response_with_top_limit ():
606
+ """Mock response with many references to test top limit during document building"""
607
+ references = []
608
+ for i in range (15 ): # More than any reasonable top limit
609
+ references .append (
610
+ KnowledgeAgentAzureSearchDocReference (
611
+ id = str (i ),
612
+ activity_source = 1 ,
613
+ doc_key = f"doc{ i } " ,
614
+ source_data = {"content" : f"Content { i } " , "sourcepage" : f"page{ i } .pdf" },
615
+ )
616
+ )
617
+
618
+ return KnowledgeAgentRetrievalResponse (
619
+ response = [
620
+ KnowledgeAgentMessage (
621
+ role = "assistant" ,
622
+ content = [KnowledgeAgentMessageTextContent (text = "Test response" )],
623
+ )
624
+ ],
625
+ activity = [
626
+ KnowledgeAgentSearchActivityRecord (
627
+ id = 1 ,
628
+ target_index = "index" ,
629
+ query = KnowledgeAgentSearchActivityRecordQuery (search = "query" ),
630
+ count = 10 ,
631
+ elapsed_ms = 50 ,
632
+ ),
633
+ ],
634
+ references = references ,
635
+ )
636
+
637
+
461
638
class MockAudio :
462
639
def __init__ (self , audio_data ):
463
640
self .audio_data = audio_data
0 commit comments