Skip to content

feat: Add the PGVectorStore class #168

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a21a8e2
feat: Add the PGVectorStore class
dishaprakash Mar 19, 2025
926f417
Linter and format fix
dishaprakash Mar 19, 2025
a34ddbe
update poetry lock
dishaprakash Mar 19, 2025
bdd2bf6
minor variable name change
dishaprakash Mar 19, 2025
239b1c3
Fix import test
dishaprakash Mar 19, 2025
544cade
enabled socket in one test file
dishaprakash Mar 19, 2025
03dcac1
enabled socket in all test files
dishaprakash Mar 19, 2025
7b4fa7f
Debug tests being skipped
dishaprakash Mar 19, 2025
1d42314
Debug tests being skipped
dishaprakash Mar 19, 2025
dc9a5b8
Debug tests being skipped
dishaprakash Mar 19, 2025
4c3f93f
Debug tests being failed
dishaprakash Mar 19, 2025
b3a12b7
revert debug lines
dishaprakash Mar 19, 2025
8b30833
Remove IVFIndex
dishaprakash Mar 19, 2025
1496033
Minor change
dishaprakash Mar 19, 2025
cbd0889
Review changes
dishaprakash Apr 1, 2025
b436df3
Refactor vectorstore packaging in import
dishaprakash Apr 1, 2025
eb6954d
Change test table names
dishaprakash Apr 1, 2025
3e52c56
Linter fix
dishaprakash Apr 1, 2025
a24fe73
Minor fix
dishaprakash Apr 1, 2025
c74858e
Fix test
dishaprakash Apr 1, 2025
e52e609
Fix tests
dishaprakash Apr 1, 2025
1f6a70e
Remove chat message history format
dishaprakash Apr 1, 2025
8029731
Fix test
dishaprakash Apr 1, 2025
cf58c2a
Fix indexing tests
dishaprakash Apr 1, 2025
b9526c6
Make escape sql string function private
dishaprakash Apr 1, 2025
1d6563a
Rename namespaces
dishaprakash Apr 2, 2025
c9ad8f3
Enable support for TypedDict along with Column
dishaprakash Apr 2, 2025
a913b5a
Fix import test
dishaprakash Apr 2, 2025
9e539e0
Linter fix
dishaprakash Apr 2, 2025
1daac17
Linter fix
dishaprakash Apr 2, 2025
5062185
Add validation and quotes for indexes
dishaprakash Apr 3, 2025
fe62c35
Merge branch 'pg-vectorstore' into upstream-langchain
averikitsch Apr 4, 2025
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
Prev Previous commit
Next Next commit
Remove IVFIndex
  • Loading branch information
dishaprakash committed Mar 19, 2025
commit 8b30833c8fa8b7614ecf5952ce4b76dfa4cc1c86
30 changes: 0 additions & 30 deletions langchain_postgres/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,33 +116,3 @@ def to_string(self) -> str:
DeprecationWarning,
)
return f"ivfflat.probes = {self.probes}"


@dataclass
class IVFIndex(BaseIndex):
index_type: str = "ivf"
lists: int = 100
quantizer: str = field(
default="sq8", init=False
) # Disable `quantizer` initialization currently only supports the value "sq8"

def index_options(self) -> str:
"""Set index query options for vector store initialization."""
return f"(lists = {self.lists}, quantizer = {self.quantizer})"


@dataclass
class IVFQueryOptions(QueryOptions):
probes: int = 1

def to_parameter(self) -> list[str]:
"""Convert index attributes to list of configurations."""
return [f"ivf.probes = {self.probes}"]

def to_string(self) -> str:
"""Convert index attributes to string."""
warnings.warn(
"to_string is deprecated, use to_parameter instead.",
DeprecationWarning,
)
return f"ivf.probes = {self.probes}"
20 changes: 0 additions & 20 deletions tests/unit_tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
HNSWQueryOptions,
IVFFlatIndex,
IVFFlatQueryOptions,
IVFIndex,
IVFQueryOptions,
)


Expand Down Expand Up @@ -62,21 +60,3 @@ def test_ivfflat_query_options(self) -> None:
assert "to_string is deprecated, use to_parameter instead." in str(
w[-1].message
)

def test_ivf_index(self) -> None:
index = IVFIndex(name="test_index", lists=200)
assert index.index_type == "ivf"
assert index.lists == 200
assert index.quantizer == "sq8" # Check default value
assert index.index_options() == "(lists = 200, quantizer = sq8)"

def test_ivf_query_options(self) -> None:
options = IVFQueryOptions(probes=2)
assert options.to_parameter() == ["ivf.probes = 2"]

with warnings.catch_warnings(record=True) as w:
options.to_string()
assert len(w) == 1
assert "to_string is deprecated, use to_parameter instead." in str(
w[-1].message
)
15 changes: 0 additions & 15 deletions tests/unit_tests/test_pg_vectorstore_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest
import pytest_asyncio
import sqlalchemy
from langchain_core.documents import Document
from langchain_core.embeddings import DeterministicFakeEmbedding
from sqlalchemy import text
Expand All @@ -15,7 +14,6 @@
DistanceStrategy,
HNSWIndex,
IVFFlatIndex,
IVFIndex,
)
from tests.utils import VECTORSTORE_CONNECTION_STRING_ASYNCPG as CONNECTION_STRING

Expand Down Expand Up @@ -178,16 +176,3 @@ async def test_aapply_vector_index_ivfflat(self, vs: PGVectorStore) -> None:
async def test_is_valid_index(self, vs: PGVectorStore) -> None:
is_valid = await vs.ais_valid_index("invalid_index")
assert is_valid == False

async def test_aapply_vector_index_ivf(self, vs: PGVectorStore) -> None:
index = IVFIndex(distance_strategy=DistanceStrategy.EUCLIDEAN)
await vs.aapply_vector_index(index, concurrently=True)
assert await vs.ais_valid_index(DEFAULT_INDEX_NAME_ASYNC)
index = IVFIndex(
name="secondindex",
distance_strategy=DistanceStrategy.INNER_PRODUCT,
)
await vs.aapply_vector_index(index)
assert await vs.ais_valid_index("secondindex")
await vs.adrop_vector_index("secondindex")
await vs.adrop_vector_index()