mirror of
https://github.com/vxcontrol/langchaingo.git
synced 2026-08-24 21:31:28 -04:00
064f09155c
- Raised the `go` directive from 1.24.1 to 1.26.5 to satisfy pgx/v5 and ollama's minimum Go version requirements and to pick up 15 patched standard library CVEs. - Updated `pgx/v5`, `otel`/`otel/sdk`/`otlptracehttp`, `x/net`, and the AWS `eventstream` protocol package to their latest requested versions. - Remediated govulncheck-flagged CVEs in `grpc`, `x/text`, `x/crypto`, `antchfx/xpath`, AWS SDK `bedrock*`/`s3` services, `etcd/server`, and `mongo-driver` v1/v2. - Fixed ollama's `MainGPU` API type change (`int` -> `*int`) in `llms/ollama/options.go` without breaking the public `WithRunnerMainGPU` signature.
PostgreSQL Database Chain Example
This example demonstrates how to use the LangChain Go library to interact with a PostgreSQL database using natural language queries. It showcases the power of combining language models with database operations.
What This Example Does
-
Database Setup:
- Creates two tables:
fooandfoo1. - Populates
foowith 100 rows andfoo1with 200 rows of sample data.
- Creates two tables:
-
LangChain Integration:
- Initializes an OpenAI language model.
- Sets up a SQL database chain using the PostgreSQL database.
-
Natural Language Queries:
- Executes three different queries using natural language:
a. Retrieves rows from the
footable where the ID is less than 23. b. Repeats the first query but specifies the table name explicitly. c. Compares the data volume infooandfoo1tables.
- Executes three different queries using natural language:
a. Retrieves rows from the
Key Features
- Natural Language to SQL: Converts human-readable questions into SQL queries.
- Database Interaction: Executes SQL queries and returns results.
- Flexible Querying: Demonstrates querying with and without specifying table names.
- Data Comparison: Shows the ability to analyze and compare data across tables.
How to Run
- Ensure you have a PostgreSQL database set up and accessible.
- Set the
LANGCHAINGO_POSTGRESQLenvironment variable with your database connection string. - Make sure you have an OpenAI API key set up (the example uses default configuration).
- Run the example using
go run postgresql_database_chain.go.
This example is perfect for developers looking to integrate natural language processing with database operations, enabling more intuitive data querying and analysis.