https://github.com/pgvector/pgvector-prolog
pgvector examples for Prolog
https://github.com/pgvector/pgvector-prolog
Last synced: 2 months ago
JSON representation
pgvector examples for Prolog
- Host: GitHub
- URL: https://github.com/pgvector/pgvector-prolog
- Owner: pgvector
- License: mit
- Created: 2025-11-23T21:21:20.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2025-11-23T21:55:26.000Z (7 months ago)
- Last Synced: 2026-04-04T04:38:08.627Z (2 months ago)
- Language: Prolog
- Size: 2.93 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-vector-databases - pgvector-prolog - Prolog client and examples for pgvector, enabling logic programs to interact with vector search capabilities in PostgreSQL. ([Read more](/details/pgvector-prolog.md)) `SDK` `pgvector` `vector store` (Sdks & Libraries)
README
# pgvector-prolog
[pgvector](https://github.com/pgvector/pgvector) examples for Prolog
Supports [postgresql-prolog](https://github.com/aarroyoc/postgresql-prolog)
[](https://github.com/pgvector/pgvector-prolog/actions)
## Getting Started
Follow the instructions for your database library:
- [postgresql-prolog](#postgresql-prolog)
## postgresql-prolog
Enable the extension
```prolog
postgresql:query(Connection, "CREATE EXTENSION IF NOT EXISTS vector", ok)
```
Create a table
```prolog
postgresql:query(Connection, "CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))", ok)
```
Insert vectors
```prolog
postgresql:sql(Connection, [insert_into(items, [embedding]), values("[1,2,3]")], data([]))
```
Get the nearest neighbors
```prolog
postgresql:query(Connection, "SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5", Rows)
```
Add an approximate index
```prolog
postgresql:query(Connection, "CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)", ok)
```
Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance
See a [full example](example.pl)
## Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- [Report bugs](https://github.com/pgvector/pgvector-prolog/issues)
- Fix bugs and [submit pull requests](https://github.com/pgvector/pgvector-prolog/pulls)
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development:
```sh
git clone https://github.com/pgvector/pgvector-prolog.git
cd pgvector-prolog
createdb pgvector_prolog_test
scryer-prolog example.pl -g "main,halt."
```