You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Using embedding services (OpenAI, HuggingFace, etc.)
154
+
$results = Document::query()
155
+
->semanticSearch(
156
+
"What is machine learning?",
157
+
'embedding',
158
+
'openai'
159
+
)
160
+
->get();
161
+
162
+
// Sparse vector search with ELSER
163
+
$results = Document::query()
164
+
->sparseVectorSearch("How does AI work?", 'content_embedding')
165
+
->get();
166
+
```
167
+
168
+
#### Hybrid Search & Semantic Reranking
169
+
170
+
```php
171
+
// Hybrid search combining text and vector scores
172
+
$results = Document::query()
173
+
->hybridSearch(
174
+
"machine learning applications",
175
+
['content'],
176
+
'embedding',
177
+
$queryVector,
178
+
textWeight: 0.3,
179
+
vectorWeight: 0.7
180
+
)
181
+
->get();
182
+
183
+
// Semantic reranking to improve relevance
184
+
$results = Document::query()
185
+
->search("artificial intelligence")
186
+
->semanticRerank("How do neural networks work?")
187
+
->get();
188
+
```
189
+
190
+
#### ES|QL Support
191
+
192
+
```php
193
+
// Using Elasticsearch's SQL-like query language
194
+
$results = Document::query()
195
+
->esql("FROM documents WHERE match(content, 'artificial intelligence') | LIMIT 10")
196
+
->get();
197
+
```
198
+
199
+
#### Performance Optimizations
200
+
201
+
```php
202
+
// Field selection and exclusion
203
+
$results = Document::query()
204
+
->select(['content', 'title']) // Only return these fields
205
+
->exclude(['embedding']) // Exclude large vector fields
206
+
->trackTotalHits(false) // Disable exact hit counting for better performance
207
+
->search("machine learning")
208
+
->get();
209
+
```
210
+
211
+
### Data Transfer Objects & Pagination
212
+
213
+
Laravel Elastoquent integrates with [spatie/laravel-data](https://github.com/spatie/laravel-data) to provide structured DTOs for your Elasticsearch results:
214
+
215
+
```php
216
+
// Using the built-in ElasticDocument DTO
217
+
$results = Document::query()
218
+
->where('category', 'technology')
219
+
->asDocument() // Return results as ElasticDocument DTOs
220
+
->get();
221
+
222
+
// Using a custom DTO that extends ElasticDocument
0 commit comments