python-3.xpostgresqlhaystack

How do you name the PostgreSQL indexes when using Haystack's PgvectorDocumentStore?


I would like to give custom names for the two indexes created by PgvectorDocumentStore when creating a table in my PostgreSQL database. The default names are haystack_hnsw_index and haystack_keyword_index.

According to this page:

https://docs.haystack.deepset.ai/reference/integrations-pgvector

I should be able to set it via parameters:

def __init__(*,
         connection_string: Secret = Secret.from_env_var("PG_CONN_STR"),
         table_name: str = "haystack_documents",
         language: str = "english",
         embedding_dimension: int = 768,
         vector_function: Literal["cosine_similarity", "inner_product",
                                  "l2_distance"] = "cosine_similarity",
         recreate_table: bool = False,
         search_strategy: Literal["exact_nearest_neighbor",
                                  "hnsw"] = "exact_nearest_neighbor",
         hnsw_recreate_index_if_exists: bool = False,
         hnsw_index_creation_kwargs: Optional[Dict[str, int]] = None,
         hnsw_index_name: str = "haystack_hnsw_index",
         hnsw_ef_search: Optional[int] = None,
         keyword_index_name: str = "haystack_keyword_index")

But as far as I can see these parameters do not exist. So how do you give your own names to these indexes.

I need to be able to do this or else you get an error if you ever create a new PgvectorDocumentStore with a different table name you end up with an error when it tries to create a duplicate index for that table (since the name is hard coded to always be the same.)

It's a bit hard to believe Deepset made this mistake, so I assume there must be some way to do this. But I can't seem to find it anywhere on the internet.


Solution

  • Starting from pgvector-haystack>=0.4.0, these two parameters are available:

    If you don't see them, try updating the package: pip install -U pgvector-haystack