Skip to content

Commit 30abfc4

Browse files
authored
add instructions for saving loading (#642)
1 parent 95720ad commit 30abfc4

File tree

1 file changed

+75
-3
lines changed

1 file changed

+75
-3
lines changed

docs/modules/utils/combine_docs_examples/vectorstores.ipynb

+75-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
{
1818
"cell_type": "code",
19-
"execution_count": 1,
19+
"execution_count": 6,
2020
"id": "965eecee",
2121
"metadata": {
2222
"pycharm": {
@@ -32,7 +32,7 @@
3232
},
3333
{
3434
"cell_type": "code",
35-
"execution_count": 2,
35+
"execution_count": 7,
3636
"id": "68481687",
3737
"metadata": {
3838
"pycharm": {
@@ -51,7 +51,7 @@
5151
},
5252
{
5353
"cell_type": "code",
54-
"execution_count": 3,
54+
"execution_count": 8,
5555
"id": "015f4ff5",
5656
"metadata": {
5757
"pycharm": {
@@ -199,6 +199,78 @@
199199
"docs_and_scores[0]"
200200
]
201201
},
202+
{
203+
"cell_type": "markdown",
204+
"id": "b386dbb8",
205+
"metadata": {},
206+
"source": [
207+
"### Saving and loading\n",
208+
"You can also save and load a FAISS index. This is useful so you don't have to recreate it everytime you use it."
209+
]
210+
},
211+
{
212+
"cell_type": "code",
213+
"execution_count": 12,
214+
"id": "b58b3955",
215+
"metadata": {},
216+
"outputs": [],
217+
"source": [
218+
"import pickle"
219+
]
220+
},
221+
{
222+
"cell_type": "code",
223+
"execution_count": 14,
224+
"id": "1897e23d",
225+
"metadata": {},
226+
"outputs": [],
227+
"source": [
228+
"with open(\"foo.pkl\", 'wb') as f:\n",
229+
" pickle.dump(docsearch, f)"
230+
]
231+
},
232+
{
233+
"cell_type": "code",
234+
"execution_count": 15,
235+
"id": "bf3732f1",
236+
"metadata": {},
237+
"outputs": [],
238+
"source": [
239+
"with open(\"foo.pkl\", 'rb') as f:\n",
240+
" new_docsearch = pickle.load(f)"
241+
]
242+
},
243+
{
244+
"cell_type": "code",
245+
"execution_count": 16,
246+
"id": "5bf2ee24",
247+
"metadata": {},
248+
"outputs": [],
249+
"source": [
250+
"docs = new_docsearch.similarity_search(query)"
251+
]
252+
},
253+
{
254+
"cell_type": "code",
255+
"execution_count": 18,
256+
"id": "edc2aad1",
257+
"metadata": {},
258+
"outputs": [
259+
{
260+
"data": {
261+
"text/plain": [
262+
"Document(page_content='In state after state, new laws have been passed, not only to suppress the vote, but to subvert entire elections. \\n\\nWe cannot let this happen. \\n\\nTonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', lookup_str='', metadata={}, lookup_index=0)"
263+
]
264+
},
265+
"execution_count": 18,
266+
"metadata": {},
267+
"output_type": "execute_result"
268+
}
269+
],
270+
"source": [
271+
"docs[0]"
272+
]
273+
},
202274
{
203275
"cell_type": "markdown",
204276
"id": "eea6e627",

0 commit comments

Comments
 (0)