Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

AlloyDBEmbeddingRetriever

Retrieve documents from an AlloyDBDocumentStore using vector similarity search. Use this component in query pipelines to find semantically similar documents based on dense embeddings.

Embedding Models in Query Pipelines and Indexes

The embedding model you use to embed documents in your indexing pipeline must be the same as the embedding model you use to embed the query in your query pipeline.

This means the embedders for your indexing and query pipelines must match. For example, if you use CohereDocumentEmbedder to embed your documents, you should use CohereTextEmbedder with the same model to embed your queries.

Key Features

  • Performs vector similarity search using embeddings stored in AlloyDB.
  • Supports cosine similarity, inner product, and L2 distance similarity functions.
  • Supports exact nearest neighbor (ENN) and HNSW approximate nearest neighbor (ANN) search strategies defined on the document store.
  • Configurable filter policy to merge or replace filters at query time.

Configuration

Add Workspace-Level Integration

  1. Click your profile icon and choose Settings.
  2. Go to Workspace>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in the current workspace.

Add Organization-Level Integration

  1. Click your profile icon and choose Settings.
  2. Go to Organization>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in all workspaces in the current organization.
  1. First, configure an AlloyDBDocumentStore in your pipeline.
  2. Drag the AlloyDBEmbeddingRetriever component onto the canvas from the Component Library.
  3. Connect an embedder component to provide query_embedding as input.
  4. Connect the retriever output to downstream components such as PromptBuilder.

Connections

AlloyDBEmbeddingRetriever receives a query_embedding (list of floats) from a text embedder such as SentenceTransformersTextEmbedder. It outputs a list of Document objects you can connect to PromptBuilder or other downstream components.

Source Code

To check this component's source code, open embedding_retriever.py in the Haystack Core Integrations repository.

Usage Examples

Basic Configuration

  AlloyDBEmbeddingRetriever:
type: haystack_integrations.components.retrievers.alloydb.embedding_retriever.AlloyDBEmbeddingRetriever
init_parameters:
document_store: AlloyDBDocumentStore
top_k: 5

Using the Component in a Pipeline

# haystack-pipeline
components:
text_embedder:
type: haystack.components.embedders.sentence_transformers_text_embedder.SentenceTransformersTextEmbedder
init_parameters:
model: sentence-transformers/all-MiniLM-L6-v2

document_store:
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: 384

retriever:
type: haystack_integrations.components.retrievers.alloydb.embedding_retriever.AlloyDBEmbeddingRetriever
init_parameters:
document_store: document_store
top_k: 5

connections:
- sender: text_embedder.embedding
receiver: retriever.query_embedding

inputs:
query:
- text_embedder.text

outputs:
documents: retriever.documents

Parameters

Inputs

ParameterTypeDescription
query_embeddingList[float]The query embedding vector to search for similar documents.
filtersOptional[Dict[str, Any]]Filters to apply when retrieving documents.
top_kOptional[int]The maximum number of documents to retrieve. Overrides the init-time value.

Outputs

ParameterTypeDescription
documentsList[Document]A list of the most similar documents from the document store.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
document_storeAlloyDBDocumentStoreThe AlloyDB document store to retrieve documents from.
filtersOptional[Dict[str, Any]]NoneDefault filters to apply when retrieving documents.
top_kint10The maximum number of documents to retrieve.
vector_functionOptional[str]NoneOverride the document store's vector similarity function. One of cosine_similarity, inner_product, or l2_distance.
filter_policyFilterPolicyFilterPolicy.REPLACEHow to handle filters passed at query time. REPLACE replaces init-time filters; MERGE combines them.

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
query_embeddingList[float]The embedding vector to search with.
filtersOptional[Dict[str, Any]]NoneRuntime filters to apply.
top_kOptional[int]NoneMaximum number of documents to retrieve. Overrides the init-time value.
vector_functionOptional[str]NoneOverride the vector similarity function for this query.