mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
81e5b1ad36
<!-- Thank you for contributing to LangChain! Replace this comment with: - Description: a description of the change, - Issue: the issue # it fixes (if applicable), - Dependencies: any dependencies required for this change, - Tag maintainer: for a quicker response, tag the relevant maintainer (see below), - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out! If you're adding a new integration, please include: 1. a test for the integration, preferably unit tests that do not rely on network access, 2. an example notebook showing its use. Maintainer responsibilities: - General / Misc / if you don't know who to tag: @dev2049 - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev - Models / Prompts: @hwchase17, @dev2049 - Memory: @hwchase17 - Agents / Tools / Toolkits: @vowelparrot - Tracing / Callbacks: @agola11 - Async: @agola11 If no one reviews your PR within a few days, feel free to @-mention the same people again. See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md -->
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from langchain.embeddings import OpenAIEmbeddings
|
|
from langchain.retrievers.merger_retriever import MergerRetriever
|
|
from langchain.vectorstores import Chroma
|
|
|
|
|
|
def test_merger_retriever_get_relevant_docs() -> None:
|
|
"""Test get_relevant_docs."""
|
|
texts_group_a = [
|
|
"This is a document about the Boston Celtics",
|
|
"Fly me to the moon is one of my favourite songs."
|
|
"I simply love going to the movies",
|
|
]
|
|
texts_group_b = [
|
|
"This is a document about the Poenix Suns",
|
|
"The Boston Celtics won the game by 20 points",
|
|
"Real stupidity beats artificial intelligence every time. TP",
|
|
]
|
|
embeddings = OpenAIEmbeddings()
|
|
retriever_a = Chroma.from_texts(texts_group_a, embedding=embeddings).as_retriever(
|
|
search_kwargs={"k": 1}
|
|
)
|
|
retriever_b = Chroma.from_texts(texts_group_b, embedding=embeddings).as_retriever(
|
|
search_kwargs={"k": 1}
|
|
)
|
|
|
|
# The Lord of the Retrievers.
|
|
lotr = MergerRetriever(retrievers=[retriever_a, retriever_b])
|
|
|
|
actual = lotr.get_relevant_documents("Tell me about the Celtics")
|
|
assert len(actual) == 2
|
|
assert texts_group_a[0] in [d.page_content for d in actual]
|
|
assert texts_group_b[1] in [d.page_content for d in actual]
|