langchain/libs/community/tests/integration_tests/retrievers/test_dria_index.py
ccurme c010ec8b71
patch: deprecate (a)get_relevant_documents (#20477)
- `.get_relevant_documents(query)` -> `.invoke(query)`
- `.get_relevant_documents(query=query)` -> `.invoke(query)`
- `.get_relevant_documents(query, callbacks=callbacks)` ->
`.invoke(query, config={"callbacks": callbacks})`
- `.get_relevant_documents(query, **kwargs)` -> `.invoke(query,
**kwargs)`

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
2024-04-22 11:14:53 -04:00

42 lines
1.2 KiB
Python

import pytest
from langchain_core.documents import Document
from langchain_community.retrievers import DriaRetriever
# Set a fixture for DriaRetriever
@pytest.fixture
def dria_retriever() -> DriaRetriever:
api_key = "<YOUR_API_KEY>"
contract_id = "B16z9i3rRi0KEeibrzzMU33YTB4WDtos1vdiMBTmKgs"
retriever = DriaRetriever(api_key=api_key, contract_id=contract_id)
return retriever
def test_dria_retriever(dria_retriever: DriaRetriever) -> None:
texts = [
{
"text": "Langchain",
"metadata": {
"source": "source#1",
"document_id": "doc123",
"content": "Langchain",
},
}
]
dria_retriever.add_texts(texts)
# Assuming invoke returns a list of Document instances
docs = dria_retriever.invoke("Langchain")
# Perform assertions
assert len(docs) > 0, "Expected at least one document"
doc = docs[0]
assert isinstance(doc, Document), "Expected a Document instance"
assert isinstance(doc.page_content, str), (
"Expected document content type " "to be string"
)
assert isinstance(
doc.metadata, dict
), "Expected document metadata content to be a dictionary"