mirror of
https://github.com/vxcontrol/langchaingo.git
synced 2026-07-21 00:45:22 -04:00
c150dc39fe
- Upgraded `github.com/ollama/ollama` from v0.14.3 to v0.16.3 across multiple modules to ensure compatibility with the latest features and fixes. - Updated `github.com/klauspost/compress` from v1.18.0 to v1.18.3 in various modules to incorporate performance improvements and bug fixes. - Adjusted go.mod and go.sum files in relevant examples to reflect these changes, ensuring all examples are using the latest dependency versions.
Google AlloyDB Vector Store Example
This example demonstrates how to use AlloyDB for Postgres for vector similarity search with LangChain in Go.
What This Example Does
-
Creates a AlloyDB VectorStore:
- Initializes the
alloydb.PostgresEngineobject to establish a connection to the AlloyDB database. - Initializes a new table to store embeddings.
- Initializes a
alloydb.VectorStoreobject using a VertexAI model for embeddings.
- Initializes the
-
Initializes VertexAI Embeddings:
- Creates an embeddings client using the VertexAI API.
-
Adds Sample Documents:
- Inserts several documents (cities) with metadata into the vector store.
- Each document includes the city name, population, and area.
-
Performs Similarity Searches:
- Basic search for documents similar to "Japan".
- Customized search for documents using filters by metadata.
How to Run the Example
-
Set the following environment variables. Your AlloyDB values can be found in the Google Cloud Console:
export PROJECT_ID=<your project Id> export GOOGLE_CLOUD_LOCATION=<your cloud location> export ALLOYDB_USERNAME=<your user> export ALLOYDB_PASSWORD=<your password> export ALLOYDB_REGION=<your region> export ALLOYDB_CLUSTER=<your cluster> export ALLOYDB_INSTANCE=<your instance> export ALLOYDB_DATABASE=<your database> export ALLOYDB_TABLE=<your tablename> -
Run the Go example:
go run google_alloydb_vectorstore_example.go
Key Features
- This example demonstrates how to use
alloydb.PostgresEnginefor connection pooling. - It shows how to integrate with VertexAI embeddings models.
- Run the code to add documents and perform a similarity search with
alloydb.VectorStore. - Demonstrates how to filter through the metadata added by using key value pairs.
This example provides a practical demonstration of using vector databases for semantic search and similarity matching, which can be incredibly useful for various AI and machine learning applications.