Skip to content

Commit b21a189

Browse files
MiyouErikBjare
andauthored
feat: don't print relevance score by default (#11)
* feat: don't print relevance score by default * fix: renamed `--print-relevance` to `--score` --------- Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>
1 parent 6c1900f commit b21a189

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

gptme_rag/cli.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def print_content(self, content: str, doc: Document):
109109
else Syntax(content, lexer, theme="monokai", word_wrap=True)
110110
)
111111

112-
def print_relevance(self, relevance: float):
112+
def print_score(self, relevance: float):
113113
"""Print relevance score."""
114114
self.console.print(f"\n[yellow]Relevance: {relevance:.2f}[/yellow]")
115115

@@ -342,6 +342,11 @@ def index(
342342
help="Context expansion: none (matched chunks), adjacent (with neighboring chunks), file (entire file)",
343343
)
344344
@click.option("--raw", is_flag=True, help="Skip syntax highlighting")
345+
@click.option(
346+
"--score",
347+
is_flag=True,
348+
help="Output relevance scores",
349+
)
345350
@click.option("--explain", is_flag=True, help="Show scoring explanations")
346351
@click.option(
347352
"--weights",
@@ -370,6 +375,7 @@ def search(
370375
n_results: int,
371376
persist_dir: Path,
372377
max_tokens: int,
378+
score: bool,
373379
format: str,
374380
expand: str,
375381
raw: bool,
@@ -406,9 +412,9 @@ def search(
406412
persist_directory=persist_dir,
407413
enable_persist=True,
408414
scoring_weights=scoring_weights,
409-
embedding_function="modernbert"
410-
if embedding_function is None
411-
else embedding_function,
415+
embedding_function=(
416+
"modernbert" if embedding_function is None else embedding_function
417+
),
412418
device=device or "cpu",
413419
)
414420
assembler = ContextAssembler(max_tokens=max_tokens)
@@ -498,8 +504,8 @@ def get_expanded_content(doc: Document, expand: str, indexer: Indexer) -> str:
498504
if format == "full":
499505
for i, doc in enumerate(documents):
500506
# Show relevance info first
501-
if distances:
502-
formatter.print_relevance(1 - distances[i])
507+
if distances and score:
508+
formatter.print_score(1 - distances[i])
503509

504510
# Get and format content
505511
content = get_expanded_content(doc, expand, indexer)
@@ -550,7 +556,8 @@ def get_expanded_content(doc: Document, expand: str, indexer: Indexer) -> str:
550556
console.print(f"\n {'Total':15} [bold blue]{total:>7.3f}[/bold blue]")
551557
else:
552558
# Just show the base relevance score
553-
formatter.print_relevance(1 - distances[i])
559+
if distances and score:
560+
formatter.print_score(1 - distances[i])
554561

555562
# Display preview
556563
formatter.print_preview(doc)
@@ -617,9 +624,9 @@ def watch(
617624
indexer = Indexer(
618625
persist_directory=persist_dir,
619626
enable_persist=True,
620-
embedding_function="modernbert"
621-
if embedding_function is None
622-
else embedding_function,
627+
embedding_function=(
628+
"modernbert" if embedding_function is None else embedding_function
629+
),
623630
device=device or "cpu",
624631
chunk_size=chunk_size, # Now optional in Indexer
625632
chunk_overlap=chunk_overlap, # Now optional in Indexer

0 commit comments

Comments
 (0)