RAG 與記憶 API 參考
boring.rag
RAG (Retrieval-Augmented Generation) System for Boring V10.24
Components: - CodeIndexer: AST-based Python code chunking - DependencyGraph: Function/class call graph - RAGRetriever: Hybrid search (vector + graph) - HyDEExpander: Query expansion with hypothetical documents (V10.24 NEW) - CrossEncoderReranker: High-precision reranking (V10.24 NEW) - EnsembleReranker: Multi-signal reranking (V10.24 NEW)
V10.24 Key Enhancements: - HyDE: Generate hypothetical code for better semantic matching (+15-20% accuracy) - Cross-Encoder Reranking: Fine-grained relevance scoring (+10-15% precision) - Ensemble Reranking: Combine semantic, keyword, structure, and usage signals
Usage
from boring.rag import RAGRetriever, create_rag_retriever from boring.rag import HyDEExpander, CrossEncoderReranker
retriever = create_rag_retriever(project_root) retriever.build_index()
Basic retrieval
results = retriever.retrieve("authentication error handling")
With HyDE expansion
hyde = HyDEExpander() expanded = hyde.expand_query("how to handle login errors") results = retriever.retrieve(expanded.hypothetical_document)
With cross-encoder reranking
reranker = CrossEncoderReranker() reranked = reranker.rerank(query, [r.chunk.content for r in results], [r.score for r in results])
CodeChunk
dataclass
A semantic chunk of code for embedding.
Source code in src/boring/rag/code_indexer.py
CodeIndexer
Parse Python files and extract semantic chunks.
Features: - AST-based parsing for accurate structure extraction - Dependency tracking (what each function calls) - Configurable chunk size limits
Source code in src/boring/rag/code_indexer.py
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 130 131 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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | |
get_changed_files(since_commit)
Identify files changed between since_commit and HEAD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
since_commit
|
str
|
Git commit hash to compare against HEAD. |
required |
Returns:
| Type | Description |
|---|---|
list[Path]
|
List of absolute paths to changed files. |
Source code in src/boring/rag/code_indexer.py
collect_files()
Collect all files that should be indexed.
Returns:
| Type | Description |
|---|---|
list[Path]
|
List of Path objects for all indexable files in the project. |
Source code in src/boring/rag/code_indexer.py
index_project(files_to_index=None)
Index files in the project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files_to_index
|
list[Path] | None
|
Optional list of files to process. If None, scans all. |
None
|
Yields:
| Type | Description |
|---|---|
CodeChunk
|
CodeChunk objects for each semantic unit |
Source code in src/boring/rag/code_indexer.py
index_file(file_path)
Extract chunks from a file (AST for Python, line-based for others).
Source code in src/boring/rag/code_indexer.py
IndexStats
dataclass
Statistics about the indexed codebase.
Source code in src/boring/rag/code_indexer.py
DependencyGraph
Bidirectional dependency graph for code chunks.
Edges: - callers[A] = {B, C} means B and C call A - callees[A] = {X, Y} means A calls X and Y
Usage
graph = DependencyGraph(chunks) callers = graph.get_callers(chunk_id) # Who calls this? impact = graph.get_impact_zone(chunk_id) # What might break?
Source code in src/boring/rag/graph_builder.py
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 130 131 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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
add_chunk(chunk)
Add a single chunk to the graph.
Source code in src/boring/rag/graph_builder.py
get_chunk(chunk_id)
get_chunks_by_name(name)
get_callers(chunk_id)
Get all chunks that call this chunk.
Use case: "Who depends on this function?"
Source code in src/boring/rag/graph_builder.py
get_callees(chunk_id)
Get all chunks that this chunk calls.
Use case: "What does this function depend on?"
Source code in src/boring/rag/graph_builder.py
get_related_chunks(seed_chunks, depth=1, direction='both')
Get related chunks via BFS on the dependency graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed_chunks
|
list[CodeChunk]
|
Starting chunks |
required |
depth
|
int
|
How many hops to traverse (default 1 per user decision) |
1
|
direction
|
str
|
"callers", "callees", or "both" |
'both'
|
Returns:
| Type | Description |
|---|---|
list[CodeChunk]
|
Related chunks (excluding seeds) |
Source code in src/boring/rag/graph_builder.py
get_impact_zone(modified_chunk_id, depth=1)
Get the "impact zone" - all chunks that might break if this one changes.
This returns all CALLERS (things that depend on the modified chunk). If you change a function, its callers might break.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modified_chunk_id
|
str
|
The chunk being modified |
required |
depth
|
int
|
How many levels of callers to include (default 1) |
1
|
Returns:
| Type | Description |
|---|---|
list[CodeChunk]
|
List of chunks that might be affected |
Source code in src/boring/rag/graph_builder.py
get_context_for_modification(modified_chunk_id)
Get comprehensive context for modifying a chunk.
Returns dict with: - callers: Who calls this (might break) - callees: What this calls (need to understand interface) - siblings: Other methods in same class
Source code in src/boring/rag/graph_builder.py
get_stats()
Get graph statistics.
Source code in src/boring/rag/graph_builder.py
find_path(from_id, to_id, max_depth=5)
Find shortest path between two chunks (if exists).
Useful for understanding how two distant pieces of code are connected.
Source code in src/boring/rag/graph_builder.py
visualize(format='mermaid', max_nodes=50)
Generate a visualization of the dependency graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format
|
str
|
Output format ("mermaid" or "json") |
'mermaid'
|
max_nodes
|
int
|
Maximum nodes to include (for readability) |
50
|
Returns:
| Type | Description |
|---|---|
str
|
String representation of the graph |
Source code in src/boring/rag/graph_builder.py
GraphStats
dataclass
HyDEExpander
HyDE (Hypothetical Document Embeddings) for improved code retrieval.
Instead of directly embedding the query, we first generate a hypothetical code snippet that would answer the query, then embed that.
This improves retrieval because: 1. Hypothetical code is closer in embedding space to actual code 2. Query intent is better captured 3. Technical jargon is made explicit
Source code in src/boring/rag/hyde.py
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 130 131 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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
__init__(use_llm=False)
Initialize HyDE expander.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_llm
|
bool
|
If True, use LLM for better hypothetical generation. If False, use template-based generation (faster, no API). |
False
|
Source code in src/boring/rag/hyde.py
expand_query(query)
Expand a query into a hypothetical document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Natural language query or error message |
required |
Returns:
| Type | Description |
|---|---|
HyDEResult
|
HyDEResult with hypothetical code and metadata |
Source code in src/boring/rag/hyde.py
HyDEResult
dataclass
TreeSitterParser
Wrapper for tree-sitter parsing.
Source code in src/boring/rag/parser.py
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 130 131 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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
is_available()
get_language_for_file(file_path)
parse_file(file_path)
Parse a file and extract semantic chunks. Returns empty list if language not supported or parser fails.
Source code in src/boring/rag/parser.py
extract_chunks(code, language)
Extract chunks from code string using tree-sitter.
V11.0: Enhanced to handle interface, type_alias, namespace, and Go method receivers.
Source code in src/boring/rag/parser.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
validate_language_support(language, test_code)
Validate that Tree-sitter queries work correctly for a given language.
V11.0: Structured testing for cross-language precision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
language
|
str
|
Language name (e.g., 'go', 'typescript') |
required |
test_code
|
str
|
Sample code to parse |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dict with validation results |
Source code in src/boring/rag/parser.py
RAGRetriever
Hybrid RAG retriever for code context.
Features: - Semantic search via ChromaDB embeddings - 1-layer graph expansion (per user decision) - Smart jump: Agent can request deeper traversal on-demand - Recency boost: recently modified files rank higher
Usage
retriever = RAGRetriever(project_root) retriever.build_index()
Basic retrieval
results = retriever.retrieve("authentication error handling")
With graph expansion for specific function
context = retriever.get_modification_context("src/auth.py", "login")
Source code in src/boring/rag/rag_retriever.py
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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 | |
is_available
property
Check if RAG system is available.
build_index(force=False, incremental=True)
Index the entire codebase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force
|
bool
|
If True, rebuild even if index exists |
False
|
incremental
|
bool
|
If True (and not force), only index changed files. |
True
|
Returns:
| Type | Description |
|---|---|
int
|
Number of chunks indexed |
Source code in src/boring/rag/rag_retriever.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
retrieve(query, n_results=10, expand_graph=True, file_filter=None, chunk_types=None, threshold=0.0, use_hyde=True, use_rerank=True)
Retrieve relevant code chunks with caching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Natural language query or error message |
required |
n_results
|
int
|
Maximum results to return |
10
|
expand_graph
|
bool
|
Whether to include 1-layer dependency context |
True
|
file_filter
|
str | None
|
Filter by file path substring (e.g., "auth") |
None
|
chunk_types
|
list[str] | None
|
Filter by chunk types (e.g., ["function", "class"]) |
None
|
threshold
|
float
|
Minimum relevance score (0.0 to 1.0) |
0.0
|
use_hyde
|
bool
|
Whether to use HyDE query expansion (V10.24+) |
True
|
use_rerank
|
bool
|
Whether to use Cross-Encoder reranking (V10.24+) |
True
|
Returns:
| Type | Description |
|---|---|
list[RetrievalResult]
|
List of RetrievalResult sorted by relevance |
Source code in src/boring/rag/rag_retriever.py
record_user_selection(chunk_id, query, session_id='')
Record that a user selected a specific chunk from results.
This feedback improves future ranking for similar queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_id
|
str
|
The chunk that was selected |
required |
query
|
str
|
The query that produced the results |
required |
session_id
|
str
|
Optional session identifier |
''
|
Source code in src/boring/rag/rag_retriever.py
retrieve_async(query, n_results=10, expand_graph=True, file_filter=None, chunk_types=None)
async
Async version of retrieve for non-blocking operations.
Wraps ChromaDB calls in a budgeted thread pool for async compatibility.
Source code in src/boring/rag/rag_retriever.py
get_modification_context(file_path, function_name=None, class_name=None)
Get comprehensive context for modifying a specific code location.
This is the "smart" entry point that returns: - The target chunk itself - Its callers (might break) - Its callees (need to understand interface) - Sibling methods (if in a class)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Relative path to the file |
required |
function_name
|
str | None
|
Name of function (optional) |
None
|
class_name
|
str | None
|
Name of class (optional) |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, list[RetrievalResult]]
|
Dict with categorized context |
Source code in src/boring/rag/rag_retriever.py
smart_expand(chunk_id, depth=2)
On-demand deeper graph traversal (Agent-triggered "smart jump").
When 1-layer expansion isn't enough, the agent can request deeper traversal for specific chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_id
|
str
|
The chunk to expand from |
required |
depth
|
int
|
How many layers to expand (default 2) |
2
|
Returns:
| Type | Description |
|---|---|
list[RetrievalResult]
|
Additional context chunks |
Source code in src/boring/rag/rag_retriever.py
generate_context_injection(query, max_tokens=4000, include_signatures_only=False)
Generate context string for AI prompt injection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
The current task or error |
required |
max_tokens
|
int
|
Maximum tokens (estimate: 4 chars = 1 token) |
4000
|
include_signatures_only
|
bool
|
If True, only include function signatures |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted context string ready for prompt injection |
Source code in src/boring/rag/rag_retriever.py
get_stats()
Get combined RAG statistics.
Source code in src/boring/rag/rag_retriever.py
update_file(file_path)
Incrementally update index for a single changed file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to the modified file |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of chunks updated |
Source code in src/boring/rag/rag_retriever.py
clear()
Clear all indexed data.
Source code in src/boring/rag/rag_retriever.py
RAGStats
dataclass
Combined statistics for RAG system.
Source code in src/boring/rag/rag_retriever.py
RetrievalResult
dataclass
A retrieved code chunk with relevance info.
Source code in src/boring/rag/rag_retriever.py
CrossEncoderReranker
Cross-encoder based reranker for high-precision code retrieval.
Cross-encoders process query-document pairs jointly, allowing for deeper semantic understanding than bi-encoder approaches.
Models: - ms-marco-MiniLM-L-6-v2: Fast, good for general text (default) - cross-encoder/ms-marco-TinyBERT-L-2: Ultra-fast - cross-encoder/stsb-roberta-base: Good for semantic similarity
Source code in src/boring/rag/reranker.py
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 130 131 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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
__init__(model_name='balanced', device='cpu')
Initialize cross-encoder reranker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Model preset ("fast", "balanced", "accurate") or HuggingFace model name |
'balanced'
|
device
|
str
|
Device to use ("cpu", "cuda", "mps") |
'cpu'
|
Source code in src/boring/rag/reranker.py
rerank(query, documents, original_scores, top_k=10, weight_original=0.3)
Rerank documents using cross-encoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query |
required |
documents
|
list[str]
|
List of document texts |
required |
original_scores
|
list[float]
|
Original retrieval scores |
required |
top_k
|
int
|
Number of results to return |
10
|
weight_original
|
float
|
Weight for original score in combination |
0.3
|
Returns:
| Type | Description |
|---|---|
list[tuple[int, RerankScore]]
|
List of (original_index, RerankScore) sorted by combined score |
Source code in src/boring/rag/reranker.py
EnsembleReranker
Ensemble reranker combining multiple signals.
Combines: 1. Cross-encoder/heuristic scores 2. Keyword matching 3. Code structure analysis 4. Usage patterns (from IntelligentRanker)
Source code in src/boring/rag/reranker.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
__init__(weights=None)
Initialize ensemble reranker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
dict[str, float] | None
|
Custom weights for each signal |
None
|
Source code in src/boring/rag/reranker.py
rerank(query, chunks, original_scores, usage_scores=None, top_k=10)
Rerank using ensemble of signals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query |
required |
chunks
|
list
|
List of code chunks with content and metadata |
required |
original_scores
|
list[float]
|
Original retrieval scores |
required |
usage_scores
|
dict[str, float] | None
|
Optional usage-based scores from IntelligentRanker |
None
|
top_k
|
int
|
Number of results to return |
10
|
Returns:
| Type | Description |
|---|---|
list[tuple[int, float]]
|
List of (original_index, final_score) sorted by score |
Source code in src/boring/rag/reranker.py
RerankScore
dataclass
Score from cross-encoder reranking.
Source code in src/boring/rag/reranker.py
expand_query_with_hyde(query, use_llm=False)
Convenience function to expand a query using HyDE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Natural language query |
required |
use_llm
|
bool
|
Whether to use LLM for generation |
False
|
Returns:
| Type | Description |
|---|---|
HyDEResult
|
HyDEResult with hypothetical document |
Source code in src/boring/rag/hyde.py
create_rag_retriever(project_root=None, persist_dir=None)
Factory function to create RAGRetriever with standard project paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_root
|
Path | None
|
Project root directory |
None
|
persist_dir
|
Path | None
|
Optional custom persist directory |
None
|
Returns:
| Type | Description |
|---|---|
RAGRetriever
|
RAGRetriever instance |