Skip to content

Commit

Permalink
chore: Migration guide update (#286)
Browse files Browse the repository at this point in the history
* Separate alloydb prep steps

* mention default public ip
  • Loading branch information
twishabansal authored Dec 12, 2024
1 parent 779f18a commit 8ad9622
Showing 1 changed file with 43 additions and 28 deletions.
71 changes: 43 additions & 28 deletions samples/migrations/migrate_vectorstore_to_alloydb.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,38 +240,53 @@ The process of getting data from vector stores varies depending on the specific
> **_NOTE:_** The embeddings service defined here is not used to generate the embeddings, but required by the vectorstore.
> Embeddings are directly copied from the original table.

2. Create AlloyDB table and Vector Store
2. Prepare AlloyDB table
1. Connect to AlloyDB

```python
from langchain_google_alloydb_pg import AlloyDBEngine, AlloyDBVectorStore

# Replace these variable values
engine = await AlloyDBEngine.afrom_instance(
project_id="my-project-id",
instance="my-instance-name",
region="us-central1",
cluster="my-primary",
database="test_db",
user="user",
password="password",
)
```python
from langchain_google_alloydb_pg import AlloyDBEngine

# Replace these variable values
engine = await AlloyDBEngine.afrom_instance(
project_id="my-project-id",
instance="my-instance-name",
region="us-central1",
cluster="my-primary",
database="test_db",
user="user",
password="password",
# The default IP type here is public.
# ip_type=IPTypes.PUBLIC,
)
```

# Create an AlloyDB table. Set the table name.
await engine.ainit_vectorstore_table(
table_name='table_name',
> **_NOTE:_** We are using a public IP connection as mentioned [here](https://github.com/GoogleCloudPlatform/alloydb-python-connector?tab=readme-ov-file#specifying-ip-address-type).

# Fake embeddings use a vector size of 768.
# If you're choosing another vector embeddings service, choose the corresponding vector size
vector_size=768,
)
1. Create a table to copy data into (if it does not exist).

# Create a vector store instance
vector_store = await AlloyDBVectorStore.create(
engine=engine,
embedding_service=embeddings_service,
table_name='table_name',
)
```
```python
# Create an AlloyDB table. Set the table name.
await engine.ainit_vectorstore_table(
table_name='table_name',

# Fake embeddings use a vector size of 768.
# If you're choosing another vector embeddings service, choose the corresponding vector size
vector_size=768,
)
```

1. Initialise a vector store object

```python
from langchain_google_alloydb_pg import AlloyDBVectorStore

# Create a vector store instance
vector_store = await AlloyDBVectorStore.create(
engine=engine,
embedding_service=embeddings_service,
table_name='table_name',
)
```

> **_NOTE:_** This code adds metadata to the "langchain_metadata" column in a JSON format. For more efficient filtering, you can organize this metadata into separate columns. Refer to the [vector store docs](https://github.com/googleapis/langchain-google-alloydb-pg-python/blob/main/docs/vector_store.ipynb) for examples of creating metadata columns.

Expand Down

0 comments on commit 8ad9622

Please sign in to comment.