Skip to content

Commit 825fa1c

Browse files
authored
refactor!: Refactor AlloyDBVectorStore to depend on PGVectorstore (#435)
* refactor!: Refactor AlloyDBVectorStore to depend on PGVectorstore * Linter fix * Fix tests * Fix tests * fix tests * linter fix * fix vectorstore * add all existing tests * fix tests * fix tests * fix tests * fix tests * fix tests * fix tests * fix tests * fix tests * fix dependecies * Add tests for hybrid search * linter fix * fix test * Add better documentation for breaking change * minor fix * update deps * Re-expose hybrid search config * add header * linter fix
1 parent 3b6fc68 commit 825fa1c

15 files changed

+837
-2005
lines changed

docs/vector_store.ipynb

Lines changed: 125 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,45 @@
650650
"all_texts = [\"Apples and oranges\", \"Cars and airplanes\", \"Pineapple\", \"Train\", \"Banana\"]\n",
651651
"metadatas = [{\"len\": len(t)} for t in all_texts]\n",
652652
"ids = [str(uuid.uuid4()) for _ in all_texts]\n",
653-
"await custom_store.aadd_texts(all_texts, metadatas=metadatas, ids=ids)\n",
653+
"await custom_store.aadd_texts(all_texts, metadatas=metadatas, ids=ids)"
654+
]
655+
},
656+
{
657+
"cell_type": "markdown",
658+
"metadata": {},
659+
"source": [
660+
"#### For v0.13.0+\n",
654661
"\n",
662+
"**Important Update:** Support for string filters has been deprecated. Please use dictionaries to add filters."
663+
]
664+
},
665+
{
666+
"cell_type": "code",
667+
"execution_count": null,
668+
"metadata": {},
669+
"outputs": [],
670+
"source": [
671+
"# Use filter on search\n",
672+
"docs = await custom_store.asimilarity_search(query, filter={\"len\": {\"$gte\": 6}})\n",
673+
"\n",
674+
"print(docs)"
675+
]
676+
},
677+
{
678+
"cell_type": "markdown",
679+
"metadata": {},
680+
"source": [
681+
"#### For v0.12.0 and under\n",
682+
"\n",
683+
"You can make use of the string filters to filter on metadata"
684+
]
685+
},
686+
{
687+
"cell_type": "code",
688+
"execution_count": null,
689+
"metadata": {},
690+
"outputs": [],
691+
"source": [
655692
"# Use filter on search\n",
656693
"docs = await custom_store.asimilarity_search(query, filter=\"len >= 6\")\n",
657694
"\n",
@@ -766,6 +803,37 @@
766803
"Since price_usd is one of the metadata_columns, we can use price filter while searching"
767804
]
768805
},
806+
{
807+
"cell_type": "markdown",
808+
"metadata": {},
809+
"source": [
810+
"#### For v0.13.0+\n",
811+
"\n",
812+
"**Important Update:** Support for string filters has been deprecated. Please use dictionaries to add filters."
813+
]
814+
},
815+
{
816+
"cell_type": "code",
817+
"execution_count": null,
818+
"metadata": {},
819+
"outputs": [],
820+
"source": [
821+
"import uuid\n",
822+
"\n",
823+
"docs = await custom_store.asimilarity_search(query, filter={\"price_usd\": {\"$gte\": 100}})\n",
824+
"\n",
825+
"print(docs)"
826+
]
827+
},
828+
{
829+
"cell_type": "markdown",
830+
"metadata": {},
831+
"source": [
832+
"#### For v0.12.0 and under\n",
833+
"\n",
834+
"You can make use of the string filters to filter on metadata"
835+
]
836+
},
769837
{
770838
"cell_type": "code",
771839
"execution_count": null,
@@ -783,8 +851,62 @@
783851
"cell_type": "markdown",
784852
"metadata": {},
785853
"source": [
786-
"### Search for documents with json filter\n",
787-
"Since category is added in json metadata, we can use filter on JSON fields while searching\n"
854+
"### Search for documents with json filter\n"
855+
]
856+
},
857+
{
858+
"cell_type": "markdown",
859+
"metadata": {},
860+
"source": [
861+
"#### For v0.13.0+\n",
862+
"\n",
863+
"**Important Update:** Support for string filters has been deprecated. To filter data on the JSON metadata, you must first create a new column for the specific key you wish to filter on. Use the following SQL command to set this up."
864+
]
865+
},
866+
{
867+
"cell_type": "code",
868+
"execution_count": null,
869+
"metadata": {
870+
"vscode": {
871+
"languageId": "sql"
872+
}
873+
},
874+
"outputs": [],
875+
"source": [
876+
"ALTER TABLE vectorstore_table ADD COLUMN category VARCHAR;\n",
877+
"UPDATE vectorstore_table\n",
878+
"SET\n",
879+
" category = metadata ->> 'category';"
880+
]
881+
},
882+
{
883+
"cell_type": "markdown",
884+
"metadata": {},
885+
"source": [
886+
"Now that you've added the new column, you must update the Vectorstore instance to recognize it. After which the new column is available for filtering operations."
887+
]
888+
},
889+
{
890+
"cell_type": "code",
891+
"execution_count": null,
892+
"metadata": {},
893+
"outputs": [],
894+
"source": [
895+
"import uuid\n",
896+
"\n",
897+
"docs = await custom_store.asimilarity_search(query, filter={\"category\": \"Electronics\"})\n",
898+
"\n",
899+
"print(docs)"
900+
]
901+
},
902+
{
903+
"cell_type": "markdown",
904+
"metadata": {},
905+
"source": [
906+
"\n",
907+
"#### For v0.12.0 and under\n",
908+
"\n",
909+
"Since category is added in json metadata, we can use filter on JSON fields using string filters while searching."
788910
]
789911
},
790912
{

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ authors = [
1111
dependencies = [
1212
"google-cloud-alloydb-connector[asyncpg]>=1.2.0, <2.0.0",
1313
"google-cloud-storage>=2.18.2, <4.0.0",
14-
"langchain-core>=0.2.36, <1.0.0",
1514
"numpy>=1.24.4, <3.0.0; python_version >= '3.11'",
1615
"numpy>=1.24.4, <=2.2.6; python_version == '3.10'",
1716
"numpy>=1.24.4, <=2.0.2; python_version <= '3.9'",
18-
"pgvector>=0.2.5, <0.4.0",
19-
"SQLAlchemy[asyncio]>=2.0.25, <3.0.0",
2017
"langchain-postgres>=0.0.15",
2118
]
2219

requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
google-cloud-alloydb-connector[asyncpg]==1.9.0
22
google-cloud-storage==3.1.1
3-
langchain-core==0.3.67
43
numpy==2.3.1; python_version >= "3.11"
54
numpy==2.2.6; python_version == "3.10"
65
numpy==2.0.2; python_version <= "3.9"
7-
SQLAlchemy[asyncio]==2.0.41
86
langgraph==0.6.0
97
langchain-postgres==0.0.15

0 commit comments

Comments
 (0)