mirror of
https://github.com/vxcontrol/langchaingo.git
synced 2026-08-27 20:10:20 -04:00
1fc129969f
Add a single WithStructuredOutput(StructuredOutputConfig) call option carrying a raw JSON Schema (Draft 2020-12), so one contract yields the same guarantee — a normal-final response is a single JSON value matching the schema — on OpenAI, Anthropic, Bedrock (Converse and legacy), Google AI, Vertex, and Ollama. Each provider maps it to its native mechanism; the result is validated locally against the original schema in the new llms/structuredoutput package. Also fixes a latent Converse gap where the response stop reason was never surfaced on ContentChoice.StopReason.
Google Cloud SQL Vector Store Example
This example demonstrates how to use Cloud SQL for Postgres for vector similarity search with LangChain in Go.
What This Example Does
-
Creates a Cloud SQL VectorStore:
- Initializes the
cloudsql.PostgresEngineobject to establish a connection to the Cloud SQL database. - Initializes a new table to store embeddings.
- Initializes a
cloudsql.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:
export PROJECT_ID=<your project Id> export GOOGLE_CLOUD_LOCATION=<your cloud location> export POSTGRES_USERNAME=<your user> export POSTGRES_PASSWORD=<your password> export POSTGRES_REGION=<your region> export POSTGRES_INSTANCE=<your instance> export POSTGRES_DATABASE=<your database> export POSTGRES_TABLE=<your tablename> -
Run the Go example:
go run google_cloudsql_vectorstore_example.go
Key Features
- This example demonstrates how to use
cloudsql.PostgresEnginefor connection pooling. - It shows how to integrate with VertexAI embeddings models.
- Run the code to add documents and perform a similarity search with
cloudsql.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.