mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 16:13:25 +00:00
Community[Patch] Remove docs form bm25 repr (#16110)
Resolves: https://github.com/langchain-ai/langsmith-sdk/issues/356
This commit is contained in:
parent
c323742f4f
commit
f3601b0aaf
@ -4,6 +4,7 @@ from typing import Any, Callable, Dict, Iterable, List, Optional
|
||||
|
||||
from langchain_core.callbacks import CallbackManagerForRetrieverRun
|
||||
from langchain_core.documents import Document
|
||||
from langchain_core.pydantic_v1 import Field
|
||||
from langchain_core.retrievers import BaseRetriever
|
||||
|
||||
|
||||
@ -16,7 +17,7 @@ class BM25Retriever(BaseRetriever):
|
||||
|
||||
vectorizer: Any
|
||||
""" BM25 vectorizer."""
|
||||
docs: List[Document]
|
||||
docs: List[Document] = Field(repr=False)
|
||||
""" List of documents."""
|
||||
k: int = 4
|
||||
""" Number of documents to return."""
|
||||
|
@ -32,3 +32,14 @@ def test_from_documents() -> None:
|
||||
bm25_retriever = BM25Retriever.from_documents(documents=input_docs)
|
||||
assert len(bm25_retriever.docs) == 3
|
||||
assert bm25_retriever.vectorizer.doc_len == [4, 5, 4]
|
||||
|
||||
|
||||
@pytest.mark.requires("rank_bm25")
|
||||
def test_repr() -> None:
|
||||
input_docs = [
|
||||
Document(page_content="I have a pen."),
|
||||
Document(page_content="Do you have a pen?"),
|
||||
Document(page_content="I have a bag."),
|
||||
]
|
||||
bm25_retriever = BM25Retriever.from_documents(documents=input_docs)
|
||||
assert "I have a pen" not in repr(bm25_retriever)
|
||||
|
Loading…
Reference in New Issue
Block a user