Skip to main content

search through files with fts5, vectors and get reranked results. Fast

Project description

litesearch

This file will become your README and also the index of your documentation.

Developer Guide

If you are new to using nbdev here are some useful pointers to get you started.

Install litesearch in Development mode

# make sure litesearch package is installed in development mode
$ pip install -e .

# make changes under nbs/ directory
# ...

# compile to have changes apply to litesearch
$ nbdev_prepare

Usage

Installation

Install latest from the GitHub repository:

$ pip install git+https://github.com/Karthik777/litesearch.git

or from pypi ,

$ pip install litesearch

Documentation

Documentation can be found hosted on this GitHub repository’s pages. Additionally you can find package manager specific guidelines on conda and pypi respectively.

Let’s setup some deps to make full use of litesearch

from fastcore.all import *
from fastlite import *
import numpy as np
from litesearch import *

Let’s set the db up. This db has usearch loaded. So, you can run cosine distance calculations using simd(means fast, real fast)

db: Database = setup_db(':memory:')
embs = dict(v1=np.ones(512).tobytes(), v2=np.zeros(512).tobytes())
db.q('''select
    distance_cosine_f16(:v1,:v2) as diff,
    distance_cosine_f16(:v1,:v1) as same ''',embs)
[{'diff': 1.0, 'same': 0.0}]

There are way more functions you can run now. Checkout: https://unum-cloud.github.io/USearch/sqlite/index.html

Checkout the examples/01_simple_rag.ipynb for a full-fledged rag example.

Let’s create a store and push some content in.

store = db.mk_store()
store.schema
'CREATE TABLE [content] (\n   [id] INTEGER PRIMARY KEY,\n   [content] TEXT NOT NULL,\n   [embedding] BLOB,\n   [metadata] TEXT,\n   [uploaded_at] FLOAT DEFAULT CURRENT_TIMESTAMP\n)'
txts = ['this is a text', "I'm hungry", "Let's play! shall we?"]
embs = [np.full(512, i) for i in range(3)]
rows = [dict(content=t, embedding=e) for t,e in zip(txts,embs)]
store.insert_all(rows)
<Table content (id, content, embedding, metadata, uploaded_at)>

Cool, let’s search through these contents

litesearch provides a search method which reranks the results from both FTS and vector search using Reciprocal Rank Fusion (RRF)

You can always turn it off.

q,e='playing hungry',np.full(512,1).tobytes()
res = db.search(pre(q), e, columns=['id', 'content'], lim=2)
print(res)
[{'id': 2, 'content': "I'm hungry"}, {'id': 3, 'content': "Let's play! shall we?"}, {'id': 1, 'content': 'this is a text'}]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

litesearch-0.0.4.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

litesearch-0.0.4-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file litesearch-0.0.4.tar.gz.

File metadata

  • Download URL: litesearch-0.0.4.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for litesearch-0.0.4.tar.gz
Algorithm Hash digest
SHA256 ce01eb0267219bba06f9f93db0a75a84bb9f8a250aa4ea5620870e7b08666d83
MD5 85d3f720b2edfcebce27658f9967c9ad
BLAKE2b-256 2ebe1e62761dad66fefcc12de88329be4cdfef5843534698a0c6b1065c78cd50

See more details on using hashes here.

File details

Details for the file litesearch-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: litesearch-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for litesearch-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 947e9d05a1a2bb53ce639b8444e3f9b6b9e5bb12f7a4558334bc79b7a6894ef3
MD5 2bac435dacebfedc1aed95f88342b062
BLAKE2b-256 80c856fe29b7af61ff5012662d7cb8060548d0df97dc0ffaa3b2be26096bdd95

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page