Skip to content

Commit f8bb1aa

Browse files
authored
Splitter notebook: extend new strategy class (#242)
* Splitter notebook: extend new strategy class fixes #240 * remove variable
1 parent 4c60c28 commit f8bb1aa

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

notebooks/document-chunking/with-langchain-splitters.ipynb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@
265265
"\n",
266266
"\n",
267267
"def parent_child_splitter(documents, chunk_size: int = 200):\n",
268-
"\n",
269268
" child_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size)\n",
270269
"\n",
271270
" docs = []\n",
@@ -550,22 +549,20 @@
550549
"source": [
551550
"from langchain_elasticsearch import (\n",
552551
" ElasticsearchStore,\n",
553-
" ApproxRetrievalStrategy,\n",
552+
" DenseVectorStrategy,\n",
554553
")\n",
555554
"from typing import List, Union\n",
556555
"from langchain_core.documents import Document\n",
557556
"\n",
558557
"\n",
559-
"class CustomRetrievalStrategy(ApproxRetrievalStrategy):\n",
560-
"\n",
561-
" def query(\n",
558+
"class CustomRetrievalStrategy(DenseVectorStrategy):\n",
559+
" def es_query(\n",
562560
" self,\n",
563561
" query: Union[str, None],\n",
564562
" filter: List[dict],\n",
565563
" **kwargs,\n",
566564
" ):\n",
567-
"\n",
568-
" es_query = {\n",
565+
" return {\n",
569566
" \"knn\": {\n",
570567
" \"inner_hits\": {\"_source\": False, \"fields\": [\"passages.text\"]},\n",
571568
" \"field\": \"passages.vector.predicted_value\",\n",
@@ -581,8 +578,6 @@
581578
" }\n",
582579
" }\n",
583580
"\n",
584-
" return es_query\n",
585-
"\n",
586581
"\n",
587582
"vector_store = ElasticsearchStore(\n",
588583
" index_name=INDEX_NAME,\n",

0 commit comments

Comments
 (0)