Skip to content

Commit

Permalink
patch: deprecate (a)get_relevant_documents (#20477)
Browse files Browse the repository at this point in the history
- `.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 <[email protected]>
  • Loading branch information
ccurme and efriis authored Apr 22, 2024
1 parent 939d113 commit c010ec8
Show file tree
Hide file tree
Showing 171 changed files with 443 additions and 535 deletions.
4 changes: 2 additions & 2 deletions cookbook/Multi_modal_RAG.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@
"source": [
"# Check retrieval\n",
"query = \"Give me company names that are interesting investments based on EV / NTM and NTM rev growth. Consider EV / NTM multiples vs historical?\"\n",
"docs = retriever_multi_vector_img.get_relevant_documents(query, limit=6)\n",
"docs = retriever_multi_vector_img.invoke(query, limit=6)\n",
"\n",
"# We get 4 docs\n",
"len(docs)"
Expand All @@ -630,7 +630,7 @@
"source": [
"# Check retrieval\n",
"query = \"What are the EV / NTM and NTM rev growth for MongoDB, Cloudflare, and Datadog?\"\n",
"docs = retriever_multi_vector_img.get_relevant_documents(query, limit=6)\n",
"docs = retriever_multi_vector_img.invoke(query, limit=6)\n",
"\n",
"# We get 4 docs\n",
"len(docs)"
Expand Down
2 changes: 1 addition & 1 deletion cookbook/Multi_modal_RAG_google.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@
],
"source": [
"query = \"What are the EV / NTM and NTM rev growth for MongoDB, Cloudflare, and Datadog?\"\n",
"docs = retriever_multi_vector_img.get_relevant_documents(query, limit=1)\n",
"docs = retriever_multi_vector_img.invoke(query, limit=1)\n",
"\n",
"# We get 2 docs\n",
"len(docs)"
Expand Down
8 changes: 2 additions & 6 deletions cookbook/Semi_structured_and_multi_modal_RAG.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,7 @@
],
"source": [
"# We can retrieve this table\n",
"retriever.get_relevant_documents(\n",
" \"What are results for LLaMA across across domains / subjects?\"\n",
")[1]"
"retriever.invoke(\"What are results for LLaMA across across domains / subjects?\")[1]"
]
},
{
Expand Down Expand Up @@ -614,9 +612,7 @@
}
],
"source": [
"retriever.get_relevant_documents(\"Images / figures with playful and creative examples\")[\n",
" 1\n",
"]"
"retriever.invoke(\"Images / figures with playful and creative examples\")[1]"
]
},
{
Expand Down
4 changes: 1 addition & 3 deletions cookbook/Semi_structured_multi_modal_RAG_LLaMA2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,7 @@
}
],
"source": [
"retriever.get_relevant_documents(\"Images / figures with playful and creative examples\")[\n",
" 0\n",
"]"
"retriever.invoke(\"Images / figures with playful and creative examples\")[0]"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion cookbook/advanced_rag_eval.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@
"# Testing on retrieval\n",
"query = \"What percentage of CPI is dedicated to Housing, and how does it compare to the combined percentage of Medical Care, Apparel, and Other Goods and Services?\"\n",
"suffix_for_images = \" Include any pie charts, graphs, or tables.\"\n",
"docs = retriever_multi_vector_img.get_relevant_documents(query + suffix_for_images)"
"docs = retriever_multi_vector_img.invoke(query + suffix_for_images)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion cookbook/custom_agent_with_plugin_retrieval.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"\n",
"def get_tools(query):\n",
" # Get documents, which contain the Plugins to use\n",
" docs = retriever.get_relevant_documents(query)\n",
" docs = retriever.invoke(query)\n",
" # Get the toolkits, one for each plugin\n",
" tool_kits = [toolkits_dict[d.metadata[\"plugin_name\"]] for d in docs]\n",
" # Get the tools: a separate NLAChain for each endpoint\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
"\n",
"def get_tools(query):\n",
" # Get documents, which contain the Plugins to use\n",
" docs = retriever.get_relevant_documents(query)\n",
" docs = retriever.invoke(query)\n",
" # Get the toolkits, one for each plugin\n",
" tool_kits = [toolkits_dict[d.metadata[\"plugin_name\"]] for d in docs]\n",
" # Get the tools: a separate NLAChain for each endpoint\n",
Expand Down
2 changes: 1 addition & 1 deletion cookbook/custom_agent_with_tool_retrieval.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"\n",
"\n",
"def get_tools(query):\n",
" docs = retriever.get_relevant_documents(query)\n",
" docs = retriever.invoke(query)\n",
" return [ALL_TOOLS[d.metadata[\"index\"]] for d in docs]"
]
},
Expand Down
2 changes: 1 addition & 1 deletion cookbook/langgraph_crag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
" print(\"---RETRIEVE---\")\n",
" state_dict = state[\"keys\"]\n",
" question = state_dict[\"question\"]\n",
" documents = retriever.get_relevant_documents(question)\n",
" documents = retriever.invoke(question)\n",
" return {\"keys\": {\"documents\": documents, \"question\": question}}\n",
"\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion cookbook/langgraph_self_rag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
" print(\"---RETRIEVE---\")\n",
" state_dict = state[\"keys\"]\n",
" question = state_dict[\"question\"]\n",
" documents = retriever.get_relevant_documents(question)\n",
" documents = retriever.invoke(question)\n",
" return {\"keys\": {\"documents\": documents, \"question\": question}}\n",
"\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion cookbook/multi_modal_RAG_chroma.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@
" display(HTML(image_html))\n",
"\n",
"\n",
"docs = retriever.get_relevant_documents(\"Woman with children\", k=10)\n",
"docs = retriever.invoke(\"Woman with children\", k=10)\n",
"for doc in docs:\n",
" if is_base64(doc.page_content):\n",
" plt_img_base64(doc.page_content)\n",
Expand Down
2 changes: 1 addition & 1 deletion cookbook/multi_modal_RAG_vdms.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@
"\n",
"\n",
"query = \"Woman with children\"\n",
"docs = retriever.get_relevant_documents(query, k=10)\n",
"docs = retriever.invoke(query, k=10)\n",
"\n",
"for doc in docs:\n",
" if is_base64(doc.page_content):\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
"\n",
"retriever = vector_store.as_retriever(search_type=\"similarity\", search_kwargs={\"k\": 3})\n",
"\n",
"retrieved_docs = retriever.get_relevant_documents(\"<your question>\")\n",
"retrieved_docs = retriever.invoke(\"<your question>\")\n",
"\n",
"print(retrieved_docs[0].page_content)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion cookbook/self_query_hotel_search.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@
}
],
"source": [
"results = retriever.get_relevant_documents(\n",
"results = retriever.invoke(\n",
" \"I want to stay somewhere highly rated along the coast. I want a room with a patio and a fireplace.\"\n",
")\n",
"for res in results:\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/chat/maritalk.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"\n",
"query = \"Qual o tempo máximo para realização da prova?\"\n",
"\n",
"docs = retriever.get_relevant_documents(query)\n",
"docs = retriever.invoke(query)\n",
"\n",
"chain.invoke(\n",
" {\"input_documents\": docs, \"query\": query}\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/document_loaders/docugami.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@
],
"source": [
"# Query retriever, should return parents (using MMR since that was set as search_type above)\n",
"retrieved_parent_docs = retriever.get_relevant_documents(\n",
"retrieved_parent_docs = retriever.invoke(\n",
" \"what signs does Birch Street allow on their property?\"\n",
")\n",
"for chunk in retrieved_parent_docs:\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/document_loaders/figma.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
" # delete the gpt-4 model_name to use the default gpt-3.5 turbo for faster results\n",
" gpt_4 = ChatOpenAI(temperature=0.02, model_name=\"gpt-4\")\n",
" # Use the retriever's 'get_relevant_documents' method if needed to filter down longer docs\n",
" relevant_nodes = figma_doc_retriever.get_relevant_documents(human_input)\n",
" relevant_nodes = figma_doc_retriever.invoke(human_input)\n",
" conversation = [system_message_prompt, human_message_prompt]\n",
" chat_prompt = ChatPromptTemplate.from_messages(conversation)\n",
" response = gpt_4(\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/document_loaders/spreedly.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
],
"source": [
"# Test the retriever\n",
"spreedly_doc_retriever.get_relevant_documents(\"CRC\")"
"spreedly_doc_retriever.invoke(\"CRC\")"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
")\n",
"\n",
"query = \"What is the plan for the economy?\"\n",
"docs = retriever.get_relevant_documents(query)\n",
"docs = retriever.invoke(query)\n",
"pretty_print_docs(docs)"
]
},
Expand Down Expand Up @@ -162,9 +162,7 @@
" base_compressor=compressor, base_retriever=retriever\n",
")\n",
"\n",
"compressed_docs = compression_retriever.get_relevant_documents(\n",
" \"What is the plan for the economy?\"\n",
")\n",
"compressed_docs = compression_retriever.invoke(\"What is the plan for the economy?\")\n",
"pretty_print_docs(compressed_docs)"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
"retriever = FAISS.from_documents(texts, embedding).as_retriever(search_kwargs={\"k\": 20})\n",
"\n",
"query = \"What did the president say about Ketanji Brown Jackson\"\n",
"docs = retriever.get_relevant_documents(query)\n",
"docs = retriever.invoke(query)\n",
"pretty_print_docs(docs)"
]
},
Expand Down Expand Up @@ -388,7 +388,7 @@
" base_compressor=ov_compressor, base_retriever=retriever\n",
")\n",
"\n",
"compressed_docs = compression_retriever.get_relevant_documents(\n",
"compressed_docs = compression_retriever.invoke(\n",
" \"What did the president say about Ketanji Jackson Brown\"\n",
")\n",
"print([doc.metadata[\"id\"] for doc in compressed_docs])"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
").as_retriever(search_kwargs={\"k\": 20})\n",
"\n",
"query = \"What did the president say about Ketanji Brown Jackson\"\n",
"docs = retriever.get_relevant_documents(query)\n",
"docs = retriever.invoke(query)\n",
"pretty_print_docs(docs)"
]
},
Expand Down Expand Up @@ -382,7 +382,7 @@
" base_compressor=compressor, base_retriever=retriever\n",
")\n",
"\n",
"compressed_docs = compression_retriever.get_relevant_documents(\n",
"compressed_docs = compression_retriever.invoke(\n",
" \"What did the president say about Ketanji Jackson Brown\"\n",
")\n",
"pretty_print_docs(compressed_docs)"
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/platforms/google.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ docai_wh_retriever = GoogleDocumentAIWarehouseRetriever(
project_number=...
)
query = ...
documents = docai_wh_retriever.get_relevant_documents(
documents = docai_wh_retriever.invoke(
query, user_ldap=...
)
```
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/providers/cohere.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ from langchain.retrievers import CohereRagRetriever
from langchain_core.documents import Document

rag = CohereRagRetriever(llm=ChatCohere())
print(rag.get_relevant_documents("What is cohere ai?"))
print(rag.invoke("What is cohere ai?"))
```

Usage of the Cohere [RAG Retriever](/docs/integrations/retrievers/cohere)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/providers/metal.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ from metal_sdk.metal import Metal
metal = Metal("API_KEY", "CLIENT_ID", "INDEX_ID");
retriever = MetalRetriever(metal, params={"limit": 2})

docs = retriever.get_relevant_documents("search term")
docs = retriever.invoke("search term")
```
2 changes: 1 addition & 1 deletion docs/docs/integrations/providers/ragatouille.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
" base_compressor=RAG.as_langchain_document_compressor(), base_retriever=retriever\n",
")\n",
"\n",
"compressed_docs = compression_retriever.get_relevant_documents(\n",
"compressed_docs = compression_retriever.invoke(\n",
" \"What animation studio did Miyazaki found\"\n",
")"
]
Expand Down
4 changes: 1 addition & 3 deletions docs/docs/integrations/providers/vectara/vectara_chat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@
"openai_api_key = os.environ[\"OPENAI_API_KEY\"]\n",
"llm = OpenAI(openai_api_key=openai_api_key, temperature=0)\n",
"retriever = vectara.as_retriever()\n",
"d = retriever.get_relevant_documents(\n",
" \"What did the president say about Ketanji Brown Jackson\", k=2\n",
")\n",
"d = retriever.invoke(\"What did the president say about Ketanji Brown Jackson\", k=2)\n",
"print(d)"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"metadata": {},
"outputs": [],
"source": [
"retriever.get_relevant_documents(\"what is langchain\")"
"retriever.invoke(\"what is langchain\")"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/retrievers/arcee.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"outputs": [],
"source": [
"query = \"Can AI-driven music therapy contribute to the rehabilitation of patients with disorders of consciousness?\"\n",
"documents = retriever.get_relevant_documents(query=query)"
"documents = retriever.invoke(query)"
]
},
{
Expand All @@ -108,7 +108,7 @@
"]\n",
"\n",
"# Retrieve documents with filters and size params\n",
"documents = retriever.get_relevant_documents(query=query, size=5, filters=filters)"
"documents = retriever.invoke(query, size=5, filters=filters)"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/retrievers/arxiv.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"metadata": {},
"outputs": [],
"source": [
"docs = retriever.get_relevant_documents(query=\"1605.08386\")"
"docs = retriever.invoke(\"1605.08386\")"
]
},
{
Expand Down Expand Up @@ -162,7 +162,7 @@
},
"outputs": [
{
"name": "stdin",
"name": "stdout",
"output_type": "stream",
"text": [
" ········\n"
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/retrievers/azure_ai_search.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"metadata": {},
"outputs": [],
"source": [
"retriever.get_relevant_documents(\"what is langchain?\")"
"retriever.invoke(\"what is langchain?\")"
]
},
{
Expand Down Expand Up @@ -263,7 +263,7 @@
}
],
"source": [
"retriever.get_relevant_documents(\"What is Azure OpenAI?\")"
"retriever.invoke(\"What is Azure OpenAI?\")"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/retrievers/bedrock.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"source": [
"query = \"What did the president say about Ketanji Brown?\"\n",
"\n",
"retriever.get_relevant_documents(query=query)"
"retriever.invoke(query)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/retrievers/bm25.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
},
"outputs": [],
"source": [
"result = retriever.get_relevant_documents(\"foo\")"
"result = retriever.invoke(\"foo\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/retrievers/breebs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"source": [
"breeb_key = \"Parivoyage\"\n",
"retriever = BreebsRetriever(breeb_key)\n",
"documents = retriever.get_relevant_documents(\n",
"documents = retriever.invoke(\n",
" \"What are some unique, lesser-known spots to explore in Paris?\"\n",
")\n",
"print(documents)"
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/retrievers/chaindesk.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
}
],
"source": [
"retriever.get_relevant_documents(\"What is Daftpage?\")"
"retriever.invoke(\"What is Daftpage?\")"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/retrievers/chatgpt-plugin.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
}
],
"source": [
"retriever.get_relevant_documents(\"alice's phone number\")"
"retriever.invoke(\"alice's phone number\")"
]
},
{
Expand Down
Loading

0 comments on commit c010ec8

Please sign in to comment.