pgvector-vectorstore-example

command module
v0.0.0-...-3308821 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

PGVector Store with OpenAI Embeddings Example

This example demonstrates how to use pgvector, a PostgreSQL extension for vector similarity search, with OpenAI embeddings in a Go application. It showcases the integration of langchain-go, OpenAI's API, and pgvector to create a powerful vector database for similarity searches.

What This Example Does

  1. Sets up a PostgreSQL Database with pgvector:

    • Uses Docker to run a PostgreSQL instance with the pgvector extension installed.
    • Automatically creates and enables the vector extension when the container starts.
  2. Initializes OpenAI Embeddings:

    • Creates an embeddings client using the OpenAI API.
    • Requires an OpenAI API key to be set as an environment variable.
  3. Creates a PGVector Store:

    • Establishes a connection to the PostgreSQL database.
    • Initializes a vector store using pgvector and OpenAI embeddings.
  4. Adds Sample Documents:

    • Inserts several documents (cities) with metadata into the vector store.
    • Each document includes the city name, population, and area.
  5. Performs Similarity Searches:

    • Demonstrates various types of similarity searches: a. Basic search for documents similar to "japan". b. Search for South American cities with a score threshold. c. Search with both score threshold and metadata filtering.

How to Run the Example

  1. Start the PostgreSQL database:

    docker compose up -d
    
  2. Set your OpenAI API key:

    export OPENAI_API_KEY=<your key>
    
  3. Run the Go example:

    go run pgvector_vectorstore_example.go
    

Key Features

  • Integration of pgvector with OpenAI embeddings
  • Similarity search with score thresholds
  • Metadata filtering in vector searches
  • Dockerized PostgreSQL setup for easy deployment

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.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL