Skip to content

Commit

Permalink
Updated BM25 retriever code (#596)
Browse files Browse the repository at this point in the history
Update the code of `BM25HTMLRetriever` to have the same preprocessing code as `SemanticRetriever` and changed default k
  • Loading branch information
dhuynh95 authored Aug 30, 2024
1 parent 0e77f9b commit ae2f7a5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lavague-core/lavague/core/retrievers.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,29 @@ def retrieve(
class BM25HtmlRetriever(BaseHtmlRetriever):
"""Mainly for benchmarks, do not use it as the performances are not up to par with the other retrievers"""

def __init__(self, top_k=3) -> None:
def __init__(self, top_k=10, xpathed_only=True) -> None:
self.top_k = top_k
self.xpathed_only = xpathed_only

def retrieve(
self, query: QueryBundle, html_chunks: List[str], viewport_only=True
) -> List[str]:
html = clean_html(merge_html_chunks(html_chunks))
cleaned_html = clean_html(html)

splitter = LangchainNodeParser(
lc_splitter=RecursiveCharacterTextSplitter.from_language(
language="html",
)
)
nodes = splitter.get_nodes_from_documents([Document(text=cleaned_html)])
nodes = splitter.get_nodes_from_documents(
[Document(text=merge_html_chunks(html_chunks))]
)

if self.xpathed_only:
nodes = filter_for_xpathed_nodes(nodes)

retriever = BM25Retriever.from_defaults(
nodes=nodes, similarity_top_k=self.top_k
)

nodes = retriever.retrieve(query)
return get_nodes_text(nodes)

Expand Down

0 comments on commit ae2f7a5

Please sign in to comment.