2023-04-07 05:27:37 +00:00
{
"cells": [
{
"cell_type": "markdown",
"id": "ce0f17b9",
"metadata": {},
"source": [
"# Weaviate Hybrid Search\n",
"\n",
2023-05-17 22:29:22 +00:00
">[Weaviate](https://weaviate.io/developers/weaviate) is an open source vector database.\n",
"\n",
">[Hybrid search](https://weaviate.io/blog/hybrid-search-explained) is a technique that combines multiple search algorithms to improve the accuracy and relevance of search results. It uses the best features of both keyword-based search algorithms with vector search techniques.\n",
"\n",
">The `Hybrid search in Weaviate` uses sparse and dense vectors to represent the meaning and context of search queries and documents.\n",
"\n",
"This notebook shows how to use `Weaviate hybrid search` as a LangChain retriever."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bba863a2-977c-4add-b5f4-bfc33a80eae5",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#!pip install weaviate-client"
2023-04-07 05:27:37 +00:00
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "c10dd962",
"metadata": {},
"outputs": [],
"source": [
"import weaviate\n",
"import os\n",
"\n",
"WEAVIATE_URL = \"...\"\n",
"client = weaviate.Client(\n",
" url=WEAVIATE_URL,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "f47a2bfe",
"metadata": {},
"outputs": [],
"source": [
"from langchain.retrievers.weaviate_hybrid_search import WeaviateHybridSearchRetriever\n",
"from langchain.schema import Document"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f2eff08e",
"metadata": {},
"outputs": [],
"source": [
"retriever = WeaviateHybridSearchRetriever(client, index_name=\"LangChain\", text_key=\"text\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "cd8a7b17",
"metadata": {},
"outputs": [],
"source": [
"docs = [Document(page_content=\"foo\")]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "3c5970db",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['3f79d151-fb84-44cf-85e0-8682bfe145e0']"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"retriever.add_documents(docs)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "bf7dbb98",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[Document(page_content='foo', metadata={})]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"retriever.get_relevant_documents(\"foo\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b2bc87c1",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2023-05-17 22:29:22 +00:00
"version": "3.10.6"
2023-04-07 05:27:37 +00:00
}
},
"nbformat": 4,
"nbformat_minor": 5
}