@pleaseai/context-please-core 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +39 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/context.d.ts +25 -0
  4. package/dist/context.d.ts.map +1 -1
  5. package/dist/context.js +74 -0
  6. package/dist/context.js.map +1 -1
  7. package/dist/embedding/base-embedding.d.ts.map +1 -1
  8. package/dist/embedding/base-embedding.js +4 -0
  9. package/dist/embedding/base-embedding.js.map +1 -1
  10. package/dist/embedding/gemini-embedding.d.ts +41 -0
  11. package/dist/embedding/gemini-embedding.d.ts.map +1 -1
  12. package/dist/embedding/gemini-embedding.js +154 -25
  13. package/dist/embedding/gemini-embedding.js.map +1 -1
  14. package/dist/embedding/huggingface-embedding.d.ts +70 -0
  15. package/dist/embedding/huggingface-embedding.d.ts.map +1 -0
  16. package/dist/embedding/huggingface-embedding.js +270 -0
  17. package/dist/embedding/huggingface-embedding.js.map +1 -0
  18. package/dist/embedding/index.d.ts +1 -0
  19. package/dist/embedding/index.d.ts.map +1 -1
  20. package/dist/embedding/index.js +1 -0
  21. package/dist/embedding/index.js.map +1 -1
  22. package/dist/splitter/ast-splitter.d.ts.map +1 -1
  23. package/dist/splitter/ast-splitter.js.map +1 -1
  24. package/dist/vectordb/factory.d.ts +20 -1
  25. package/dist/vectordb/factory.d.ts.map +1 -1
  26. package/dist/vectordb/factory.js +67 -1
  27. package/dist/vectordb/factory.js.map +1 -1
  28. package/dist/vectordb/faiss-vectordb.d.ts +162 -0
  29. package/dist/vectordb/faiss-vectordb.d.ts.map +1 -0
  30. package/dist/vectordb/faiss-vectordb.js +762 -0
  31. package/dist/vectordb/faiss-vectordb.js.map +1 -0
  32. package/dist/vectordb/index.d.ts +1 -0
  33. package/dist/vectordb/index.d.ts.map +1 -1
  34. package/dist/vectordb/index.js +20 -1
  35. package/dist/vectordb/index.js.map +1 -1
  36. package/dist/vectordb/sparse/simple-bm25.d.ts +1 -0
  37. package/dist/vectordb/sparse/simple-bm25.d.ts.map +1 -1
  38. package/dist/vectordb/sparse/simple-bm25.js +1 -3
  39. package/dist/vectordb/sparse/simple-bm25.js.map +1 -1
  40. package/package.json +3 -1
@@ -0,0 +1,162 @@
1
+ import { BaseDatabaseConfig, BaseVectorDatabase } from './base/base-vector-database';
2
+ import { BM25Config } from './sparse/simple-bm25';
3
+ import { HybridSearchOptions, HybridSearchRequest, HybridSearchResult, SearchOptions, VectorDocument, VectorSearchResult } from './types';
4
+ export interface FaissConfig extends BaseDatabaseConfig {
5
+ /**
6
+ * Storage directory for FAISS indexes
7
+ * @default ~/.context/faiss-indexes
8
+ */
9
+ storageDir?: string;
10
+ /**
11
+ * BM25 configuration for sparse vector generation
12
+ */
13
+ bm25Config?: BM25Config;
14
+ }
15
+ /**
16
+ * FAISS Vector Database implementation for local-only deployments
17
+ *
18
+ * Features:
19
+ * - Zero-configuration file-based storage
20
+ * - Hybrid search with BM25 sparse vectors
21
+ * - RRF (Reciprocal Rank Fusion) reranking
22
+ * - Perfect for local development and small-to-medium codebases
23
+ *
24
+ * Architecture:
25
+ * - Dense vectors: Stored in FAISS IndexFlatL2 (L2 distance)
26
+ * - Sparse vectors: Generated using SimpleBM25 for keyword matching
27
+ * - Hybrid search: Combines both using RRF fusion
28
+ *
29
+ * Storage structure:
30
+ * ~/.context/faiss-indexes/
31
+ * └── {collection_name}/
32
+ * ├── dense.index # FAISS index file
33
+ * ├── sparse.json # BM25 model (vocabulary, IDF)
34
+ * └── metadata.json # Document metadata
35
+ *
36
+ * Limitations:
37
+ * - Document deletion is NOT supported (FAISS IndexFlatL2 limitation)
38
+ * - Query filters are NOT supported (returns all documents)
39
+ * - To remove documents, you must drop and recreate the collection
40
+ */
41
+ export declare class FaissVectorDatabase extends BaseVectorDatabase<FaissConfig> {
42
+ private collections;
43
+ constructor(config: FaissConfig);
44
+ /**
45
+ * Get storage directory (lazily computed from config)
46
+ */
47
+ private get storageDir();
48
+ /**
49
+ * Initialize FAISS storage directory
50
+ */
51
+ protected initialize(): Promise<void>;
52
+ /**
53
+ * FAISS indexes are loaded on-demand when accessed
54
+ */
55
+ protected ensureLoaded(collectionName: string): Promise<void>;
56
+ /**
57
+ * Get collection storage path
58
+ */
59
+ private getCollectionPath;
60
+ /**
61
+ * Load collection from disk
62
+ */
63
+ private loadCollection;
64
+ /**
65
+ * Save collection to disk
66
+ */
67
+ private saveCollection;
68
+ /**
69
+ * Create collection with dense vectors only
70
+ */
71
+ createCollection(collectionName: string, dimension: number, description?: string): Promise<void>;
72
+ /**
73
+ * Create collection with hybrid search support (dense + sparse vectors)
74
+ */
75
+ createHybridCollection(collectionName: string, dimension: number, description?: string): Promise<void>;
76
+ /**
77
+ * Drop collection
78
+ */
79
+ dropCollection(collectionName: string): Promise<void>;
80
+ /**
81
+ * Check if collection exists
82
+ */
83
+ hasCollection(collectionName: string): Promise<boolean>;
84
+ /**
85
+ * List all collections
86
+ */
87
+ listCollections(): Promise<string[]>;
88
+ /**
89
+ * Insert vector documents (dense only)
90
+ */
91
+ insert(collectionName: string, documents: VectorDocument[]): Promise<void>;
92
+ /**
93
+ * Insert hybrid vector documents (dense + sparse)
94
+ */
95
+ insertHybrid(collectionName: string, documents: VectorDocument[]): Promise<void>;
96
+ /**
97
+ * Search similar vectors (dense search only)
98
+ */
99
+ search(collectionName: string, queryVector: number[], options?: SearchOptions): Promise<VectorSearchResult[]>;
100
+ /**
101
+ * Hybrid search with multiple vector fields (dense + sparse)
102
+ */
103
+ hybridSearch(collectionName: string, searchRequests: HybridSearchRequest[], options?: HybridSearchOptions): Promise<HybridSearchResult[]>;
104
+ /**
105
+ * Perform dense vector search using FAISS index
106
+ */
107
+ private performDenseSearch;
108
+ /**
109
+ * Perform sparse search using BM25
110
+ */
111
+ private performSparseSearch;
112
+ /**
113
+ * Calculate sparse vector dot product score
114
+ */
115
+ private calculateSparseScore;
116
+ /**
117
+ * Pre-compute ranks from scores (O(n log n) instead of O(n²))
118
+ */
119
+ private computeRanks;
120
+ /**
121
+ * Apply Reciprocal Rank Fusion (RRF) reranking
122
+ */
123
+ private applyRRF;
124
+ /**
125
+ * Delete documents by IDs
126
+ *
127
+ * ⚠️ NOT IMPLEMENTED: FAISS does not support document deletion
128
+ *
129
+ * The FAISS IndexFlatL2 library does not provide a way to remove vectors
130
+ * from an existing index. To fully remove documents, you must:
131
+ *
132
+ * 1. Drop the collection using dropCollection()
133
+ * 2. Recreate it using createCollection() or createHybridCollection()
134
+ * 3. Re-insert all documents except the ones you want to delete
135
+ *
136
+ * @throws Error Always throws - deletion is not supported
137
+ * @param collectionName Collection name
138
+ * @param ids Document IDs to delete (not used)
139
+ */
140
+ delete(collectionName: string, ids: string[]): Promise<void>;
141
+ /**
142
+ * Query documents with filter conditions
143
+ *
144
+ * ⚠️ LIMITATION: Filter parameter is currently ignored
145
+ *
146
+ * This method returns ALL documents in the collection (up to limit),
147
+ * not filtered results. Filter parsing is not yet implemented for FAISS.
148
+ *
149
+ * @param collectionName Collection name
150
+ * @param filter Filter expression (currently ignored - returns all documents)
151
+ * @param outputFields Fields to return in results
152
+ * @param limit Maximum number of results (only limit is enforced)
153
+ * @returns All documents with specified fields (up to limit)
154
+ */
155
+ query(collectionName: string, filter: string, outputFields: string[], limit?: number): Promise<Record<string, any>[]>;
156
+ /**
157
+ * Check collection limit
158
+ * FAISS has no inherent collection limit (only limited by disk space)
159
+ */
160
+ checkCollectionLimit(): Promise<boolean>;
161
+ }
162
+ //# sourceMappingURL=faiss-vectordb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"faiss-vectordb.d.ts","sourceRoot":"","sources":["../../src/vectordb/faiss-vectordb.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AACpF,OAAO,EAAE,UAAU,EAAc,MAAM,sBAAsB,CAAA;AAC7D,OAAO,EACL,mBAAmB,E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