Skip to content

Commit 7917d62

Browse files
refactor!: Refactor PostgresVectorStore and PostgresEngine to depend on PGVectorstore and PGEngine respectively (#316)
* refactor: Refactor PostgresEngine to depend on PGEngine * update deps * update deps * Linter fix * fix tests * linter fix * refactor!: Refactor PostgresVectorStore to depend on PGVectorstore (#319) * refactor!: Refactor PostgresVectorStore to depend on PGVectorstore * Liter fix * fix tests * re-expose hybrid search config * header fix * fix tests * fix tests * fix tests * fix tests * fix tests * expose hybrid search config through init --------- Co-authored-by: Averi Kitsch <akitsch@google.com>
1 parent 40278de commit 7917d62

18 files changed

+767
-2273
lines changed

docs/vector_store.ipynb

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,49 @@
585585
"all_texts = [\"Apples and oranges\", \"Cars and airplanes\", \"Pineapple\", \"Train\", \"Banana\"]\n",
586586
"metadatas = [{\"len\": len(t)} for t in all_texts]\n",
587587
"ids = [str(uuid.uuid4()) for _ in all_texts]\n",
588-
"await custom_store.aadd_texts(all_texts, metadatas=metadatas, ids=ids)\n",
588+
"await custom_store.aadd_texts(all_texts, metadatas=metadatas, ids=ids)"
589+
]
590+
},
591+
{
592+
"cell_type": "markdown",
593+
"metadata": {},
594+
"source": [
595+
"#### For v0.15.0+\n",
596+
"\n",
597+
"**Important Update:** Support for string filters has been deprecated. Please use dictionaries to add filters."
598+
]
599+
},
600+
{
601+
"cell_type": "code",
602+
"execution_count": null,
603+
"metadata": {},
604+
"outputs": [],
605+
"source": [
606+
"# Use filter on search\n",
607+
"docs = await custom_store.asimilarity_search_by_vector(\n",
608+
" query_vector, filter={\"len\": {\"$gte\": 6}}\n",
609+
")\n",
589610
"\n",
611+
"print(docs)"
612+
]
613+
},
614+
{
615+
"cell_type": "markdown",
616+
"metadata": {},
617+
"source": [
618+
"#### For v0.14 and under\n",
619+
"\n",
620+
"You can make use of the string filters to filter on metadata"
621+
]
622+
},
623+
{
624+
"cell_type": "code",
625+
"execution_count": null,
626+
"metadata": {},
627+
"outputs": [],
628+
"source": [
590629
"# Use filter on search\n",
591-
"docs = await custom_store.asimilarity_search_by_vector(query_vector, filter=\"len >= 6\")\n",
630+
"docs = await custom_store.asimilarity_search(query, filter=\"len >= 6\")\n",
592631
"\n",
593632
"print(docs)"
594633
]

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ authors = [
1111

1212
dependencies = [
1313
"cloud-sql-python-connector[asyncpg] >= 1.10.0, <2.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, <1.0.0",
19-
"SQLAlchemy[asyncio]>=2.0.25, <3.0.0"
17+
"langchain-postgres>=0.0.15",
2018
]
2119

2220
classifiers = [

requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
cloud-sql-python-connector[asyncpg]==1.18.2
2-
langchain-core==0.3.68
32
numpy==2.3.1; python_version >= "3.11"
43
numpy==2.2.6; python_version == "3.10"
54
numpy==2.0.2; python_version <= "3.9"
6-
pgvector==0.4.1
7-
SQLAlchemy[asyncio]==2.0.41
85
langgraph==0.6.0
6+
langchain-postgres==0.0.15

src/langchain_google_cloud_sql_pg/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from langchain_postgres import Column
16+
from langchain_postgres.v2.hybrid_search_config import (
17+
HybridSearchConfig,
18+
reciprocal_rank_fusion,
19+
weighted_sum_ranking,
20+
)
21+
1522
from . import indexes
1623
from .chat_message_history import PostgresChatMessageHistory
1724
from .checkpoint import PostgresSaver
18-
from .engine import Column, PostgresEngine
25+
from .engine import PostgresEngine
1926
from .loader import PostgresDocumentSaver, PostgresLoader
2027
from .vectorstore import PostgresVectorStore
2128
from .version import __version__
@@ -29,5 +36,8 @@
2936
"PostgresLoader",
3037
"PostgresDocumentSaver",
3138
"PostgresSaver",
39+
"HybridSearchConfig",
40+
"reciprocal_rank_fusion",
41+
"weighted_sum_ranking",
3242
"__version__",
3343
]

0 commit comments

Comments
 (0)