Skip to content

refactor!: Refactor AlloyDBVectorStore to depend on PGVectorstore #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 125 additions & 3 deletions docs/vector_store.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,45 @@
"all_texts = [\"Apples and oranges\", \"Cars and airplanes\", \"Pineapple\", \"Train\", \"Banana\"]\n",
"metadatas = [{\"len\": len(t)} for t in all_texts]\n",
"ids = [str(uuid.uuid4()) for _ in all_texts]\n",
"await custom_store.aadd_texts(all_texts, metadatas=metadatas, ids=ids)\n",
"await custom_store.aadd_texts(all_texts, metadatas=metadatas, ids=ids)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### For v0.13.0+\n",
"\n",
"**Important Update:** Support for string filters has been deprecated. Please use dictionaries to add filters."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Use filter on search\n",
"docs = await custom_store.asimilarity_search(query, filter={\"len\": {\"$gte\": 6}})\n",
"\n",
"print(docs)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### For v0.12.0 and under\n",
"\n",
"You can make use of the string filters to filter on metadata"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Use filter on search\n",
"docs = await custom_store.asimilarity_search(query, filter=\"len >= 6\")\n",
"\n",
Expand Down Expand Up @@ -766,6 +803,37 @@
"Since price_usd is one of the metadata_columns, we can use price filter while searching"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### For v0.13.0+\n",
"\n",
"**Important Update:** Support for string filters has been deprecated. Please use dictionaries to add filters."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import uuid\n",
"\n",
"docs = await custom_store.asimilarity_search(query, filter={\"price_usd\": {\"$gte\": 100}})\n",
"\n",
"print(docs)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### For v0.12.0 and under\n",
"\n",
"You can make use of the string filters to filter on metadata"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -783,8 +851,62 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Search for documents with json filter\n",
"Since category is added in json metadata, we can use filter on JSON fields while searching\n"
"### Search for documents with json filter\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### For v0.13.0+\n",
"\n",
"**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."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "sql"
}
},
"outputs": [],
"source": [
"ALTER TABLE vectorstore_table ADD COLUMN category VARCHAR;\n",
"UPDATE vectorstore_table\n",
"SET\n",
" category = metadata ->> 'category';"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import uuid\n",
"\n",
"docs = await custom_store.asimilarity_search(query, filter={\"category\": \"Electronics\"})\n",
"\n",
"print(docs)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"#### For v0.12.0 and under\n",
"\n",
"Since category is added in json metadata, we can use filter on JSON fields using string filters while searching."
]
},
{
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ authors = [
dependencies = [
"google-cloud-alloydb-connector[asyncpg]>=1.2.0, <2.0.0",
"google-cloud-storage>=2.18.2, <4.0.0",
"langchain-core>=0.2.36, <1.0.0",
"numpy>=1.24.4, <3.0.0; python_version >= '3.11'",
"numpy>=1.24.4, <=2.2.6; python_version == '3.10'",
"numpy>=1.24.4, <=2.0.2; python_version <= '3.9'",
"pgvector>=0.2.5, <0.4.0",
"SQLAlchemy[asyncio]>=2.0.25, <3.0.0",
"langchain-postgres>=0.0.15",
]

Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
google-cloud-alloydb-connector[asyncpg]==1.9.0
google-cloud-storage==3.1.1
langchain-core==0.3.67
numpy==2.3.1; python_version >= "3.11"
numpy==2.2.6; python_version == "3.10"
numpy==2.0.2; python_version <= "3.9"
SQLAlchemy[asyncio]==2.0.41
langgraph==0.6.0
langchain-postgres==0.0.15
Loading