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

[Bug]: Operator class "vector_cosine_ops" does not exist for access method "hnsw" #17568

Open
kjnez opened this issue Jan 21, 2025 · 1 comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized

Comments

@kjnez
Copy link

kjnez commented Jan 21, 2025

Bug Description

If I set "hnsw_dist_method": "vector_cosine_ops" in hnsw_kwargs when using PGVectorStore.from_params, I got the following warning:

WARNING 2025-01-21 05:22:38,543 base 30247 140612435187392 PG Setup: Error creating HNSW index: (psycopg2.errors.UndefinedObject) operator class "vector_cosine_ops" does not exist for access method "hnsw"

[SQL: CREATE INDEX IF NOT EXISTS data_paul_graham_essay_embedding_idx ON onshape_schema.data_paul_graham_essay USING hnsw (embedding vector_cosine_ops) WITH (m = 16, ef_construction = 64)]
(Background on this error at: https://sqlalche.me/e/20/f405)

Version

0.12.11

Steps to Reproduce

  1. Create an index
  2. Load it using PGVectorStore.from_params() and set hnsw_kwargs as follows
hnsw_kwargs={
                "hnsw_m": 16,
                "hnsw_ef_construction": 64,
                "hnsw_ef_search": 40,
                "hnsw_dist_method": "vector_cosine_ops",
            },
debug=True
  1. Observe the output from the terminal

Relevant Logs/Tracbacks

2025-01-21 05:22:38,541 INFO sqlalchemy.engine.Engine CREATE INDEX IF NOT EXISTS data_paul_graham_essay_embedding_idx ON db_schema.data_paul_graham_essay USING hnsw (embedding vector_cosine_ops) WITH (m = 16, ef_construction = 64)
INFO 2025-01-21 05:22:38,541 base 30247 140612435187392 CREATE INDEX IF NOT EXISTS data_paul_graham_essay_embedding_idx ON db_schema.data_paul_graham_essay USING hnsw (embedding vector_cosine_ops) WITH (m = 16, ef_construction = 64)
2025-01-21 05:22:38,541 INFO sqlalchemy.engine.Engine [generated in 0.00008s] {}
INFO 2025-01-21 05:22:38,541 base 30247 140612435187392 [generated in 0.00008s] {}
2025-01-21 05:22:38,542 INFO sqlalchemy.engine.Engine ROLLBACK
INFO 2025-01-21 05:22:38,542 base 30247 140612435187392 ROLLBACK
WARNING 2025-01-21 05:22:38,543 base 30247 140612435187392 PG Setup: Error creating HNSW index: (psycopg2.errors.UndefinedObject) operator class "vector_cosine_ops" does not exist for access method "hnsw"

[SQL: CREATE INDEX IF NOT EXISTS data_paul_graham_essay_embedding_idx ON db_schema.data_paul_graham_essay USING hnsw (embedding vector_cosine_ops) WITH (m = 16, ef_construction = 64)]
(Background on this error at: https://sqlalche.me/e/20/f405)
@kjnez kjnez added bug Something isn't working triage Issue needs to be triaged/prioritized labels Jan 21, 2025
Copy link

dosubot bot commented Jan 21, 2025

Hey @kjnez! I'm here to assist you with any bugs, questions, or contributions. Let's work together to resolve your issue.

The error you're encountering indicates that the operator class "vector_cosine_ops" does not exist for the HNSW access method in PostgreSQL. This suggests that the specified distance method might not be supported or correctly configured for the HNSW index in your PostgreSQL setup.

Here are a few steps you can take to address this issue:

  1. Verify Supported Operator Classes: Check the PostgreSQL documentation or your database configuration to ensure that "vector_cosine_ops" is a valid operator class for the HNSW access method. It's possible that this operator class is not available in your current PostgreSQL version or configuration.

  2. Check for Typographical Errors: Ensure there are no typographical errors in the operator class name. It should match exactly with what is supported by your PostgreSQL setup.

  3. Alternative Distance Methods: If "vector_cosine_ops" is not supported, consider using an alternative distance method that is compatible with the HNSW access method. You might need to consult the documentation or community resources for a list of supported methods.

  4. Database Extensions: Ensure that any necessary extensions or plugins required for using HNSW with specific operator classes are installed and enabled in your PostgreSQL database.

If none of these steps resolve the issue, you may need to consult further documentation or resources specific to your PostgreSQL version and configuration to identify the correct operator class to use.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized
Projects
None yet
Development

No branches or pull requests

1 participant