Skip to main content

setix

At its core setix provides a “set intersection index”, an inverted index data structure designed for storing sets of symbols and fast querying of sets intersecting the given set, with sorting based on the number of intersections or a similarity measure.

Additionally, a wrapper for indexing strings is provided in setix.trgm, which implements a trigram index compatible with the PostgreSQL extension pg_trgm.

Examples

Using a set index:

import setix

ix = setix.SetIntersectionIndex ()
ix.add ((1, 2, 3))
ix.add ((1, 2, 4))
ix.add ((2, 3, 4))

ix.find ((1, 2), 1).get_list()
# returns [(2, [(1, 2, 3)]),
#          (2, [(1, 2, 4)]),
#          (1, [(2, 3, 4)])]
# (the order of the first two results can change as they have equal scores)

Using a trigram index:

import setix.trgm

ix = setix.trgm.TrigramIndex ()
ix.add ("strength")
ix.add ("strenght")
ix.add ("strength and honor")

ix.find ("stremgth", threshold=1).get_list()
# returns [(6, ["strength and honor"])
#          (6, ["strength"]),
#          (4, ["strenght"])]

ix.find_similar ("stremgth", threshold=0.1).get_list()
# returns [(0.5,  ["strength"]),           # 6 intersections / (9 total + 9 total - 6)
#          (0.29, ["strenght"]),           # 4 intersections / (9 total + 9 total - 4)
#          (0.27, ["strength and honor"])] # 6 intersections / (9 total + 19 total - 6)

In general, to search for phrases containing a misspelt word, a threshold of -3*N can be given where N is the number of misspellings.

ix.find ("stremgth", threshold=-3).get_list()
# returns [(6, ["strength and honor"]),
#          (6, ["strength"])]

Benchmarks

A benchmark is included in tests/dvd_db_test.py

Results from an Athlon II running at 2.6GHz:

Python 2.7

In [1]: import tests.dvd_db_test
Loading database...
Extracted 240577 titles
Memory used by data: 107.8MB
Building index...
CPU time used: 43.1s
Unique trigrams indexed: 11352
Unique phrases indexed: 228620
Memory used by index: 80.9MB

In [2]: %timeit list (tests.dvd_db_test.titles.find("daft punk", 8))
10 loops, best of 3: 27.8 ms per loop

In [3]: %timeit list (tests.dvd_db_test.titles.find("daft punk", 1))
10 loops, best of 3: 86.4 ms per loop

Python 3.2

In [1]: import tests.dvd_db_test
Loading database...
Extracted 240577 titles
Memory used by data: 108.8MB
Building index...
CPU time used: 45.8s
Unique trigrams indexed: 11352
Unique phrases indexed: 228620
Memory used by index: 86.2MB

In [2]: %timeit list (tests.dvd_db_test.titles.find("daft punk", 8))
10 loops, best of 3: 27.9 ms per loop

In [3]: %timeit list (tests.dvd_db_test.titles.find("daft punk", 1))
10 loops, best of 3: 86.3 ms per loop

DVD title list used in the benchmark was obtained from http://www.hometheaterinfo.com/dvdlist.htm Thanks for making it available.

Release files for setix 0.8.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for setix 0.8.3
File Size Uploaded
setix-0.8.3.tar.gz 8.3 kB Details

Release files / setix-0.8.3.tar.gz

Download URL setix-0.8.3.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
022d2f82002c4cf84c31131c6f597c46bb52e845ca73667e0681a193df7f796c
BLAKE2b-256 checksum
How to use checksums
8121f0628d54be13cba7353c5452b9434fca501d61f3d5ac9bc40e2f671b5ad1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.8.3 This release

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page