Skip to content

feat: support for DiskANN index #227

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
35 changes: 34 additions & 1 deletion langchain_postgres/v2/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import warnings
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from typing import Optional
from typing import Optional, Literal


@dataclass
Expand Down Expand Up @@ -153,3 +153,36 @@ def to_string(self) -> str:
DeprecationWarning,
)
return f"ivfflat.probes = {self.probes}"


@dataclass
class DiskANNIndex(BaseIndex):
index_type: str = "diskann"
extension_name: str | None = "pg_diskann"
max_neighbors: int = 32
l_value_ib: int = 100

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


@dataclass
class DiskANNQueryOptions(QueryOptions):
iterative_search: Literal["relaxed_order", "strict_order", "off"] = "relaxed_order"
l_value_is: int = 100

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

def to_string(self) -> str:
"""Convert index attributes to string."""
warnings.warn(
"to_string is deprecated, use to_parameter instead.",
DeprecationWarning,
)
return ", ".join(self.to_parameter())