Skip to content

Commit

Permalink
fix test conflict with langchain-ai#149
Browse files Browse the repository at this point in the history
  • Loading branch information
shamspias committed Dec 15, 2024
1 parent d8e11ef commit a56c921
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 249 deletions.
127 changes: 20 additions & 107 deletions examples/vectorstore.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"!pip install --quiet -U langchain_cohere"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -65,7 +65,6 @@
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from langchain_cohere import CohereEmbeddings\n",
"from langchain_postgres import PGVector\n",
Expand All @@ -83,7 +82,8 @@
" connection=connection,\n",
" use_jsonb=True,\n",
")"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -124,7 +124,6 @@
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"docs = [\n",
" Document(page_content='there are cats in the pond', metadata={\"id\": 1, \"location\": \"pond\", \"topic\": \"animals\"}),\n",
Expand All @@ -138,7 +137,8 @@
" Document(page_content='the library hosts a weekly story time for kids', metadata={\"id\": 9, \"location\": \"library\", \"topic\": \"reading\"}),\n",
" Document(page_content='a cooking class for beginners is offered at the community center', metadata={\"id\": 10, \"location\": \"community center\", \"topic\": \"classes\"})\n",
"]\n"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -147,21 +147,10 @@
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vectorstore.add_documents(docs, ids=[doc.metadata['id'] for doc in docs])"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -170,30 +159,10 @@
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"[Document(page_content='there are cats in the pond', metadata={'id': 1, 'topic': 'animals', 'location': 'pond'}),\n",
" Document(page_content='the book club meets at the library', metadata={'id': 8, 'topic': 'reading', 'location': 'library'}),\n",
" Document(page_content='the library hosts a weekly story time for kids', metadata={'id': 9, 'topic': 'reading', 'location': 'library'}),\n",
" Document(page_content='the new art exhibit is fascinating', metadata={'id': 5, 'topic': 'art', 'location': 'museum'}),\n",
" Document(page_content='ducks are also found in the pond', metadata={'id': 2, 'topic': 'animals', 'location': 'pond'}),\n",
" Document(page_content='the market also sells fresh oranges', metadata={'id': 4, 'topic': 'food', 'location': 'market'}),\n",
" Document(page_content='a cooking class for beginners is offered at the community center', metadata={'id': 10, 'topic': 'classes', 'location': 'community center'}),\n",
" Document(page_content='fresh apples are available at the market', metadata={'id': 3, 'topic': 'food', 'location': 'market'}),\n",
" Document(page_content='a sculpture exhibit is also at the museum', metadata={'id': 6, 'topic': 'art', 'location': 'museum'}),\n",
" Document(page_content='a new coffee shop opened on Main Street', metadata={'id': 7, 'topic': 'food', 'location': 'Main Street'})]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vectorstore.similarity_search('kitty', k=10)"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -210,7 +179,6 @@
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"docs = [\n",
" Document(page_content='there are cats in the pond', metadata={\"id\": 1, \"location\": \"pond\", \"topic\": \"animals\"}),\n",
Expand All @@ -224,7 +192,8 @@
" Document(page_content='the library hosts a weekly story time for kids', metadata={\"id\": 9, \"location\": \"library\", \"topic\": \"reading\"}),\n",
" Document(page_content='a cooking class for beginners is offered at the community center', metadata={\"id\": 10, \"location\": \"community center\", \"topic\": \"classes\"})\n",
"]\n"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -260,26 +229,12 @@
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"[Document(page_content='there are cats in the pond', metadata={'id': 1, 'topic': 'animals', 'location': 'pond'}),\n",
" Document(page_content='the library hosts a weekly story time for kids', metadata={'id': 9, 'topic': 'reading', 'location': 'library'}),\n",
" Document(page_content='the new art exhibit is fascinating', metadata={'id': 5, 'topic': 'art', 'location': 'museum'}),\n",
" Document(page_content='ducks are also found in the pond', metadata={'id': 2, 'topic': 'animals', 'location': 'pond'})]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vectorstore.similarity_search('kitty', k=10, filter={\n",
" 'id': {'$in': [1, 5, 2, 9]}\n",
"})"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -296,25 +251,13 @@
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"[Document(page_content='ducks are also found in the pond', metadata={'id': 2, 'topic': 'animals', 'location': 'pond'}),\n",
" Document(page_content='there are cats in the pond', metadata={'id': 1, 'topic': 'animals', 'location': 'pond'})]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vectorstore.similarity_search('ducks', k=10, filter={\n",
" 'id': {'$in': [1, 5, 2, 9]},\n",
" 'location': {'$in': [\"pond\", \"market\"]}\n",
"})"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -323,19 +266,6 @@
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"[Document(page_content='ducks are also found in the pond', metadata={'id': 2, 'topic': 'animals', 'location': 'pond'}),\n",
" Document(page_content='there are cats in the pond', metadata={'id': 1, 'topic': 'animals', 'location': 'pond'})]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vectorstore.similarity_search('ducks', k=10, filter={\n",
" '$and': [\n",
Expand All @@ -344,7 +274,8 @@
" ]\n",
"}\n",
")"
]
],
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -353,30 +284,12 @@
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"[Document(page_content='the book club meets at the library', metadata={'id': 8, 'topic': 'reading', 'location': 'library'}),\n",
" Document(page_content='the new art exhibit is fascinating', metadata={'id': 5, 'topic': 'art', 'location': 'museum'}),\n",
" Document(page_content='the library hosts a weekly story time for kids', metadata={'id': 9, 'topic': 'reading', 'location': 'library'}),\n",
" Document(page_content='a sculpture exhibit is also at the museum', metadata={'id': 6, 'topic': 'art', 'location': 'museum'}),\n",
" Document(page_content='the market also sells fresh oranges', metadata={'id': 4, 'topic': 'food', 'location': 'market'}),\n",
" Document(page_content='a cooking class for beginners is offered at the community center', metadata={'id': 10, 'topic': 'classes', 'location': 'community center'}),\n",
" Document(page_content='a new coffee shop opened on Main Street', metadata={'id': 7, 'topic': 'food', 'location': 'Main Street'}),\n",
" Document(page_content='fresh apples are available at the market', metadata={'id': 3, 'topic': 'food', 'location': 'market'})]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vectorstore.similarity_search('bird', k=10, filter={\n",
" 'location': { \"$ne\": 'pond'}\n",
"})"
]
],
"outputs": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit a56c921

Please sign in to comment.