Skip to content

Commit 004d5d9

Browse files
Merge pull request #4 from anupammaurya6767/feature/add-flat-ip-range-search-reset
Add IndexFlatIP, Range Search, and Reset features
2 parents e8da268 + a46d2e4 commit 004d5d9

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,32 @@ index.dispose();
359359
- **No training required**
360360
- **Use case:** Large-scale production systems, best overall performance
361361

362+
### FLAT_IP (IndexFlatIP) - Inner Product for Cosine Similarity
363+
364+
- **Best for:** Cosine similarity with L2-normalized vectors (e.g., OpenAI embeddings)
365+
- **Speed:** O(n) per query - same as FLAT_L2
366+
- **Accuracy:** 100% recall (exact results)
367+
- **Memory:** Same as FLAT_L2
368+
- **Requires:** Vectors must be L2-normalized before adding
369+
- **Use case:** When you need cosine similarity (with normalized vectors, inner product = cosine similarity)
370+
- **Note:** For cosine similarity, normalize vectors first: `cosine_similarity(a, b) = dot_product(normalize(a), normalize(b))`
371+
372+
**When to use FLAT_IP vs Database Cosine Functions:**
373+
374+
FLAT_IP is optimized for large-scale, high-dimensional vector searches. Database cosine functions (PostgreSQL `pgvector`, MongoDB, etc.) are simpler for SQL integration but may be slower at scale.
375+
376+
**Choose FLAT_IP when:**
377+
- Large datasets (100k+ vectors)
378+
- High-dimensional vectors (512+ dimensions)
379+
- Frequent searches (better performance)
380+
- Need batch operations or complex indexes (IVF/HNSW with IP)
381+
382+
**Choose Database Cosine when:**
383+
- Small datasets (< 10k vectors)
384+
- Need SQL integration
385+
- Data already in database
386+
- Need ACID transactions or complex SQL filtering
387+
362388
## Examples
363389

364390
### Basic Semantic Search

src/cpp/faiss_index.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <faiss/index_factory.h>
99
#include <faiss/index_io.h>
1010
#include <faiss/impl/io.h>
11+
#include <faiss/impl/AuxIndexStructures.h>
1112
#include <fstream>
1213
#include <sstream>
1314
#include <cstdio>

0 commit comments

Comments
 (0)