Giter VIP home page Giter VIP logo

lantern's Introduction

πŸ’‘ Lantern

build test codecov Run on Replit

Lantern is an open-source PostgreSQL database extension to store vector data, generate embeddings, and handle vector search operations.

It provides a new index type for vector columns called hnsw which speeds up ORDER BY ... LIMIT queries.

Lantern builds and uses usearch, a single-header state-of-the-art HNSW implementation.

πŸ”§ Quick Install

If you don’t have PostgreSQL already, use Lantern with Docker to get started quickly:

docker run -p 5432:5432 -e 'POSTGRES_PASSWORD=postgres' lanterndata/lantern:latest-pg15

To install Lantern from source on top of PostgreSQL:

git clone --recursive https://github.com/lanterndata/lantern.git
cd lantern
mkdir build
cd build
cmake ..
make install

To install Lantern using homebrew:

brew tap lanterndata/lantern
brew install lantern && lantern_install

You can also install Lantern on top of PostgreSQL from our precompiled binaries via a single make install.

Alternatively, you can use Lantern in one click using Replit.

πŸ“– How to use Lantern

Lantern retains the standard PostgreSQL interface, so it is compatible with all of your favorite tools in the PostgreSQL ecosystem.

First, enable Lantern in SQL

CREATE EXTENSION lantern;

Create a table with a vector column and add your data

CREATE TABLE small_world (id integer, vector real[3]);
INSERT INTO small_world (id, vector) VALUES (0, '{0,0,0}'), (1, '{0,0,1}');

Create an hnsw index on the table

CREATE INDEX ON small_world USING hnsw (vector);

Customize hnsw index parameters depending on your vector data, such as the distance function (e.g., dist_l2sq_ops), index construction parameters, and index search parameters.

CREATE INDEX ON small_world USING hnsw (vector dist_l2sq_ops)
WITH (M=2, ef_construction=10, ef=4, dim=3);

Start querying data

SET enable_seqscan = false;
SELECT id, l2sq_dist(vector, ARRAY[0,0,0]) AS dist
FROM small_world ORDER BY vector <-> ARRAY[0,0,0] LIMIT 1;

A note on operators and operator classes

Lantern supports several distance functions in the index. You only need to specify the distance function used for a column at index creation time. Lantern will automatically infer the distance function to use for search so you always use <-> operator in search queries.

Note that the operator <-> is intended exclusively for use with index lookups. If you expect to not use the index in a query, just use the distance function directly (e.g. l2sq_dist(v1, v2))

There are four defined operator classes that can be employed during index creation:

  • dist_l2sq_ops: Default for the type real[]
  • dist_vec_l2sq_ops: Default for the type vector
  • dist_cos_ops: Applicable to the type real[]
  • dist_hamming_ops: Applicable for the type integer[]

Index Construction Parameters

The M, ef, and ef_construction parameters control the performance of the HNSW algorithm for your use case.

  • In general, lower M and ef_construction speed up index creation at the cost of recall.
  • Lower M and ef improve search speed and result in fewer shared buffer hits at the cost of recall. Tuning these parameters will require experimentation for your specific use case.

Miscellaneous

  • If you have previously cloned Lantern and would like to update run git pull && git submodule update

⭐️ Features

  • Embedding generation for popular use cases (CLIP model, Hugging Face models, custom model)
  • Interoperability with pgvector's data type, so anyone using pgvector can switch to Lantern
  • Parallel index creation via an external indexer
  • Ability to generate the index graph outside of the database server
  • Support for creating the index outside of the database and inside another instance allows you to create an index without interrupting database workflows.
  • See all of our helper functions to better enable your workflows

🏎️ Performance

Important takeaways:

  • There's three key metrics we track. CREATE INDEX time, SELECT throughput, and SELECT latency.
  • We match or outperform pgvector and pg_embedding (Neon) on all of these metrics.
  • We plan to continue to make performance improvements to ensure we are the best performing database.

Lantern throughput Lantern latency Lantern index creation

πŸ—ΊοΈ Roadmap

  • Cloud-hosted version of Lantern - Sign up for updates
  • Hardware-accelerated distance metrics, tailored for your CPU, enabling faster queries
  • Templates and guides for building applications for different industries
  • More tools for generating embeddings (support for third party model API’s, more local models)
  • Support for version control and A/B test embeddings
  • Autotuned index type that will choose appropriate creation parameters
  • Support for 1 byte and 2 byte vector elements, and up to 8000 dimensional vectors (PR #19)
  • Request a feature at [email protected]

πŸ“š Resources

  • GitHub issues: report bugs or issues with Lantern
  • Need support? Contact [email protected]. We are happy to troubleshoot issues and advise on how to use Lantern for your use case
  • We welcome community contributions! Feel free to open an issue or a PR. If you contact [email protected], we can find an open issue or project that fits you

lantern's People

Contributors

davkhech avatar dqii avatar ezra-varady avatar grubdragon avatar ngalstyan4 avatar siddharth1729 avatar therealdarkknight avatar var77 avatar yolovoe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.