Retrieve Chunks
Retrieve relevant chunks from a Milvus vector store using MMR (Maximal Marginal Relevance). Follows traditional RAG pipeline - retrieve first, then rerank. With automatic GPU/CPU search parameter optimization.
retrieve_relevant_chunks(vector_store, query, paper_ids=None, top_k=100, mmr_diversity=0.8)
Retrieve the most relevant chunks for a query using maximal marginal relevance. Automatically uses GPU-optimized search parameters if GPU is available.
In the traditional RAG pipeline, this should retrieve chunks from ALL available papers, not just pre-selected ones. The reranker will then select the best chunks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector_store
|
The Milvus vector store instance |
required | |
query
|
str
|
Query string |
required |
paper_ids
|
Optional[List[str]]
|
Optional list of paper IDs to filter by (default: None - search all papers) |
None
|
top_k
|
int
|
Number of chunks to retrieve (default: 100 for reranking pipeline) |
100
|
mmr_diversity
|
float
|
Diversity parameter for MMR (0=max diversity, 1=max relevance) |
0.8
|
Returns:
Type | Description |
---|---|
List[Document]
|
List of document chunks |
Source code in aiagents4pharma/talk2scholars/tools/pdf/utils/retrieve_chunks.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
retrieve_relevant_chunks_with_scores(vector_store, query, paper_ids=None, top_k=100, score_threshold=0.0)
Retrieve chunks with similarity scores, optimized for GPU/CPU.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector_store
|
The Milvus vector store instance |
required | |
query
|
str
|
Query string |
required |
paper_ids
|
Optional[List[str]]
|
Optional list of paper IDs to filter by |
None
|
top_k
|
int
|
Number of chunks to retrieve |
100
|
score_threshold
|
float
|
Minimum similarity score threshold |
0.0
|
Returns:
Type | Description |
---|---|
List[tuple[Document, float]]
|
List of (document, score) tuples |
Source code in aiagents4pharma/talk2scholars/tools/pdf/utils/retrieve_chunks.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|