verbatim_core API Reference
VerbatimTransform
verbatim_core.transform.VerbatimTransform
RAG-agnostic verbatim transform using existing components (sync/async).
Source code in packages/core/verbatim_core/transform.py
LLMSpanExtractor
verbatim_core.extractors.LLMSpanExtractor
Bases: SpanExtractor
Extract spans using an LLM with centralized client and batch processing.
Source code in packages/core/verbatim_core/extractors.py
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 | |
__init__(llm_client=None, model='gpt-4o-mini', extraction_mode='auto', max_display_spans=5, batch_size=5)
Initialize the LLM span extractor.
:param llm_client: LLM client for extraction (creates one if None) :param model: The LLM model to use (if creating new client) :param extraction_mode: "batch", "individual", or "auto" :param max_display_spans: Maximum spans to prioritize for display :param batch_size: Maximum documents to process in batch mode
Source code in packages/core/verbatim_core/extractors.py
extract_spans(question, search_results)
Extract spans using LLM with mode selection.
:param question: The query or question :param search_results: List of search results to extract from :return: Dictionary mapping result text to list of relevant spans
Source code in packages/core/verbatim_core/extractors.py
extract_spans_async(question, search_results)
async
Async version of span extraction.
:param question: The query or question :param search_results: List of search results to extract from :return: Dictionary mapping result text to list of relevant spans
Source code in packages/core/verbatim_core/extractors.py
SpanExtractor
verbatim_core.extractors.SpanExtractor
Bases: ABC
Abstract base class for span extractors.
Source code in packages/core/verbatim_core/extractors.py
extract_spans(question, search_results)
abstractmethod
Extract relevant spans from search results.
:param question: The query or question :param search_results: List of search results to extract from :return: Dictionary mapping result text to list of relevant spans
Source code in packages/core/verbatim_core/extractors.py
extract_spans_async(question, search_results)
async
Default async implementation that delegates to sync version.
Source code in packages/core/verbatim_core/extractors.py
LLMClient
verbatim_core.llm_client.LLMClient
Centralized LLM interaction handler with async support.
Provides a unified interface for all OpenAI API calls used throughout the Verbatim RAG system, including span extraction and template generation.
Source code in packages/core/verbatim_core/llm_client.py
18 19 20 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 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 | |
__init__(model='gpt-4o-mini', temperature=0.7, api_base='https://api.openai.com/v1')
Initialize the LLM client.
:param model: The OpenAI model to use :param temperature: Default temperature for completions :param api_base: The base URL for the OpenAI API (can be used with custom models and with VLLM)
Source code in packages/core/verbatim_core/llm_client.py
complete(prompt, json_mode=False, temperature=None)
Synchronous text completion.
:param prompt: The prompt to send :param json_mode: Whether to request JSON output format :param temperature: Override default temperature :return: The completion text
Source code in packages/core/verbatim_core/llm_client.py
complete_async(prompt, json_mode=False, temperature=None)
async
Asynchronous text completion.
:param prompt: The prompt to send :param json_mode: Whether to request JSON output format :param temperature: Override default temperature :return: The completion text
Source code in packages/core/verbatim_core/llm_client.py
extract_spans(question, documents)
Specialized method for span extraction from documents.
:param question: The user's question :param documents: Dictionary mapping doc IDs to document text :return: Dictionary mapping doc IDs to lists of extracted spans
Source code in packages/core/verbatim_core/llm_client.py
extract_spans_async(question, documents)
async
Async span extraction from documents.
:param question: The user's question :param documents: Dictionary mapping doc IDs to document text :return: Dictionary mapping doc IDs to lists of extracted spans
Source code in packages/core/verbatim_core/llm_client.py
extract_structured(question, template, placeholders, documents)
Extract spans organized by template placeholders with document attribution.
:param question: The user's question :param template: Template with placeholders like [METHODOLOGY] :param placeholders: Dict mapping placeholder names to hints :param documents: List of document texts :return: Dict mapping placeholder names to lists of {text, doc} objects
Source code in packages/core/verbatim_core/llm_client.py
extract_structured_async(question, template, placeholders, documents)
async
Async version of structured extraction with document attribution.
:param question: The user's question :param template: Template with placeholders like [METHODOLOGY] :param placeholders: Dict mapping placeholder names to hints :param documents: List of document texts :return: Dict mapping placeholder names to lists of {text, doc} objects
Source code in packages/core/verbatim_core/llm_client.py
generate_template(question, spans, citation_count, use_per_fact=True)
Generate a contextual template for the given question and spans.
:param question: The user's question :param spans: List of spans that will fill the template :param citation_count: Number of citation-only spans :param use_per_fact: Whether to use per-fact placeholders :return: Generated template string
Source code in packages/core/verbatim_core/llm_client.py
generate_template_async(question, spans, citation_count, use_per_fact=True)
async
Async template generation.
:param question: The user's question :param spans: List of spans that will fill the template :param citation_count: Number of citation-only spans :param use_per_fact: Whether to use per-fact placeholders :return: Generated template string
Source code in packages/core/verbatim_core/llm_client.py
ResponseBuilder
verbatim_core.response_builder.ResponseBuilder
Builds structured query responses with highlights and citations.
Takes search results and extracted spans and creates a complete QueryResponse object with proper document highlighting and citation tracking.
Source code in packages/core/verbatim_core/response_builder.py
20 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 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 | |
__init__()
build_response(question, answer, search_results, relevant_spans, display_span_count=None)
Build a complete QueryResponse from components.
:param question: The original question :param answer: The generated answer text :param search_results: List of search results from the index :param relevant_spans: Dict mapping document text to extracted spans :param display_span_count: Number of spans to display vs cite-only :return: Complete QueryResponse object
Source code in packages/core/verbatim_core/response_builder.py
clean_answer(answer)
Clean up generated answer text.
Removes common formatting issues and artifacts from LLM generation.
:param answer: Raw answer text from generation :return: Cleaned answer text
Source code in packages/core/verbatim_core/response_builder.py
TemplateManager
verbatim_core.templates.manager.TemplateManager
Template manager with strategy pattern and mode selection.
Manages different template strategies and provides a unified interface for template generation and filling. Supports persistence of configuration across sessions.
Source code in packages/core/verbatim_core/templates/manager.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 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 | |
__init__(llm_client=None, default_mode='static', rag_system=None)
Initialize template manager.
:param llm_client: Optional LLM client for contextual and random modes :param default_mode: Default template mode ("static", "contextual", "random", "question_specific", "structured") :param rag_system: Optional RAG system for structured mode
Source code in packages/core/verbatim_core/templates/manager.py
set_mode(mode)
Switch to a different template mode.
:param mode: Template mode to switch to :return: True if mode was switched successfully
Source code in packages/core/verbatim_core/templates/manager.py
get_current_mode()
get_available_modes()
Get list of available template modes.
:return: List of mode names that are available
Source code in packages/core/verbatim_core/templates/manager.py
process(question, display_spans, citation_spans)
Generate and fill a template in one operation.
:param question: The user's question :param display_spans: Spans to display with full text :param citation_spans: Spans for citation reference only :return: Completed response text
Source code in packages/core/verbatim_core/templates/manager.py
process_async(question, display_spans, citation_spans)
async
Async version of process for contextual templates.
:param question: The user's question :param display_spans: Spans to display with full text :param citation_spans: Spans for citation reference only :return: Completed response text
Source code in packages/core/verbatim_core/templates/manager.py
get_template(question='', spans=None, citation_count=0)
Generate a template without filling it.
:param question: The user's question :param spans: List of spans that will fill the template :param citation_count: Number of citation-only spans :return: Template string with placeholders
Source code in packages/core/verbatim_core/templates/manager.py
fill_template(template, display_spans, citation_spans)
Fill a template with content.
:param template: Template string with placeholders :param display_spans: Spans to display with full text :param citation_spans: Spans for citation reference only :return: Filled template
Source code in packages/core/verbatim_core/templates/manager.py
save(filepath)
Save all template configurations to file.
:param filepath: Path to save configuration
Source code in packages/core/verbatim_core/templates/manager.py
load(filepath)
Load template configurations from file.
:param filepath: Path to load configuration from :return: True if loaded successfully
Source code in packages/core/verbatim_core/templates/manager.py
info()
Get current template manager state information.
:return: Dictionary with current state info
Source code in packages/core/verbatim_core/templates/manager.py
use_static_mode(template=None)
Switch to static mode with optional custom template.
:param template: Optional custom template
Source code in packages/core/verbatim_core/templates/manager.py
use_contextual_mode(use_per_fact=True)
Switch to contextual mode with configuration.
:param use_per_fact: Whether to use per-fact placeholders :return: True if switched successfully
Source code in packages/core/verbatim_core/templates/manager.py
use_random_mode(templates=None)
Switch to random mode with optional template pool.
:param templates: Optional list of templates :return: True if switched successfully
Source code in packages/core/verbatim_core/templates/manager.py
generate_random_templates(count=10)
Generate diverse random templates if in random mode.
:param count: Number of templates to generate :return: True if generation was attempted
Source code in packages/core/verbatim_core/templates/manager.py
use_question_specific_mode(templates=None)
Switch to question-specific mode with optional template definitions.
:param templates: Optional dictionary mapping category names to template configs Format: { "category_name": { "template": "Template with [RELEVANT_SENTENCES]", "examples": ["Example question 1", "Example question 2"] } } :return: True if switched successfully
Source code in packages/core/verbatim_core/templates/manager.py
use_structured_mode(template=None, placeholder_mappings=None)
Switch to structured mode with semantic placeholders.
:param template: Template with semantic placeholders like [METHODOLOGY], [RESULTS] :param placeholder_mappings: Custom placeholder → query mappings :return: True if switched successfully
Example
manager.use_structured_mode( template="# Analysis\n## Method\n[METHODOLOGY]\n## Results\n[RESULTS]", placeholder_mappings={"THEIR_METHOD": "what method did the baseline use"} )
Source code in packages/core/verbatim_core/templates/manager.py
set_rag_system(rag_system)
Set the RAG system for modes that need it (structured).
:param rag_system: RAG system instance
Source code in packages/core/verbatim_core/templates/manager.py
process_structured_async(question, template=None, placeholder_mappings=None)
async
Convenience helper to run structured extraction.
Note: Prefer calling rag.query_async() directly after setting up structured mode. This method is kept for convenience.
Source code in packages/core/verbatim_core/templates/manager.py
set_citation_mode(mode)
Configure how citations are rendered inside filled templates.
:param mode: Citation rendering mode ("inline" or "hidden")
Source code in packages/core/verbatim_core/templates/manager.py
Models
verbatim_core.models
Pydantic models for verbatim_core (RAG-agnostic).