endee-llamaindex 0.1.2__tar.gz → 0.1.5__tar.gz
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.
- endee_llamaindex-0.1.5/PKG-INFO +615 -0
- endee_llamaindex-0.1.5/README.md +587 -0
- endee_llamaindex-0.1.5/endee_llamaindex/base.py +764 -0
- endee_llamaindex-0.1.5/endee_llamaindex/constants.py +70 -0
- endee_llamaindex-0.1.5/endee_llamaindex/utils.py +160 -0
- endee_llamaindex-0.1.5/endee_llamaindex.egg-info/PKG-INFO +615 -0
- {endee_llamaindex-0.1.2 → endee_llamaindex-0.1.5}/endee_llamaindex.egg-info/SOURCES.txt +2 -0
- endee_llamaindex-0.1.5/endee_llamaindex.egg-info/requires.txt +6 -0
- {endee_llamaindex-0.1.2 → endee_llamaindex-0.1.5}/setup.py +10 -3
- endee_llamaindex-0.1.2/PKG-INFO +0 -140
- endee_llamaindex-0.1.2/README.md +0 -116
- endee_llamaindex-0.1.2/endee_llamaindex/base.py +0 -416
- endee_llamaindex-0.1.2/endee_llamaindex.egg-info/PKG-INFO +0 -140
- endee_llamaindex-0.1.2/endee_llamaindex.egg-info/requires.txt +0 -2
- {endee_llamaindex-0.1.2 → endee_llamaindex-0.1.5}/endee_llamaindex/__init__.py +0 -0
- {endee_llamaindex-0.1.2 → endee_llamaindex-0.1.5}/endee_llamaindex.egg-info/dependency_links.txt +0 -0
- {endee_llamaindex-0.1.2 → endee_llamaindex-0.1.5}/endee_llamaindex.egg-info/top_level.txt +0 -0
- {endee_llamaindex-0.1.2 → endee_llamaindex-0.1.5}/setup.cfg +0 -0
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: endee-llamaindex
|
|
3
|
+
Version: 0.1.5
|
|
4
|
+
Summary: Vector Database for Fast ANN Searches
|
|
5
|
+
Home-page: https://endee.io
|
|
6
|
+
Author: Endee Labs
|
|
7
|
+
Author-email: vineet@endee.io
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: llama-index>=0.12.34
|
|
14
|
+
Requires-Dist: endee==0.1.9
|
|
15
|
+
Requires-Dist: fastembed>=0.3.0
|
|
16
|
+
Provides-Extra: gpu
|
|
17
|
+
Requires-Dist: fastembed-gpu>=0.3.0; extra == "gpu"
|
|
18
|
+
Dynamic: author
|
|
19
|
+
Dynamic: author-email
|
|
20
|
+
Dynamic: classifier
|
|
21
|
+
Dynamic: description
|
|
22
|
+
Dynamic: description-content-type
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: provides-extra
|
|
25
|
+
Dynamic: requires-dist
|
|
26
|
+
Dynamic: requires-python
|
|
27
|
+
Dynamic: summary
|
|
28
|
+
|
|
29
|
+
# Endee LlamaIndex Integration
|
|
30
|
+
|
|
31
|
+
Build powerful RAG applications with Endee vector database and LlamaIndex.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Table of Contents
|
|
36
|
+
|
|
37
|
+
1. [Installation](#1-installation)
|
|
38
|
+
2. [Testing locally](#testing-locally)
|
|
39
|
+
3. [Setting up Credentials](#2-setting-up-endee-and-openai-credentials)
|
|
40
|
+
4. [Creating Sample Documents](#3-creating-sample-documents)
|
|
41
|
+
5. [Setting up Endee with LlamaIndex](#4-setting-up-endee-with-llamaindex)
|
|
42
|
+
6. [Creating a Vector Index](#5-creating-a-vector-index-from-documents)
|
|
43
|
+
7. [Basic Retrieval](#6-basic-retrieval-with-query-engine)
|
|
44
|
+
8. [Using Metadata Filters](#7-using-metadata-filters)
|
|
45
|
+
9. [Advanced Filtering](#8-advanced-filtering-with-multiple-conditions)
|
|
46
|
+
10. [Custom Retriever Setup](#9-custom-retriever-setup)
|
|
47
|
+
11. [Custom Retriever with Query Engine](#10-using-a-custom-retriever-with-a-query-engine)
|
|
48
|
+
12. [Direct VectorStore Querying](#11-direct-vectorstore-querying)
|
|
49
|
+
13. [Saving and Loading Indexes](#12-saving-and-loading-indexes)
|
|
50
|
+
14. [Cleanup](#13-cleanup)
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 1. Installation
|
|
55
|
+
|
|
56
|
+
Get started by installing the required package.
|
|
57
|
+
|
|
58
|
+
### Basic Installation (Dense-only search)
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pip install endee-llamaindex
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
> **Note:** This will automatically install `endee` and `llama-index` as dependencies.
|
|
65
|
+
|
|
66
|
+
### Full Installation (with Hybrid Search support)
|
|
67
|
+
|
|
68
|
+
For hybrid search capabilities (dense + sparse vectors), install with the `hybrid` extra:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install endee-llamaindex[hybrid]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
This includes FastEmbed for sparse vector encoding (SPLADE, BM25, etc.).
|
|
75
|
+
|
|
76
|
+
### GPU-Accelerated Hybrid Search
|
|
77
|
+
|
|
78
|
+
For GPU-accelerated sparse encoding:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install endee-llamaindex[hybrid-gpu]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### All Features
|
|
85
|
+
|
|
86
|
+
To install all optional dependencies:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
pip install endee-llamaindex[all]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Installation Options Summary
|
|
93
|
+
|
|
94
|
+
| Installation | Use Case | Includes |
|
|
95
|
+
|--------------|----------|----------|
|
|
96
|
+
| `pip install endee-llamaindex` | Dense vector search only | Core dependencies |
|
|
97
|
+
| `pip install endee-llamaindex[hybrid]` | Dense + sparse hybrid search | + FastEmbed (CPU) |
|
|
98
|
+
| `pip install endee-llamaindex[hybrid-gpu]` | GPU-accelerated hybrid search | + FastEmbed (GPU) |
|
|
99
|
+
| `pip install endee-llamaindex[all]` | All features | All optional deps |
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Testing locally
|
|
104
|
+
|
|
105
|
+
From the project root:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
python -m venv env && source env/bin/activate # optional
|
|
109
|
+
pip install -e .
|
|
110
|
+
pip install pytest sentence-transformers huggingface-hub
|
|
111
|
+
export ENDEE_API_TOKEN="your-endee-api-token" # or set in endee_llamaindex/test_cases/setup_class.py
|
|
112
|
+
|
|
113
|
+
cd endee_llamaindex/test_cases && PYTHONPATH=.. python -m pytest . -v
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
See [TESTING.md](TESTING.md) for more options and single-test runs.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 2. Setting up Endee and OpenAI credentials
|
|
121
|
+
|
|
122
|
+
Configure your API credentials for Endee and OpenAI.
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
import os
|
|
126
|
+
from llama_index.embeddings.openai import OpenAIEmbedding
|
|
127
|
+
|
|
128
|
+
# Set API keys
|
|
129
|
+
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"
|
|
130
|
+
endee_api_token = "your-endee-api-token"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
> **Tip:** Store your API keys in environment variables for production use.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## 3. Creating Sample Documents
|
|
138
|
+
|
|
139
|
+
Create documents with metadata for filtering and organization.
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from llama_index.core import Document
|
|
143
|
+
|
|
144
|
+
# Create sample documents with different categories and metadata
|
|
145
|
+
documents = [
|
|
146
|
+
Document(
|
|
147
|
+
text="Python is a high-level, interpreted programming language known for its readability and simplicity.",
|
|
148
|
+
metadata={"category": "programming", "language": "python", "difficulty": "beginner"}
|
|
149
|
+
),
|
|
150
|
+
Document(
|
|
151
|
+
text="JavaScript is a scripting language that enables interactive web pages and is an essential part of web applications.",
|
|
152
|
+
metadata={"category": "programming", "language": "javascript", "difficulty": "intermediate"}
|
|
153
|
+
),
|
|
154
|
+
Document(
|
|
155
|
+
text="Machine learning is a subset of artificial intelligence that provides systems the ability to automatically learn and improve from experience.",
|
|
156
|
+
metadata={"category": "ai", "field": "machine_learning", "difficulty": "advanced"}
|
|
157
|
+
),
|
|
158
|
+
Document(
|
|
159
|
+
text="Deep learning is part of a broader family of machine learning methods based on artificial neural networks with representation learning.",
|
|
160
|
+
metadata={"category": "ai", "field": "deep_learning", "difficulty": "advanced"}
|
|
161
|
+
),
|
|
162
|
+
Document(
|
|
163
|
+
text="Vector databases are specialized database systems designed to store and query high-dimensional vectors for similarity search.",
|
|
164
|
+
metadata={"category": "database", "type": "vector", "difficulty": "intermediate"}
|
|
165
|
+
),
|
|
166
|
+
Document(
|
|
167
|
+
text="Endee is a vector database that provides secure and private vector search capabilities.",
|
|
168
|
+
metadata={"category": "database", "type": "vector", "product": "endee", "difficulty": "intermediate"}
|
|
169
|
+
)
|
|
170
|
+
]
|
|
171
|
+
|
|
172
|
+
print(f"Created {len(documents)} sample documents")
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Output:**
|
|
176
|
+
```
|
|
177
|
+
Created 6 sample documents
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## 4. Setting up Endee with LlamaIndex
|
|
183
|
+
|
|
184
|
+
Initialize the Endee vector store and connect it to LlamaIndex.
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from endee_llamaindex import EndeeVectorStore
|
|
188
|
+
from llama_index.core import StorageContext
|
|
189
|
+
import time
|
|
190
|
+
|
|
191
|
+
# Create a unique index name with timestamp to avoid conflicts
|
|
192
|
+
timestamp = int(time.time())
|
|
193
|
+
index_name = f"llamaindex_demo_{timestamp}"
|
|
194
|
+
|
|
195
|
+
# Set up the embedding model
|
|
196
|
+
embed_model = OpenAIEmbedding()
|
|
197
|
+
|
|
198
|
+
# Get the embedding dimension
|
|
199
|
+
dimension = 1536 # OpenAI's default embedding dimension
|
|
200
|
+
|
|
201
|
+
# Initialize the Endee vector store
|
|
202
|
+
vector_store = EndeeVectorStore.from_params(
|
|
203
|
+
api_token=endee_api_token,
|
|
204
|
+
index_name=index_name,
|
|
205
|
+
dimension=dimension,
|
|
206
|
+
space_type="cosine", # Can be "cosine", "l2", or "ip"
|
|
207
|
+
precision="float16" # Options: "binary", "float16", "float32", "int16d", "int8d" (default: "float16")
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
# Create storage context with our vector store
|
|
211
|
+
storage_context = StorageContext.from_defaults(vector_store=vector_store)
|
|
212
|
+
|
|
213
|
+
print(f"Initialized Endee vector store with index: {index_name}")
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Configuration Options
|
|
217
|
+
|
|
218
|
+
| Parameter | Description | Options |
|
|
219
|
+
|-----------|-------------|---------|
|
|
220
|
+
| `space_type` | Distance metric for similarity | `cosine`, `l2`, `ip` |
|
|
221
|
+
| `dimension` | Vector dimension | Must match embedding model |
|
|
222
|
+
| `precision` | Index precision setting | `"binary"`, `"float16"` (default), `"float32"`, `"int16d"`, `"int8d"` |
|
|
223
|
+
| `batch_size` | Vectors per API call | Default: `100` |
|
|
224
|
+
| `hybrid` | Enable hybrid search (dense + sparse) | Default: `False` |
|
|
225
|
+
| `M` | Optional HNSW M parameter (bi-directional links) | Optional (backend default if not specified) |
|
|
226
|
+
| `ef_con` | Optional HNSW ef_construction parameter | Optional (backend default if not specified) |
|
|
227
|
+
|
|
228
|
+
### Hybrid Search and Sparse Models
|
|
229
|
+
|
|
230
|
+
When you enable hybrid search by providing a positive `sparse_dim` and a `model_name`, the vector store automatically computes sparse (bag-of-words‑style) vectors in addition to dense vectors.
|
|
231
|
+
|
|
232
|
+
- **Sparse dimension (`sparse_dim`)**:
|
|
233
|
+
- For the built-in SPLADE models, the recommended `sparse_dim` is **30522** (matching the model vocabulary size).
|
|
234
|
+
- For dense‑only search, omit `sparse_dim` (or set it to `0`).
|
|
235
|
+
- **Supported sparse models (`model_name`)**:
|
|
236
|
+
- `"splade_pp"` → `prithivida/Splade_PP_en_v1` (SPLADE++)
|
|
237
|
+
- `"splade_cocondenser"` → `naver/splade-cocondenser-ensembledistil`
|
|
238
|
+
|
|
239
|
+
Example hybrid configuration:
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
vector_store = EndeeVectorStore.from_params(
|
|
243
|
+
api_token=endee_api_token,
|
|
244
|
+
index_name=index_name,
|
|
245
|
+
dimension=dimension, # dense dimension (e.g., 1536 for OpenAI)
|
|
246
|
+
space_type="cosine",
|
|
247
|
+
precision="float16",
|
|
248
|
+
hybrid=True,
|
|
249
|
+
sparse_dim=30522, # sparse dimension for SPLADE models
|
|
250
|
+
model_name="splade_pp", # or "splade_cocondenser"
|
|
251
|
+
)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## 5. Creating a Vector Index from Documents
|
|
257
|
+
|
|
258
|
+
Build a searchable vector index from your documents.
|
|
259
|
+
|
|
260
|
+
```python
|
|
261
|
+
from llama_index.core import VectorStoreIndex
|
|
262
|
+
|
|
263
|
+
# Create a vector index
|
|
264
|
+
index = VectorStoreIndex.from_documents(
|
|
265
|
+
documents,
|
|
266
|
+
storage_context=storage_context,
|
|
267
|
+
embed_model=embed_model
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
print("Vector index created successfully")
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Output:**
|
|
274
|
+
```
|
|
275
|
+
Vector index created successfully
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## 6. Basic Retrieval with Query Engine
|
|
281
|
+
|
|
282
|
+
Create a query engine and perform semantic search.
|
|
283
|
+
|
|
284
|
+
```python
|
|
285
|
+
# Create a query engine
|
|
286
|
+
query_engine = index.as_query_engine()
|
|
287
|
+
|
|
288
|
+
# Ask a question
|
|
289
|
+
response = query_engine.query("What is Python?")
|
|
290
|
+
|
|
291
|
+
print("Query: What is Python?")
|
|
292
|
+
print("Response:")
|
|
293
|
+
print(response)
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
**Example Output:**
|
|
297
|
+
```
|
|
298
|
+
Query: What is Python?
|
|
299
|
+
Response:
|
|
300
|
+
Python is a high-level, interpreted programming language known for its readability and simplicity.
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## 7. Using Metadata Filters
|
|
306
|
+
|
|
307
|
+
Filter search results based on document metadata.
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
from llama_index.core.vector_stores.types import MetadataFilters, MetadataFilter, FilterOperator
|
|
311
|
+
|
|
312
|
+
# Create a filtered retriever to only search within AI-related documents
|
|
313
|
+
ai_filter = MetadataFilter(key="category", value="ai", operator=FilterOperator.EQ)
|
|
314
|
+
ai_filters = MetadataFilters(filters=[ai_filter])
|
|
315
|
+
|
|
316
|
+
# Create a filtered query engine
|
|
317
|
+
filtered_query_engine = index.as_query_engine(filters=ai_filters)
|
|
318
|
+
|
|
319
|
+
# Ask a general question but only using AI documents
|
|
320
|
+
response = filtered_query_engine.query("What is learning from data?")
|
|
321
|
+
|
|
322
|
+
print("Filtered Query (AI category only): What is learning from data?")
|
|
323
|
+
print("Response:")
|
|
324
|
+
print(response)
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Available Filter Operators
|
|
328
|
+
|
|
329
|
+
| Operator | Description | Backend Symbol | Example |
|
|
330
|
+
|----------|-------------|----------------|---------|
|
|
331
|
+
| `FilterOperator.EQ` | Equal to | `$eq` | `rating == 5` |
|
|
332
|
+
| `FilterOperator.IN` | In list | `$in` | `category in ["ai", "ml"]` |
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
> **Important Notes:**
|
|
336
|
+
> - Currently, the Endee LlamaIndex integration only supports **EQ** and **IN** metadata filters.
|
|
337
|
+
> - Range-style operators (LT, LTE, GT, GTE) are **not** supported in this adapter.
|
|
338
|
+
|
|
339
|
+
### Filter Examples
|
|
340
|
+
|
|
341
|
+
Here are practical examples showing how to use the supported filter operators:
|
|
342
|
+
|
|
343
|
+
```python
|
|
344
|
+
from llama_index.core.vector_stores.types import MetadataFilters, MetadataFilter, FilterOperator
|
|
345
|
+
|
|
346
|
+
# Example 1: Equal to (EQ)
|
|
347
|
+
# Find documents with rating equal to 5
|
|
348
|
+
rating_filter = MetadataFilter(key="rating", value=5, operator=FilterOperator.EQ)
|
|
349
|
+
filters = MetadataFilters(filters=[rating_filter])
|
|
350
|
+
# Backend: {"rating": {"$eq": 5}}
|
|
351
|
+
|
|
352
|
+
# Example 2: In list (IN)
|
|
353
|
+
# Find documents in AI or ML categories
|
|
354
|
+
category_filter = MetadataFilter(key="category", value=["ai", "ml"], operator=FilterOperator.IN)
|
|
355
|
+
filters = MetadataFilters(filters=[category_filter])
|
|
356
|
+
# Backend: {"category": {"$in": ["ai", "ml"]}}
|
|
357
|
+
|
|
358
|
+
# Example 3: Combined filters (AND logic)
|
|
359
|
+
# Find AI documents with rating equal to 5
|
|
360
|
+
filters = MetadataFilters(filters=[
|
|
361
|
+
MetadataFilter(key="category", value="ai", operator=FilterOperator.EQ),
|
|
362
|
+
MetadataFilter(key="rating", value=5, operator=FilterOperator.EQ)
|
|
363
|
+
])
|
|
364
|
+
# Backend: [{"category": {"$eq": "ai"}}, {"rating": {"$eq": 5}}]
|
|
365
|
+
|
|
366
|
+
# Create a query engine with filters
|
|
367
|
+
filtered_engine = index.as_query_engine(filters=filters)
|
|
368
|
+
response = filtered_engine.query("What is machine learning?")
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
## 8. Advanced Filtering with Multiple Conditions
|
|
374
|
+
|
|
375
|
+
Combine multiple metadata filters for precise results.
|
|
376
|
+
|
|
377
|
+
```python
|
|
378
|
+
# Create a more complex filter: database category AND intermediate difficulty
|
|
379
|
+
category_filter = MetadataFilter(key="category", value="database", operator=FilterOperator.EQ)
|
|
380
|
+
difficulty_filter = MetadataFilter(key="difficulty", value="intermediate", operator=FilterOperator.EQ)
|
|
381
|
+
|
|
382
|
+
complex_filters = MetadataFilters(filters=[category_filter, difficulty_filter])
|
|
383
|
+
|
|
384
|
+
# Create a query engine with the complex filters
|
|
385
|
+
complex_filtered_engine = index.as_query_engine(filters=complex_filters)
|
|
386
|
+
|
|
387
|
+
# Query with the complex filters
|
|
388
|
+
response = complex_filtered_engine.query("Tell me about databases")
|
|
389
|
+
|
|
390
|
+
print("Complex Filtered Query (database category AND intermediate difficulty): Tell me about databases")
|
|
391
|
+
print("Response:")
|
|
392
|
+
print(response)
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
> **Note:** Multiple filters are combined with AND logic by default.
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## 9. Custom Retriever Setup
|
|
400
|
+
|
|
401
|
+
Create a custom retriever for fine-grained control over the retrieval process.
|
|
402
|
+
|
|
403
|
+
```python
|
|
404
|
+
from llama_index.core.retrievers import VectorIndexRetriever
|
|
405
|
+
|
|
406
|
+
# Create a retriever with custom parameters
|
|
407
|
+
retriever = VectorIndexRetriever(
|
|
408
|
+
index=index,
|
|
409
|
+
similarity_top_k=3, # Return top 3 most similar results
|
|
410
|
+
filters=ai_filters # Use our AI category filter from before
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
# Retrieve nodes for a query
|
|
414
|
+
nodes = retriever.retrieve("What is deep learning?")
|
|
415
|
+
|
|
416
|
+
print(f"Retrieved {len(nodes)} nodes for query: 'What is deep learning?' (with AI category filter)")
|
|
417
|
+
print("\nRetrieved content:")
|
|
418
|
+
for i, node in enumerate(nodes):
|
|
419
|
+
print(f"\nNode {i+1}:")
|
|
420
|
+
print(f"Text: {node.node.text}")
|
|
421
|
+
print(f"Metadata: {node.node.metadata}")
|
|
422
|
+
print(f"Score: {node.score:.4f}")
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
**Example Output:**
|
|
426
|
+
```
|
|
427
|
+
Retrieved 2 nodes for query: 'What is deep learning?' (with AI category filter)
|
|
428
|
+
|
|
429
|
+
Node 1:
|
|
430
|
+
Text: Deep learning is part of a broader family of machine learning methods...
|
|
431
|
+
Metadata: {'category': 'ai', 'field': 'deep_learning', 'difficulty': 'advanced'}
|
|
432
|
+
Score: 0.8934
|
|
433
|
+
|
|
434
|
+
Node 2:
|
|
435
|
+
Text: Machine learning is a subset of artificial intelligence...
|
|
436
|
+
Metadata: {'category': 'ai', 'field': 'machine_learning', 'difficulty': 'advanced'}
|
|
437
|
+
Score: 0.7821
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
---
|
|
441
|
+
|
|
442
|
+
## 10. Using a Custom Retriever with a Query Engine
|
|
443
|
+
|
|
444
|
+
Combine your custom retriever with a query engine for enhanced control.
|
|
445
|
+
|
|
446
|
+
```python
|
|
447
|
+
from llama_index.core.query_engine import RetrieverQueryEngine
|
|
448
|
+
|
|
449
|
+
# Create a query engine with our custom retriever
|
|
450
|
+
custom_query_engine = RetrieverQueryEngine.from_args(
|
|
451
|
+
retriever=retriever,
|
|
452
|
+
verbose=True # Enable verbose mode to see the retrieved nodes
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
# Query using the custom retriever query engine
|
|
456
|
+
response = custom_query_engine.query("Explain the difference between machine learning and deep learning")
|
|
457
|
+
|
|
458
|
+
print("\nFinal Response:")
|
|
459
|
+
print(response)
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
---
|
|
463
|
+
|
|
464
|
+
## 11. Direct VectorStore Querying
|
|
465
|
+
|
|
466
|
+
Query the Endee vector store directly, bypassing the LlamaIndex query engine.
|
|
467
|
+
|
|
468
|
+
```python
|
|
469
|
+
from llama_index.core.vector_stores.types import VectorStoreQuery
|
|
470
|
+
|
|
471
|
+
# Generate an embedding for our query
|
|
472
|
+
query_text = "What are vector databases?"
|
|
473
|
+
query_embedding = embed_model.get_text_embedding(query_text)
|
|
474
|
+
|
|
475
|
+
# Create a VectorStoreQuery
|
|
476
|
+
vector_store_query = VectorStoreQuery(
|
|
477
|
+
query_embedding=query_embedding,
|
|
478
|
+
similarity_top_k=2,
|
|
479
|
+
filters=MetadataFilters(filters=[MetadataFilter(key="category", value="database", operator=FilterOperator.EQ)])
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
# Execute the query directly on the vector store
|
|
483
|
+
query_result = vector_store.query(vector_store_query)
|
|
484
|
+
|
|
485
|
+
print(f"Direct VectorStore query: '{query_text}'")
|
|
486
|
+
print(f"Retrieved {len(query_result.nodes)} results with database category filter:")
|
|
487
|
+
for i, (node, score) in enumerate(zip(query_result.nodes, query_result.similarities)):
|
|
488
|
+
print(f"\nResult {i+1}:")
|
|
489
|
+
print(f"Text: {node.text}")
|
|
490
|
+
print(f"Metadata: {node.metadata}")
|
|
491
|
+
print(f"Similarity score: {score:.4f}")
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
> **Tip:** Direct querying is useful when you need raw results without LLM processing.
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
## 12. Saving and Loading Indexes
|
|
499
|
+
|
|
500
|
+
Reconnect to your index in future sessions. Your vectors are stored in the cloud.
|
|
501
|
+
|
|
502
|
+
```python
|
|
503
|
+
# To reconnect to an existing index in a future session:
|
|
504
|
+
def reconnect_to_index(api_token, index_name):
|
|
505
|
+
# Initialize the vector store with existing index
|
|
506
|
+
vector_store = EndeeVectorStore.from_params(
|
|
507
|
+
api_token=api_token,
|
|
508
|
+
index_name=index_name
|
|
509
|
+
)
|
|
510
|
+
|
|
511
|
+
# Create storage context
|
|
512
|
+
storage_context = StorageContext.from_defaults(vector_store=vector_store)
|
|
513
|
+
|
|
514
|
+
# Load the index
|
|
515
|
+
index = VectorStoreIndex.from_vector_store(
|
|
516
|
+
vector_store,
|
|
517
|
+
embed_model=OpenAIEmbedding()
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
return index
|
|
521
|
+
|
|
522
|
+
# Example usage
|
|
523
|
+
reconnected_index = reconnect_to_index(endee_api_token, index_name)
|
|
524
|
+
query_engine = reconnected_index.as_query_engine()
|
|
525
|
+
response = query_engine.query("What is Endee?")
|
|
526
|
+
print(response)
|
|
527
|
+
|
|
528
|
+
print(f"To reconnect to this index in the future, use:\n")
|
|
529
|
+
print(f"API Token: {endee_api_token}")
|
|
530
|
+
print(f"Index Name: {index_name}")
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
> **Important:** Save your `index_name` to reconnect to your data later.
|
|
534
|
+
|
|
535
|
+
---
|
|
536
|
+
|
|
537
|
+
## 13. Cleanup
|
|
538
|
+
|
|
539
|
+
Delete the index when you're done to free up resources.
|
|
540
|
+
|
|
541
|
+
```python
|
|
542
|
+
# Uncomment to delete your index
|
|
543
|
+
# endee.delete_index(index_name)
|
|
544
|
+
# print(f"Index {index_name} deleted")
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
> **Warning:** Deleting an index permanently removes all stored vectors and cannot be undone.
|
|
548
|
+
|
|
549
|
+
---
|
|
550
|
+
|
|
551
|
+
## Quick Reference
|
|
552
|
+
|
|
553
|
+
### EndeeVectorStore Parameters
|
|
554
|
+
|
|
555
|
+
| Parameter | Type | Description | Default |
|
|
556
|
+
|-----------|------|-------------|---------|
|
|
557
|
+
| `api_token` | `str` | Your Endee API token | Required |
|
|
558
|
+
| `index_name` | `str` | Name of the index | Required |
|
|
559
|
+
| `dimension` | `int` | Vector dimension | Required |
|
|
560
|
+
| `space_type` | `str` | Distance metric (`"cosine"`, `"l2"`, `"ip"`) | `"cosine"` |
|
|
561
|
+
| `precision` | `str` | Index precision (`"binary"`, `"float16"`, `"float32"`, `"int16d"`, `"int8d"`) | `"float16"` |
|
|
562
|
+
| `batch_size` | `int` | Vectors per API call | `100` |
|
|
563
|
+
| `hybrid` | `bool` | Enable hybrid search (dense + sparse vectors) | `False` |
|
|
564
|
+
| `sparse_dim` | `int` | Sparse dimension for hybrid index | `None` |
|
|
565
|
+
| `model_name` | `str` | Model name for sparse embeddings (e.g., `'splade_pp'`, `'bert_base'`) | `None` |
|
|
566
|
+
| `M` | `int` | Optional HNSW M parameter (bi-directional links per node) | `None` (backend default) |
|
|
567
|
+
| `ef_con` | `int` | Optional HNSW ef_construction parameter | `None` (backend default) |
|
|
568
|
+
|
|
569
|
+
### Distance Metrics
|
|
570
|
+
|
|
571
|
+
| Metric | Best For |
|
|
572
|
+
|--------|----------|
|
|
573
|
+
| `cosine` | Text embeddings, normalized vectors |
|
|
574
|
+
| `l2` | Image features, spatial data |
|
|
575
|
+
| `ip` | Recommendation systems, dot product similarity |
|
|
576
|
+
|
|
577
|
+
### Precision Settings
|
|
578
|
+
|
|
579
|
+
The `precision` parameter controls the vector storage format and affects memory usage and search performance:
|
|
580
|
+
|
|
581
|
+
| Precision | Description | Use Case |
|
|
582
|
+
|-----------|-------------|----------|
|
|
583
|
+
| `"float32"` | Full precision floating point | Maximum accuracy, higher memory usage |
|
|
584
|
+
| `"float16"` | Half precision floating point | Balanced accuracy and memory (default) |
|
|
585
|
+
| `"binary"` | Binary vectors | Extremely compact, best for binary embeddings |
|
|
586
|
+
| `"int8d"` | 8-bit integer quantization | High compression, good accuracy |
|
|
587
|
+
| `"int16d"` | 16-bit integer quantization | Better accuracy than int8d, moderate compression |
|
|
588
|
+
|
|
589
|
+
### HNSW Parameters (Optional)
|
|
590
|
+
|
|
591
|
+
HNSW (Hierarchical Navigable Small World) parameters control index construction and search quality. These are **optional** - if not provided, the Endee backend uses optimized defaults.
|
|
592
|
+
|
|
593
|
+
| Parameter | Description | Impact |
|
|
594
|
+
|-----------|-------------|--------|
|
|
595
|
+
| `M` | Number of bi-directional links per node | Higher M = better recall, more memory |
|
|
596
|
+
| `ef_con` | Size of dynamic candidate list during construction | Higher ef_con = better quality, slower indexing |
|
|
597
|
+
|
|
598
|
+
**Example with custom HNSW parameters:**
|
|
599
|
+
|
|
600
|
+
```python
|
|
601
|
+
vector_store = EndeeVectorStore.from_params(
|
|
602
|
+
api_token="your-token",
|
|
603
|
+
index_name="custom_index",
|
|
604
|
+
dimension=384,
|
|
605
|
+
space_type="cosine",
|
|
606
|
+
M=32, # Optional: custom M value
|
|
607
|
+
ef_con=256 # Optional: custom ef_construction
|
|
608
|
+
)
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
**Note:** Only specify M and ef_con if you need to fine-tune performance. The backend defaults work well for most use cases.
|
|
612
|
+
|
|
613
|
+
---
|
|
614
|
+
|
|
615
|
+
|