Skip to content

Commit

Permalink
Splitter notebook: extend new strategy class (#242)
Browse files Browse the repository at this point in the history
* Splitter notebook: extend new strategy class

fixes #240

* remove variable
  • Loading branch information
maxjakob authored May 17, 2024
1 parent 4c60c28 commit f8bb1aa
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions notebooks/document-chunking/with-langchain-splitters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@
"\n",
"\n",
"def parent_child_splitter(documents, chunk_size: int = 200):\n",
"\n",
" child_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size)\n",
"\n",
" docs = []\n",
Expand Down Expand Up @@ -550,22 +549,20 @@
"source": [
"from langchain_elasticsearch import (\n",
" ElasticsearchStore,\n",
" ApproxRetrievalStrategy,\n",
" DenseVectorStrategy,\n",
")\n",
"from typing import List, Union\n",
"from langchain_core.documents import Document\n",
"\n",
"\n",
"class CustomRetrievalStrategy(ApproxRetrievalStrategy):\n",
"\n",
" def query(\n",
"class CustomRetrievalStrategy(DenseVectorStrategy):\n",
" def es_query(\n",
" self,\n",
" query: Union[str, None],\n",
" filter: List[dict],\n",
" **kwargs,\n",
" ):\n",
"\n",
" es_query = {\n",
" return {\n",
" \"knn\": {\n",
" \"inner_hits\": {\"_source\": False, \"fields\": [\"passages.text\"]},\n",
" \"field\": \"passages.vector.predicted_value\",\n",
Expand All @@ -581,8 +578,6 @@
" }\n",
" }\n",
"\n",
" return es_query\n",
"\n",
"\n",
"vector_store = ElasticsearchStore(\n",
" index_name=INDEX_NAME,\n",
Expand Down

0 comments on commit f8bb1aa

Please sign in to comment.