AlloyDBDocumentStore
Store and retrieve documents using AlloyDB for PostgreSQL, Google Cloud's fully managed, PostgreSQL-compatible database with built-in vector search capabilities.
Key Features
- Stores documents in AlloyDB with full-text and vector search support.
- Supports exact nearest neighbor (ENN) and HNSW approximate nearest neighbor (ANN) vector search strategies.
- Supports multiple vector similarity functions: cosine similarity, inner product, and L2 distance.
- Supports IAM authentication for secure, keyless access.
- Configurable connection via public, private, or PSC IP types.
Configuration
Add Workspace-Level Integration
- Click your profile icon and choose Settings.
- Go to Workspace>Integrations.
- Find the provider you want to connect and click Connect next to them.
- Enter the API key and any other required details.
- Click Connect. You can use this integration in pipelines and indexes in the current workspace.
Add Organization-Level Integration
- Click your profile icon and choose Settings.
- Go to Organization>Integrations.
- Find the provider you want to connect and click Connect next to them.
- Enter the API key and any other required details.
- Click Connect. You can use this integration in pipelines and indexes in all workspaces in the current organization.
- Set up the AlloyDB instance and create a database.
- Set the
ALLOYDB_INSTANCE_URI,ALLOYDB_USER, andALLOYDB_PASSWORDenvironment variables. For instructions, see Create Secrets. - Configure the
AlloyDBDocumentStorein your pipeline YAML with the appropriate connection parameters and embedding dimension.
Source Code
To check this component's source code, open document_store.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
AlloyDBDocumentStore:
type: haystack_integrations.document_stores.alloydb.document_store.AlloyDBDocumentStore
init_parameters:
instance_uri:
type: env_var
env_vars:
- ALLOYDB_INSTANCE_URI
strict: true
user:
type: env_var
env_vars:
- ALLOYDB_USER
strict: true
password:
type: env_var
env_vars:
- ALLOYDB_PASSWORD
strict: false
db: my_database
embedding_dimension: 768
Using HNSW Index for Approximate Nearest Neighbor Search
AlloyDBDocumentStore:
type: haystack_integrations.document_stores.alloydb.document_store.AlloyDBDocumentStore
init_parameters:
instance_uri:
type: env_var
env_vars:
- ALLOYDB_INSTANCE_URI
strict: true
user:
type: env_var
env_vars:
- ALLOYDB_USER
strict: true
password:
type: env_var
env_vars:
- ALLOYDB_PASSWORD
strict: false
db: my_database
embedding_dimension: 768
search_strategy: hnsw
vector_function: cosine_similarity
Parameters
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
instance_uri | Secret | Secret.from_env_var("ALLOYDB_INSTANCE_URI") | The AlloyDB instance URI. |
user | Secret | Secret.from_env_var("ALLOYDB_USER") | The database user. |
password | Secret | Secret.from_env_var("ALLOYDB_PASSWORD", strict=False) | The database password. Not required when using IAM authentication. |
db | str | postgres | The name of the database to connect to. |
enable_iam_auth | bool | False | Whether to use IAM authentication. |
ip_type | str | PRIVATE | The IP type for the connection. One of PRIVATE, PUBLIC, or PSC. |
create_extension | bool | True | Whether to create the vector extension if it doesn't exist. |
schema_name | str | public | The schema name where the document table is stored. |
table_name | str | haystack_documents | The name of the table to store documents in. |
language | str | english | The language used for full-text search indexing. |
embedding_dimension | int | 768 | The dimensionality of document embeddings. Must match your embedding model's output. |
vector_function | str | cosine_similarity | The vector similarity function. One of cosine_similarity, inner_product, or l2_distance. |
recreate_table | bool | False | Whether to drop and recreate the document table on initialization. |
search_strategy | str | exact_nearest_neighbor | The vector search strategy. One of exact_nearest_neighbor or hnsw. |
hnsw_recreate_index_if_exists | bool | False | Whether to recreate the HNSW index if it already exists. |
hnsw_index_creation_kwargs | Optional[Dict[str, int]] | None | Additional keyword arguments for HNSW index creation (for example, m and ef_construction). |
hnsw_index_name | str | haystack_hnsw_index | The name of the HNSW index. |
hnsw_ef_search | Optional[int] | None | The ef_search parameter for HNSW queries. Higher values improve recall at the cost of speed. |
keyword_index_name | str | haystack_keyword_index | The name of the full-text search index. |
Related Information
Was this page helpful?