Skip to content
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

pgvector - hnsw index table drop is not using schema name #1275

Open
mabartcz opened this issue Jan 3, 2025 · 2 comments · May be fixed by #1277
Open

pgvector - hnsw index table drop is not using schema name #1275

mabartcz opened this issue Jan 3, 2025 · 2 comments · May be fixed by #1277
Labels
bug Something isn't working contributions wanted! Looking for external contributions integration:pgvector

Comments

@mabartcz
Copy link

mabartcz commented Jan 3, 2025

Describe the bug
If using pgvector, hnsw and multiple schema names (not the default one) the "hnsw index drop" does not drop the table, even if
hnsw_recreate_index_if_exists=True.

It seems to me that there is missing schema_name before table_name in drop index SQL query in:
pgvector/document_store.py (row 392)

Current code:
sql_drop_index = SQL("DROP INDEX IF EXISTS {index_name}").format(index_name=Identifier(self.hnsw_index_name))

Should be:
sql_drop_index = SQL("DROP INDEX IF EXISTS {schema_name}.{index_name}").format(schema_name=Identifier(self.schema_name),index_name=Identifier(self.hnsw_index_name))

To Reproduce

  1. Create PostgreSQL with pgvector using docker (pgvector/pgvector:pg17)
  2. Try to write documents 2 times with same table name (hnsw index should be dropped but it is not.
    Minimal example code: https://gist.github.com/mabartcz/4faa3e1ae7a56c8a9536b1ab8e7d4572
  3. Get error: "psycopg.errors.DuplicateTable: relation "test_table_index" already exists"

Describe your environment (please complete the following information):

  • OS: Windows 11
  • pgvector-haystack: 1.2.0
  • haystack-ai: 2.8.0

If I am not missing something, I can create PR to fix the issue :)

@mabartcz mabartcz added the bug Something isn't working label Jan 3, 2025
@anakin87
Copy link
Member

anakin87 commented Jan 3, 2025

Hello and thank you for reporting the issue.

I think you are right.

Would you like to open a PR to fix this bug (and add a small test)?
(Contributing guidelines)

@anakin87 anakin87 added the contributions wanted! Looking for external contributions label Jan 3, 2025
@mabartcz
Copy link
Author

mabartcz commented Jan 3, 2025

Yes, I will open PR with fix and test.

@mabartcz mabartcz linked a pull request Jan 6, 2025 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working contributions wanted! Looking for external contributions integration:pgvector
Projects
Development

Successfully merging a pull request may close this issue.

2 participants