Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: don't print relevance score by default #11

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions gptme_rag/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def print_content(self, content: str, doc: Document):
else Syntax(content, lexer, theme="monokai", word_wrap=True)
)

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

Expand Down Expand Up @@ -342,6 +342,11 @@ def index(
help="Context expansion: none (matched chunks), adjacent (with neighboring chunks), file (entire file)",
)
@click.option("--raw", is_flag=True, help="Skip syntax highlighting")
@click.option(
"--score",
is_flag=True,
help="Output relevance scores",
)
@click.option("--explain", is_flag=True, help="Show scoring explanations")
@click.option(
"--weights",
Expand Down Expand Up @@ -370,6 +375,7 @@ def search(
n_results: int,
persist_dir: Path,
max_tokens: int,
score: bool,
format: str,
expand: str,
raw: bool,
Expand Down Expand Up @@ -406,9 +412,9 @@ def search(
persist_directory=persist_dir,
enable_persist=True,
scoring_weights=scoring_weights,
embedding_function="modernbert"
if embedding_function is None
else embedding_function,
embedding_function=(
"modernbert" if embedding_function is None else embedding_function
),
device=device or "cpu",
)
assembler = ContextAssembler(max_tokens=max_tokens)
Expand Down Expand Up @@ -498,8 +504,8 @@ def get_expanded_content(doc: Document, expand: str, indexer: Indexer) -> str:
if format == "full":
for i, doc in enumerate(documents):
# Show relevance info first
if distances:
formatter.print_relevance(1 - distances[i])
if distances and score:
formatter.print_score(1 - distances[i])

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

# Display preview
formatter.print_preview(doc)
Expand Down Expand Up @@ -617,9 +624,9 @@ def watch(
indexer = Indexer(
persist_directory=persist_dir,
enable_persist=True,
embedding_function="modernbert"
if embedding_function is None
else embedding_function,
embedding_function=(
"modernbert" if embedding_function is None else embedding_function
),
device=device or "cpu",
chunk_size=chunk_size, # Now optional in Indexer
chunk_overlap=chunk_overlap, # Now optional in Indexer
Expand Down