This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support more index types besides ivfflat (#224)
Previously, we only support indexing embeddings using the `ivfflat` access method in [pgvector](https://github.com/pgvector/pgvector). Recently, a new access method `hnsw` has been added to pgvector. `hnsw` is believed to be more performant and accurate than `ivfflat`. To allow for more flexibility, we add a new parameter `method` to allow user to choose which access method to use when creating index. Also, a new parameter `embedding_dimension` is added to support more models, since dimension is required for pgvector to create index. A new test case for embeddings is added in `tests/test_embedding.py`. To support `set allow_system_table_mods = on;`, Postgres is upgraded from 12 to 13 on CI.
- Loading branch information
Showing
15 changed files
with
131 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
server/postgres12-python311.Dockerfile → server/postgres13-python311.Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
server/postgres12-python39.Dockerfile → server/postgres13-python39.Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit -o nounset -o pipefail -o xtrace | ||
|
||
python3 -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu | ||
python3 -m pip install sentence-transformers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
|
||
import greenplumpython as gp | ||
from tests import db | ||
|
||
|
||
@pytest.mark.requires_pgvector | ||
def test_embedding_query_string(db: gp.Database): | ||
content = ["I have a dog.", "I like eating apples."] | ||
t = ( | ||
db.create_dataframe(columns={"id": range(len(content)), "content": content}) | ||
.save_as( | ||
temp=True, | ||
column_names=["id", "content"], | ||
distribution_key={"id"}, | ||
distribution_type="hash", | ||
drop_if_exists=True, | ||
drop_cascade=True, | ||
) | ||
.check_unique(columns={"id"}) | ||
) | ||
t = t.embedding().create_index(column="content", model_name="all-MiniLM-L6-v2") | ||
df = t.embedding().search(column="content", query="apple", top_k=1) | ||
assert len(list(df)) == 1 | ||
for row in df: | ||
assert row["content"] == "I like eating apples." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters