Skip to content

Commit

Permalink
Created Answer.get_unique_docs_from_contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza committed Mar 26, 2024
1 parent fdaf51a commit 61dfee0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions paperqa/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from collections.abc import Collection
from typing import Any, Callable
from uuid import UUID, uuid4

Expand Down Expand Up @@ -233,6 +234,15 @@ def add_tokens(self, result: LLMResult):
self.token_counts[result.model][0] += result.prompt_count
self.token_counts[result.model][1] += result.completion_count

def get_unique_docs_from_contexts(
self, score_threshold: int = 0
) -> Collection[Doc]:
"""Parse contexts for docs with scores above the input threshold."""
return {
c.text.doc
for c in filter(lambda x: x.score >= score_threshold, self.contexts)
}


class ChunkMetadata(BaseModel):
"""Metadata for chunking algorithm."""
Expand Down

0 comments on commit 61dfee0

Please sign in to comment.