Skip to content

Commit e8c05eb

Browse files
fix(lib): corregge context size Ollama e credentials fetch per autenticazione
1 parent 25fec0b commit e8c05eb

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Fixed
11+
- Frontend API calls now include credentials for proper session authentication
12+
- Ollama context size reduced from 8192 to 2048 to match nomic-embed-text model limit
13+
1014
## [1.1.2] - 2025-12-02
1115

1216
### Changed

frontend/static/app.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function ragifyApp() {
6464
// Collections
6565
async loadCollections() {
6666
try {
67-
const res = await fetch('/api/collections');
67+
const res = await fetch('/api/collections', { credentials: 'include' });
6868
const data = await res.json();
6969
console.log('API response:', data);
7070
this.collections = data.collections || [];
@@ -99,7 +99,8 @@ function ragifyApp() {
9999
const res = await fetch('/api/collections', {
100100
method: 'POST',
101101
headers: { 'Content-Type': 'application/json' },
102-
body: JSON.stringify({ name: this.newCollectionName })
102+
body: JSON.stringify({ name: this.newCollectionName }),
103+
credentials: 'include'
103104
});
104105

105106
if (res.ok) {
@@ -120,7 +121,7 @@ function ragifyApp() {
120121
if (!confirm(`Delete collection "${name}"? This cannot be undone.`)) return;
121122

122123
try {
123-
const res = await fetch(`/api/collections/${name}`, { method: 'DELETE' });
124+
const res = await fetch(`/api/collections/${name}`, { method: 'DELETE', credentials: 'include' });
124125
if (res.ok) {
125126
this.showToast('Collection deleted', 'success');
126127
await this.loadCollections();
@@ -146,7 +147,7 @@ function ragifyApp() {
146147
// Jobs
147148
async loadJobs() {
148149
try {
149-
const res = await fetch('/api/jobs?limit=10');
150+
const res = await fetch('/api/jobs?limit=10', { credentials: 'include' });
150151
const data = await res.json();
151152
this.jobs = data.jobs || [];
152153
} catch (e) {
@@ -189,7 +190,8 @@ function ragifyApp() {
189190

190191
const res = await fetch('/api/upload', {
191192
method: 'POST',
192-
body: formData
193+
body: formData,
194+
credentials: 'include'
193195
});
194196

195197
if (res.ok) {
@@ -222,7 +224,8 @@ function ragifyApp() {
222224
query: this.searchQuery,
223225
collection: this.searchCollection,
224226
limit: 10
225-
})
227+
}),
228+
credentials: 'include'
226229
});
227230

228231
if (res.ok) {

lib/chunking.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ def _fallback_chunk(
212212
return final_chunks
213213

214214

215-
def validate_chunk_size(chunk_text: str, max_tokens: int = 8192) -> bool:
215+
def validate_chunk_size(chunk_text: str, max_tokens: int = 2048) -> bool:
216216
"""
217217
Validate that chunk doesn't exceed embedding model's token limit.
218-
218+
219219
Args:
220220
chunk_text: Chunk text to validate
221-
max_tokens: Maximum allowed tokens (nomic-embed-text: 8192)
221+
max_tokens: Maximum allowed tokens (nomic-embed-text: 2048)
222222
223223
Returns:
224224
True if chunk is within limits
@@ -232,7 +232,7 @@ def create_chunks(
232232
chunk_size: int = 500,
233233
chunk_overlap: int = 50,
234234
min_tokens: int = 0,
235-
max_tokens: int = 8192
235+
max_tokens: int = 2048
236236
) -> list[dict]:
237237
"""
238238
Create chunks from text using two-level semantic chunking (chonkie + semchunk).
@@ -247,7 +247,7 @@ def create_chunks(
247247
chunk_size: Target chunk size in tokens (default: 500)
248248
chunk_overlap: Overlap between chunks in tokens (default: 50)
249249
min_tokens: Minimum chunk size to keep (default: 50)
250-
max_tokens: Maximum chunk size before re-chunking (default: 8192)
250+
max_tokens: Maximum chunk size before re-chunking (default: 2048)
251251
252252
Returns:
253253
List of chunk dictionaries with text and metadata

lib/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ChunkingConfig(BaseModel):
3939
strategies: ChunkingStrategyConfig = Field(default_factory=ChunkingStrategyConfig)
4040
chunk_size: int = Field(default=512, description="Target chunk size in tokens")
4141
overlap: int = Field(default=50, description="Overlap between chunks in tokens")
42-
max_tokens: int = Field(default=8192, description="Maximum tokens per chunk")
42+
max_tokens: int = Field(default=2048, description="Maximum tokens per chunk (nomic-embed-text limit)")
4343

4444

4545
class EmbeddingConfig(BaseModel):
@@ -266,7 +266,7 @@ def merge_cli_args(config: RagifyConfig, args: dict) -> RagifyConfig:
266266
default: semantic
267267
chunk_size: 512
268268
overlap: 50
269-
max_tokens: 8192
269+
max_tokens: 2048
270270
271271
embedding:
272272
provider: ollama

lib/embedding.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Configuration
1717
OLLAMA_URL = os.getenv('OLLAMA_URL', 'http://localhost:11434')
1818
EMBEDDING_MODEL = "nomic-embed-text"
19-
MAX_TOKENS = 8192 # nomic-embed-text limit
19+
MAX_TOKENS = 2048 # nomic-embed-text context limit
2020

2121

2222
def get_embedding(text: str, timeout: int = 60, max_retries: int = 3) -> Optional[list[float]]:
@@ -46,7 +46,8 @@ def get_embedding(text: str, timeout: int = 60, max_retries: int = 3) -> Optiona
4646
f"{OLLAMA_URL}/api/embeddings",
4747
json={
4848
"model": EMBEDDING_MODEL,
49-
"prompt": text
49+
"prompt": text,
50+
"options": {"num_ctx": MAX_TOKENS}
5051
},
5152
timeout=timeout
5253
)

0 commit comments

Comments
 (0)