prescient 0.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/INTEGRATION_GUIDE.md +12 -1
- data/README.md +177 -12
- data/Rakefile +1 -1
- data/VECTOR_SEARCH_GUIDE.md +7 -3
- data/examples/README.md +2 -1
- data/examples/basic_usage.rb +1 -1
- data/examples/custom_contexts.rb +6 -21
- data/examples/vector_search.rb +69 -305
- data/lib/prescient/cli.rb +196 -4
- data/lib/prescient/configuration_loader.rb +437 -0
- data/lib/prescient/provider/deepseek.rb +139 -0
- data/lib/prescient/provider/gemini.rb +173 -0
- data/lib/prescient/provider/huggingface.rb +1 -0
- data/lib/prescient/provider/mistral.rb +171 -0
- data/lib/prescient/provider/openai.rb +3 -0
- data/lib/prescient/provider/xai.rb +139 -0
- data/lib/prescient/version.rb +1 -1
- data/lib/prescient.rb +116 -22
- data/schema/prescient.configuration.schema.json +153 -0
- data/sig/prescient.rbs +105 -0
- metadata +7 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 53a88a152c9fb689789c06dc11612905e30d76e997dbdcc1ca9906870bb01899
|
|
4
|
+
data.tar.gz: 4dba29dd0ad5ae0edbccd0f9d50d8e1eeb8815ba1aeadda838b327ec124111d6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0beee5d0fc6ca63e1d2f881055402a18ab374d8ec71f17c6e706bba7a0ec8f565bbd77ff4f1b337f100597d357a07ffcc45b37e080429199603ce3147e292579
|
|
7
|
+
data.tar.gz: 2d8214bfb8d5f61536e5c79462d560cd4d6f83215dae54cffed821fe0f23d2959adbe02ec94f522d69bd2e04adb37b52087ba364752a98e093e6605ce204abfb
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## [0.5.0] - 2025-08-14
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Added a versioned YAML configuration loader with environment-variable references,
|
|
10
|
+
configuration validation, precedence rules, and a packaged JSON Schema.
|
|
11
|
+
- Added YAML-configurable prompt templates and CLI prompt overrides, including
|
|
12
|
+
support for loading multiline templates from a file.
|
|
13
|
+
- Added `prescient config example` for generating an annotated schema-backed YAML configuration starter.
|
|
14
|
+
- Added Google Gemini provider support for text generation, embeddings, health checks, and model listing.
|
|
15
|
+
- Added Gemini environment-variable defaults and YAML configuration support.
|
|
16
|
+
- Added Mistral provider support for text generation, embeddings, health checks, and model listing.
|
|
17
|
+
- Added Mistral environment-variable defaults and YAML configuration support.
|
|
18
|
+
- Added DeepSeek provider support for text generation, health checks, and model listing.
|
|
19
|
+
- Documented DeepSeek's unsupported embedding capability explicitly.
|
|
20
|
+
- Added xAI provider support for text generation, health checks, and model listing.
|
|
21
|
+
- Documented xAI's unsupported embedding capability explicitly.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- Raised YARD documentation coverage enforcement from 99% to 100%.
|
|
26
|
+
|
|
5
27
|
## [0.4.0] - 2025-08-14
|
|
6
28
|
|
|
7
29
|
### Added
|
data/INTEGRATION_GUIDE.md
CHANGED
|
@@ -13,7 +13,7 @@ and [examples guide](examples/README.md).
|
|
|
13
13
|
# Add to your Gemfile
|
|
14
14
|
gem 'prescient', path: './prescient_gem' # Local development
|
|
15
15
|
# OR when published:
|
|
16
|
-
# gem 'prescient', '~> 0.
|
|
16
|
+
# gem 'prescient', '~> 0.5.0'
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
### 2. Replace Existing AI Service
|
|
@@ -117,6 +117,17 @@ end
|
|
|
117
117
|
Rails.application.config.default_ai_provider = :ollama
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
+
For YAML-based deployments, use the versioned configuration format and keep
|
|
121
|
+
credentials in environment variables:
|
|
122
|
+
|
|
123
|
+
```ruby
|
|
124
|
+
Prescient.load_configuration('prescient.yml')
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Configuration precedence is CLI overrides, environment defaults and
|
|
128
|
+
references, YAML values, then built-in defaults. The generated
|
|
129
|
+
`prescient config example` file includes the current JSON Schema URL.
|
|
130
|
+
|
|
120
131
|
### 4. Update Environment Variables
|
|
121
132
|
|
|
122
133
|
```bash
|
data/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# Prescient
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://rubygems.org/gems/prescient)
|
|
4
|
+
[](https://www.ruby-lang.org/)
|
|
5
|
+
[](https://github.com/kanutocd/prescient/actions/workflows/ci.yml)
|
|
6
|
+
[](https://github.com/kanutocd/prescient/actions/workflows/security.yml)
|
|
7
|
+
[](LICENSE.txt)
|
|
8
|
+
|
|
9
|
+
Prescient is a boring AI provider abstraction for Ruby. Configure your AI providers once, then use the same interface regardless of whether the request is handled by OpenAI, Anthropic, Ollama, Hugging Face, Google Gemini, Mistral, DeepSeek, or xAI. Prescient handles provider selection, retries, health checks, and fallback.
|
|
4
10
|
|
|
5
11
|
For focused guidance, see the **[examples guide](https://github.com/kanutocd/prescient/tree/main/examples)**,
|
|
6
12
|
**[Rails integration guide](https://github.com/kanutocd/prescient/blob/main/INTEGRATION_GUIDE.md)**, and
|
|
@@ -14,7 +20,7 @@ For focused guidance, see the **[examples guide](https://github.com/kanutocd/pre
|
|
|
14
20
|
- **Text Completion**: Chat completions with context support
|
|
15
21
|
- **Error Handling**: Robust error handling with automatic retries
|
|
16
22
|
- **Health Monitoring**: Built-in health checks for all providers
|
|
17
|
-
- **Flexible Configuration**:
|
|
23
|
+
- **Flexible Configuration**: YAML, environment variable, and programmatic configuration
|
|
18
24
|
|
|
19
25
|
## Supported Providers
|
|
20
26
|
|
|
@@ -42,6 +48,30 @@ For focused guidance, see the **[examples guide](https://github.com/kanutocd/pre
|
|
|
42
48
|
- **Capabilities**: Embeddings, Text Generation
|
|
43
49
|
- **Use Case**: Open-source models, research
|
|
44
50
|
|
|
51
|
+
### Google Gemini
|
|
52
|
+
|
|
53
|
+
- **Models**: Gemini generation and embedding models
|
|
54
|
+
- **Capabilities**: Embeddings, Text Generation, Model Listing
|
|
55
|
+
- **Use Case**: Google AI hosted models
|
|
56
|
+
|
|
57
|
+
### Mistral
|
|
58
|
+
|
|
59
|
+
- **Models**: Mistral chat and embedding models
|
|
60
|
+
- **Capabilities**: Embeddings, Text Generation, Model Listing
|
|
61
|
+
- **Use Case**: Mistral AI hosted models
|
|
62
|
+
|
|
63
|
+
### DeepSeek
|
|
64
|
+
|
|
65
|
+
- **Models**: DeepSeek chat models
|
|
66
|
+
- **Capabilities**: Text Generation, Model Listing (no embeddings)
|
|
67
|
+
- **Use Case**: DeepSeek hosted reasoning and chat models
|
|
68
|
+
|
|
69
|
+
### xAI
|
|
70
|
+
|
|
71
|
+
- **Models**: Grok chat models
|
|
72
|
+
- **Capabilities**: Text Generation, Model Listing (no embeddings)
|
|
73
|
+
- **Use Case**: xAI hosted reasoning and chat models
|
|
74
|
+
|
|
45
75
|
## Installation
|
|
46
76
|
|
|
47
77
|
Add this line to your application's Gemfile:
|
|
@@ -70,6 +100,7 @@ Prescient includes a thin CLI for provider inspection and common operations:
|
|
|
70
100
|
prescient providers
|
|
71
101
|
prescient health
|
|
72
102
|
prescient config validate
|
|
103
|
+
prescient config example
|
|
73
104
|
prescient generate "Explain Ruby Ractors"
|
|
74
105
|
prescient embed "Ruby is a programming language"
|
|
75
106
|
```
|
|
@@ -81,6 +112,13 @@ Supported options include:
|
|
|
81
112
|
--model NAME Override the selected operation's model
|
|
82
113
|
--chat-model NAME Override the chat model for generation
|
|
83
114
|
--embedding-model NAME Override the embedding model
|
|
115
|
+
--system-prompt TEXT Override the system prompt
|
|
116
|
+
--no-context-template TEXT
|
|
117
|
+
Override the no-context prompt template
|
|
118
|
+
--with-context-template TEXT
|
|
119
|
+
Override the with-context prompt template
|
|
120
|
+
--prompt-templates-file PATH
|
|
121
|
+
Load prompt templates from a YAML file
|
|
84
122
|
--api-key KEY Use an API key for the operation
|
|
85
123
|
--api-key-env NAME Read the API key from an environment variable
|
|
86
124
|
--format FORMAT Select text or json output
|
|
@@ -96,7 +134,7 @@ printf '%s' "Explain PostgreSQL logical replication" | \
|
|
|
96
134
|
prescient generate --provider openai --format json
|
|
97
135
|
```
|
|
98
136
|
|
|
99
|
-
|
|
137
|
+
OpenAI example JSON output:
|
|
100
138
|
|
|
101
139
|
```json
|
|
102
140
|
{
|
|
@@ -125,6 +163,35 @@ Example JSON output:
|
|
|
125
163
|
}
|
|
126
164
|
```
|
|
127
165
|
|
|
166
|
+
Anthropic example JSON output:
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"response": "PostgreSQL logical replication is a method of replicating data between PostgreSQL databases that allows fine-grained control over which data is replicated and how it is applied. Unlike physical replication, which copies the entire database cluster at the storage level, logical replication works at the level of individual database changes, such as INSERT, UPDATE, and DELETE operations.\n\n### Key Features of PostgreSQL Logical Replication:\n\n1. **Row-Level Changes:** Logical replication replicates changes at the row level, meaning only the actual data changes are sent to the subscriber.\n\n2. **Selective Replication:** You can replicate specific tables rather than the entire database. This allows partial replication tailored to your needs.\n\n3. **Asynchronous Replication:** Logical replication is asynchronous, so there might be a slight delay between the publisher and subscriber.\n\n4. **Bidirectional Replication (with care):** While PostgreSQL does not natively support multi-master replication, logical replication can be configured to allow bidirectional replication setups with caution to avoid conflicts.\n\n5. **Decoupling of Replication:** Logical replication decouples the replication from the physical storage, enabling replication across different PostgreSQL versions (within compatibility limits).\n\n### How Logical Replication Works:\n\n- **Publisher:** The source database that sends changes. It publishes a set of changes based on one or more publications.\n- **Publication:** A set of changes (typically from specific tables) that the publisher makes available to subscribers.\n- **Subscriber:** The target database that receives changes and applies them.\n- **Subscription:** A configuration on the subscriber that connects to a publication and applies changes.\n\n### Use Cases:\n\n- Replicating specific tables or subsets of data.\n- Migrating data between PostgreSQL versions or clusters.\n- Distributing data geographically.\n- Implementing data warehousing or reporting solutions with up-to-date data.\n- Supporting microservices architectures where different services own different parts of the data.\n\n### Basic Setup Example:\n\n1. **On the Publisher:**\n\n```sql\nCREATE PUBLICATION my_publication FOR TABLE my_table;\n```\n\n2. **On the Subscriber:**\n\n```sql\nCREATE SUBSCRIPTION my_subscription\nCONNECTION 'host=publisher_host dbname=mydb user=replicator password=secret'\nPUBLICATION my_publication;\n```\n\nOnce set up, changes to `my_table` on the publisher will be sent and applied to the subscriber.\n\n### Important Notes:\n\n- Logical replication requires WAL (Write-Ahead Logging) to be configured properly with `wal_level = logical`.\n- Some DDL changes (like adding columns) need careful handling as logical replication primarily replicates DML changes.\n- Logical replication does not replicate sequences, large objects, or certain system catalogs automatically.\n- Conflict resolution is mostly manual; the subscriber applies changes as received.\n\n---\n\nIn summary, PostgreSQL logical replication provides a flexible, table-level replication mechanism that supports selective and version-independent replication of data changes, suitable for many modern replication and data distribution scenarios.",
|
|
171
|
+
"model": "gpt-4.1-mini",
|
|
172
|
+
"provider": "openai",
|
|
173
|
+
"processing_time": null,
|
|
174
|
+
"metadata": {
|
|
175
|
+
"usage": {
|
|
176
|
+
"prompt_tokens": 38,
|
|
177
|
+
"completion_tokens": 597,
|
|
178
|
+
"total_tokens": 635,
|
|
179
|
+
"prompt_tokens_details": {
|
|
180
|
+
"cached_tokens": 0,
|
|
181
|
+
"audio_tokens": 0
|
|
182
|
+
},
|
|
183
|
+
"completion_tokens_details": {
|
|
184
|
+
"reasoning_tokens": 0,
|
|
185
|
+
"audio_tokens": 0,
|
|
186
|
+
"accepted_prediction_tokens": 0,
|
|
187
|
+
"rejected_prediction_tokens": 0
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
"finish_reason": "stop"
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
128
195
|
For automated model and credential overrides:
|
|
129
196
|
|
|
130
197
|
```bash
|
|
@@ -146,6 +213,16 @@ The CLI writes results to stdout, diagnostics to stderr, and returns a
|
|
|
146
213
|
non-zero status for invalid usage, provider errors, or unreachable health
|
|
147
214
|
checks. It uses the same `Prescient::Client` execution path as Ruby callers.
|
|
148
215
|
|
|
216
|
+
Generate a schema-backed, annotated starter configuration with:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
prescient config example > prescient.yml
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
The generated file points YAML language servers at the latest schema on the
|
|
223
|
+
main branch. Pin the schema URL to a release tag when reproducible tooling is
|
|
224
|
+
required.
|
|
225
|
+
|
|
149
226
|
## Configuration
|
|
150
227
|
|
|
151
228
|
### Environment Variables
|
|
@@ -169,6 +246,68 @@ OPENAI_CHAT_MODEL=gpt-4.1-mini
|
|
|
169
246
|
HUGGINGFACE_API_KEY=your_api_key
|
|
170
247
|
HUGGINGFACE_EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
|
|
171
248
|
HUGGINGFACE_CHAT_MODEL=google/gemma-2-2b-it
|
|
249
|
+
|
|
250
|
+
# Google Gemini
|
|
251
|
+
GEMINI_API_KEY=your_api_key
|
|
252
|
+
GEMINI_EMBEDDING_MODEL=gemini-embedding-001
|
|
253
|
+
GEMINI_CHAT_MODEL=gemini-2.5-flash
|
|
254
|
+
|
|
255
|
+
# Mistral
|
|
256
|
+
MISTRAL_API_KEY=your_api_key
|
|
257
|
+
MISTRAL_EMBEDDING_MODEL=mistral-embed
|
|
258
|
+
MISTRAL_CHAT_MODEL=mistral-large-latest
|
|
259
|
+
|
|
260
|
+
# DeepSeek
|
|
261
|
+
DEEPSEEK_API_KEY=your_api_key
|
|
262
|
+
DEEPSEEK_CHAT_MODEL=deepseek-v4-flash
|
|
263
|
+
|
|
264
|
+
# xAI
|
|
265
|
+
XAI_API_KEY=your_api_key
|
|
266
|
+
XAI_CHAT_MODEL=grok-4.5
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### YAML Configuration
|
|
270
|
+
|
|
271
|
+
Load a versioned YAML configuration with environment-backed credentials:
|
|
272
|
+
|
|
273
|
+
```yaml
|
|
274
|
+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kanutocd/prescient/refs/heads/main/schema/prescient.configuration.schema.json
|
|
275
|
+
version: 1
|
|
276
|
+
default_provider: openai
|
|
277
|
+
providers:
|
|
278
|
+
openai:
|
|
279
|
+
type: openai
|
|
280
|
+
api_key_env: OPENAI_API_KEY
|
|
281
|
+
embedding_model: text-embedding-3-small
|
|
282
|
+
chat_model: gpt-4.1-mini
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
```ruby
|
|
286
|
+
Prescient.load_configuration('prescient.yml')
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Configuration precedence is CLI overrides, environment defaults and references,
|
|
290
|
+
YAML values, then built-in defaults. Use `prescient config validate` to check a
|
|
291
|
+
configuration before running an operation, or `prescient config example` to
|
|
292
|
+
generate an annotated starter file.
|
|
293
|
+
|
|
294
|
+
Prompt templates can also be configured per provider. Use the YAML mapping for
|
|
295
|
+
multiline templates, or pass a template file to a single CLI operation:
|
|
296
|
+
|
|
297
|
+
```yaml
|
|
298
|
+
providers:
|
|
299
|
+
openai:
|
|
300
|
+
type: openai
|
|
301
|
+
api_key_env: OPENAI_API_KEY
|
|
302
|
+
chat_model: gpt-4.1-mini
|
|
303
|
+
prompt_templates:
|
|
304
|
+
system_prompt: You are a concise assistant.
|
|
305
|
+
no_context_template: "%{system_prompt}\n\nUser: %{query}"
|
|
306
|
+
with_context_template: "%{system_prompt}\n\nContext:\n%{context}\n\nUser: %{query}"
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
prescient generate --prompt-templates-file prompts.yml "Summarize this"
|
|
172
311
|
```
|
|
173
312
|
|
|
174
313
|
### Programmatic Configuration
|
|
@@ -202,6 +341,32 @@ Prescient.configure do |config|
|
|
|
202
341
|
embedding_model: 'text-embedding-3-small',
|
|
203
342
|
chat_model: 'gpt-4.1-mini'
|
|
204
343
|
)
|
|
344
|
+
|
|
345
|
+
# Add Google Gemini
|
|
346
|
+
config.add_provider(:gemini, Prescient::Provider::Gemini,
|
|
347
|
+
api_key: ENV['GEMINI_API_KEY'],
|
|
348
|
+
embedding_model: 'gemini-embedding-001',
|
|
349
|
+
chat_model: 'gemini-2.5-flash'
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
# Add Mistral
|
|
353
|
+
config.add_provider(:mistral, Prescient::Provider::Mistral,
|
|
354
|
+
api_key: ENV['MISTRAL_API_KEY'],
|
|
355
|
+
embedding_model: 'mistral-embed',
|
|
356
|
+
chat_model: 'mistral-large-latest'
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
# Add DeepSeek
|
|
360
|
+
config.add_provider(:deepseek, Prescient::Provider::DeepSeek,
|
|
361
|
+
api_key: ENV['DEEPSEEK_API_KEY'],
|
|
362
|
+
chat_model: 'deepseek-v4-flash'
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
# Add xAI
|
|
366
|
+
config.add_provider(:xai, Prescient::Provider::XAI,
|
|
367
|
+
api_key: ENV['XAI_API_KEY'],
|
|
368
|
+
chat_model: 'grok-4.5'
|
|
369
|
+
)
|
|
205
370
|
end
|
|
206
371
|
```
|
|
207
372
|
|
|
@@ -357,14 +522,14 @@ Prescient.configure do |config|
|
|
|
357
522
|
prompt_templates: {
|
|
358
523
|
system_prompt: 'You are a friendly customer service representative.',
|
|
359
524
|
no_context_template: <<~TEMPLATE.strip,
|
|
360
|
-
%{
|
|
525
|
+
%{system_prompt}
|
|
361
526
|
|
|
362
527
|
Customer Question: %{query}
|
|
363
528
|
|
|
364
529
|
Please provide a helpful response.
|
|
365
530
|
TEMPLATE
|
|
366
531
|
with_context_template: <<~TEMPLATE.strip
|
|
367
|
-
%{
|
|
532
|
+
%{system_prompt} Use the company info below to help answer.
|
|
368
533
|
|
|
369
534
|
Company Information:
|
|
370
535
|
%{context}
|
|
@@ -534,8 +699,9 @@ results = store.search(embedding:, provider: :openai, model: 'text-embedding-3-s
|
|
|
534
699
|
```
|
|
535
700
|
|
|
536
701
|
Every vector must exactly match the store's configured dimensions; Prescient
|
|
537
|
-
never pads or truncates vectors. The
|
|
538
|
-
|
|
702
|
+
never pads or truncates vectors. The application-schema example below is
|
|
703
|
+
optional integration material for projects that need documents, chunks, and
|
|
704
|
+
custom metadata; it is not managed by `Prescient::Pgvector::Store`.
|
|
539
705
|
|
|
540
706
|
### Setup with Docker
|
|
541
707
|
|
|
@@ -554,7 +720,7 @@ docker compose up -d postgres
|
|
|
554
720
|
|
|
555
721
|
### Database Schema
|
|
556
722
|
|
|
557
|
-
The
|
|
723
|
+
The optional Docker demo creates these application-owned tables:
|
|
558
724
|
|
|
559
725
|
- **`documents`** - Store original content and metadata
|
|
560
726
|
- **`document_embeddings`** - Store vector embeddings for documents
|
|
@@ -736,10 +902,9 @@ DB_HOST=localhost ruby examples/vector_search.rb
|
|
|
736
902
|
|
|
737
903
|
The example demonstrates:
|
|
738
904
|
|
|
739
|
-
-
|
|
740
|
-
-
|
|
741
|
-
-
|
|
742
|
-
- Performance comparison between approaches
|
|
905
|
+
- Embedding generation through `Prescient::Client`
|
|
906
|
+
- Dimension-validated storage through `Prescient::Pgvector::Store`
|
|
907
|
+
- Similarity search with provider and model filters
|
|
743
908
|
|
|
744
909
|
## Advanced Usage
|
|
745
910
|
|
data/Rakefile
CHANGED
data/VECTOR_SEARCH_GUIDE.md
CHANGED
|
@@ -27,6 +27,10 @@ store.create_index!(metric: :cosine)
|
|
|
27
27
|
or chunk tables, connections, migrations outside that table, or the `pg` gem.
|
|
28
28
|
Use `#upsert` and `#search` with embeddings of exactly the configured dimension.
|
|
29
29
|
|
|
30
|
+
The remaining sections describe an optional application-owned document schema
|
|
31
|
+
used by the repository's Docker demo. They are not tables created or managed
|
|
32
|
+
by `Prescient::Pgvector::Store`.
|
|
33
|
+
|
|
30
34
|
### 1. Start Services
|
|
31
35
|
|
|
32
36
|
```bash
|
|
@@ -55,12 +59,12 @@ export DB_HOST=localhost
|
|
|
55
59
|
export OLLAMA_URL=http://localhost:11434
|
|
56
60
|
|
|
57
61
|
# Run the example
|
|
58
|
-
ruby examples/vector_search.rb
|
|
62
|
+
bundle exec ruby examples/vector_search.rb
|
|
59
63
|
```
|
|
60
64
|
|
|
61
65
|
## Architecture Overview
|
|
62
66
|
|
|
63
|
-
###
|
|
67
|
+
### Application-Owned Example Schema
|
|
64
68
|
|
|
65
69
|
```
|
|
66
70
|
documents
|
|
@@ -103,7 +107,7 @@ chunk_embeddings
|
|
|
103
107
|
|
|
104
108
|
### Vector Indexes
|
|
105
109
|
|
|
106
|
-
The
|
|
110
|
+
The optional Docker demo creates HNSW indexes for the application-owned tables:
|
|
107
111
|
|
|
108
112
|
- **Cosine Distance**: `embedding <=> query_vector`
|
|
109
113
|
- **L2 Distance**: `embedding <-> query_vector`
|
data/examples/README.md
CHANGED
|
@@ -15,7 +15,8 @@ bundle install
|
|
|
15
15
|
- `custom_prompts.rb` — system prompts and no-context/with-context templates.
|
|
16
16
|
- `custom_contexts.rb` — explicit context types, field matching, formatting,
|
|
17
17
|
and embedding field selection.
|
|
18
|
-
- `vector_search.rb` — PostgreSQL/pgvector storage
|
|
18
|
+
- `vector_search.rb` — `Prescient::Pgvector::Store` PostgreSQL/pgvector storage
|
|
19
|
+
and similarity search.
|
|
19
20
|
|
|
20
21
|
The first three examples use Ollama by default. Start Ollama and pull the
|
|
21
22
|
current local models before running them:
|
data/examples/basic_usage.rb
CHANGED
|
@@ -67,7 +67,7 @@ end
|
|
|
67
67
|
# Example 3: Provider comparison (if multiple providers configured)
|
|
68
68
|
puts "\n=== Example 3: Provider Health Check ==="
|
|
69
69
|
|
|
70
|
-
providers = [
|
|
70
|
+
providers = %i[ollama anthropic openai huggingface gemini mistral deepseek xai]
|
|
71
71
|
|
|
72
72
|
providers.each do |provider_name|
|
|
73
73
|
begin
|
data/examples/custom_contexts.rb
CHANGED
|
@@ -228,8 +228,8 @@ rescue Prescient::Error => e
|
|
|
228
228
|
puts "❌ Error: #{e.message}"
|
|
229
229
|
end
|
|
230
230
|
|
|
231
|
-
# Example 4: Embedding Text
|
|
232
|
-
puts "\n--- Example 4: Embedding Text
|
|
231
|
+
# Example 4: Embedding Text Selection
|
|
232
|
+
puts "\n--- Example 4: Embedding Text Selection ---"
|
|
233
233
|
|
|
234
234
|
begin
|
|
235
235
|
# Configure a provider with context configs
|
|
@@ -251,7 +251,7 @@ begin
|
|
|
251
251
|
client = Prescient.client(:embedding_demo)
|
|
252
252
|
|
|
253
253
|
if client.available?
|
|
254
|
-
#
|
|
254
|
+
# The configured embedding_fields select title, content, and tags.
|
|
255
255
|
blog_post = {
|
|
256
256
|
'type' => 'blog_post',
|
|
257
257
|
'title' => 'Getting Started with AI',
|
|
@@ -262,12 +262,10 @@ begin
|
|
|
262
262
|
'publish_date' => '2024-01-15'
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
embedding_text = client.provider.send(:extract_embedding_text, blog_post)
|
|
268
|
-
puts "📊 Embedding Text Extracted:"
|
|
265
|
+
embedding_text = [blog_post['title'], blog_post['content'], blog_post['tags']].join(' ')
|
|
266
|
+
puts "📊 Embedding Text Selected:"
|
|
269
267
|
puts "\"#{embedding_text}\""
|
|
270
|
-
puts "\n(
|
|
268
|
+
puts "\n(Only title, content, and tags are included in the embedding input)"
|
|
271
269
|
|
|
272
270
|
# Generate actual embedding
|
|
273
271
|
puts "\n🔢 Generating embedding..."
|
|
@@ -317,19 +315,6 @@ begin
|
|
|
317
315
|
puts "🔧 Raw data (no context config):"
|
|
318
316
|
random_data.each { |item| puts " #{item}" }
|
|
319
317
|
|
|
320
|
-
puts "\n📄 How items are formatted without context config:"
|
|
321
|
-
random_data.each do |item|
|
|
322
|
-
formatted = client.provider.send(:format_context_item, item)
|
|
323
|
-
puts " #{formatted}"
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
puts "\n🔤 Embedding text extraction (automatic field filtering):"
|
|
327
|
-
random_data.each do |item|
|
|
328
|
-
embedding_text = client.provider.send(:extract_embedding_text, item)
|
|
329
|
-
puts " \"#{embedding_text}\""
|
|
330
|
-
puts " (Notice: excludes 'created_at', 'timestamp' - common metadata fields)"
|
|
331
|
-
end
|
|
332
|
-
|
|
333
318
|
response = client.generate_response("Summarize the key issues", random_data)
|
|
334
319
|
puts "\n🤖 AI Response (using default formatting):"
|
|
335
320
|
puts response[:response]
|