crig-postgres
Version, currently main branch1 version
- main branchlatestApr 2, 2026
github.com/dsisnero/crig-postgres
PostgreSQL vector store for Crystal with pgvector support. Provides vector similarity search powered by pgvector extension.
1 stars
1 dependent
License: MIT
Installation
# Add this to your shard.yml
dependencies:
crig-postgres:
github: dsisnero/crig-postgres
branch: mainmain is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
>= 1.19.1- License
- MIT
- Author
- Dominic Sisneros
- Target
crig-postgresfrom src/crig-postgres.cr
Dependencies
Runtime Dependencies
- pg*github: will/crystal-pg, commit: c16d54814405e2b9748d9bddc3d8ce0d41d2190f
Development Dependencies
- ameba*github: crystal-ameba/amebadev
README
crig-postgres
This repository is a Crystal port of the rig-postgres Rust crate.
PostgreSQL vector store for Crystal with pgvector support, providing vector similarity search powered by the pgvector extension.
Upstream Source
- Repository: https://github.com/0xPlaygrounds/rig.git
- Subdirectory: rig-integrations/rig-postgres
- Pinned ref: Same as parent crig project
Installation
-
Add the dependency to your
shard.yml:dependencies: crig-postgres: github: dsisnero/crig-postgres -
Run
shards install
Prerequisites
- PostgreSQL with pgvector extension installed
- Create extension in your database:
CREATE EXTENSION vector;
Usage
require "crig-postgres"
# Connect to PostgreSQL
db = DB.open("postgresql://localhost/mydb")
# Create a mock embedding model (or use a real one from crig)
class MyEmbeddingModel
include CrigPostgres::EmbeddingModel
def max_documents : Int32
100
end
def ndims : Int32
1536
end
def embed_texts(texts : Enumerable(String)) : Array(CrigPostgres::Embedding)
texts.map do |text|
vec = Array.new(ndims) { rand }
CrigPostgres::Embedding.new(text, vec)
end
end
end
model = MyEmbeddingModel.new
# Create vector store
store = CrigPostgres::PostgresVectorStore.new(
embedding_model: model,
db: db,
documents_table: "documents",
distance_function: CrigPostgres::PgVectorDistanceFunction::Cosine
)
# Create table with vector support
store.create_table(dims: 1536)
# Insert documents
documents = [{my_doc, [embedding]}]
store.insert_documents(documents)
# Search for similar documents
req = CrigPostgres::VectorSearchRequest(CrigPostgres::PgSearchFilter).builder
.query("search query")
.samples(5)
.build
results = store.top_n(req, MyDocumentType)
Upstream README Highlights
The original Rust implementation provides:
PostgresVectorStorestruct with generic embedding model support- Multiple distance functions (L2, InnerProduct, Cosine, L1, Hamming, Jaccard)
PgSearchFilterfor composing SQL WHERE clauses- Integration with
pgvectorfor vector similarity search - Support for both full document and ID-only search results
Development
make install # Install dependencies
make format # Format code
make lint # Run linter
make test # Run tests
make clean # Clean build artifacts
Contributing
- Fork it (https://github.com/dsisnero/crig-postgres/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Dominic Sisneros - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
main- Seen
- Apr 2, 2026
- Crystal
>= 1.19.1- Indexed
- yes
Dependents
Repository
github.com/dsisnero/crig-postgres
Metadata
- Created
- Aug 19, 2026
- Updated
- Aug 24, 2026
- Synced
- Aug 24, 2026
- Versions
- 1