Skip to content

Commit cb36f62

Browse files
Merge branch 'dev' of https://github.com/OpenLLM-France/RAGondin into dev
2 parents 26f61d6 + 13dbd5e commit cb36f62

File tree

12 files changed

+123
-120
lines changed

12 files changed

+123
-120
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ RETRIEVER_TOP_K=5
2929

3030

3131
# EMBEDDER
32-
EMBEDDER_MODEL=HIT-TMG/KaLM-embedding-multilingual-mini-v1
32+
EMBEDDER_MODEL=jinaai/jina-embeddings-v3
3333

3434
# RERANKER
3535
RERANKER_MODEL=jinaai/jina-colbert-v2

.hydra_config/chunker/recursive_splitter.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
defaults:
22
- base
33
name: recursive_splitter
4-
chunk_size: 1500
5-
chunk_overlap: 300
4+
chunk_size: 1000
5+
chunk_overlap: 200
66

77

88
# https://chat.deepseek.com/a/chat/s/28913c5d-1f62-40b0-9247-4655994fe16b

.hydra_config/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ semaphore:
2828

2929
embedder:
3030
type: huggingface
31-
model_name: ${oc.env:EMBEDDER_MODEL_NAME, HIT-TMG/KaLM-embedding-multilingual-mini-v1}
31+
model_name: ${oc.env:EMBEDDER_MODEL_NAME, jinaai/jina-embeddings-v3}
3232

3333
vectordb:
3434
host: ${oc.env:VDB_HOST, milvus}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ chunk_overlap: 300
3434
Here, the **`chunk_size`** and **`chunk_overlap`** are measured in tokens rather than characters. For improved retrieval performance, you can enable the contextual retrieval feature. This technique, known as "Contextual Retrieval," was introduced by Anthropic to enhance retrieval quality (see [Contextual Retrieval](https://www.anthropic.com/news/contextual-retrieval) for more details). To activate this feature, set **`CONTEXT_RETRIEVAL=true`** in your **`.env`** file. Refer to the **`Usage`** section for additional instructions.
3535

3636
- **Indexing & Search**
37-
After chunking, the data is indexed in the **Milvus** vector database using the multilingual embedding model `HIT-TMG/KaLM-embedding-multilingual-mini-v1`, which performs well on the [MTEB benchmark](https://huggingface.co/spaces/mteb/leaderboard). Developers can customize the embedding model by setting the **`EMBEDDER_MODEL`** variable in the *`.env`* file to any compatible model from Huggingface, such as `"sentence-transformers/all-MiniLM-L6-v2"` for faster processing.
37+
After chunking, the data is indexed in the **Milvus** vector database using the multilingual embedding model `jinaai/jina-embeddings-v3`, which performs well on the [MTEB benchmark](https://huggingface.co/spaces/mteb/leaderboard). Developers can customize the embedding model by setting the **`EMBEDDER_MODEL`** variable in the *`.env`* file to any compatible model from Huggingface, such as `"sentence-transformers/all-MiniLM-L6-v2"` for faster processing.
3838

3939
**Note**: When selecting an embedding model, consider the language of your documents and the model's context length (token limit). The default model supports both French and English. The same model is also used to embed user queries for semantic (dense) search.
4040

converter_tests.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

ragondin/chainlit/app_front.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def on_chat_start():
6666
chat_profile = cl.user_session.get("chat_profile")
6767
settings = {
6868
"model": chat_profile,
69-
"temperature": 0,
69+
"temperature": 0.1,
7070
"stream": True,
7171
}
7272

@@ -97,6 +97,9 @@ async def __fetch_page_content(chunk_url):
9797

9898

9999
async def __format_sources(metadata_sources, only_txt=False):
100+
if not metadata_sources:
101+
return None, None
102+
100103
elements = []
101104
source_names = []
102105
for s in metadata_sources:
@@ -153,12 +156,16 @@ async def on_message(message: cl.Message):
153156
headers=headers,
154157
json=payload,
155158
) as resp:
156-
metadata_sources = json.loads(resp.headers.get("X-Metadata-Sources"))
157-
if metadata_sources:
158-
elements, source_names = await __format_sources(metadata_sources)
159-
msg = cl.Message(content="", elements=elements)
160-
else:
161-
msg = cl.Message(content="")
159+
try:
160+
metadata = resp.headers.get("X-Metadata-Sources")
161+
logger.debug(f"Metadata: {metadata}")
162+
metadata_sources = json.loads(metadata)
163+
except Exception as e:
164+
metadata_sources = None
165+
pass
166+
167+
elements, source_names = await __format_sources(metadata_sources)
168+
msg = cl.Message(content="", elements=elements)
162169

163170
# STREAM Response
164171
await msg.send()
@@ -188,9 +195,10 @@ async def on_message(message: cl.Message):
188195
cl.user_session.set("messages", messages)
189196

190197
# Show sources
191-
s = "\n\n" + "-" * 50 + "\n\nSources: \n" + "\n".join(source_names)
192-
await msg.stream_token(s)
193-
await msg.update()
198+
if source_names:
199+
s = "\n\n" + "-" * 50 + "\n\nSources: \n" + "\n".join(source_names)
200+
await msg.stream_token(s)
201+
await msg.update()
194202

195203

196204
if __name__ == "__main__":

ragondin/models/openai.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class OpenAIChatCompletionRequest(BaseModel):
1919
temperature: Optional[float] = Field(0.3)
2020
top_p: Optional[float] = Field(1.0)
2121
stream: Optional[bool] = Field(False)
22-
max_tokens: Optional[int] = Field(500)
22+
max_tokens: Optional[int] = Field(1024)
2323
logprobs: Optional[int] = Field(None)
2424

2525

@@ -75,7 +75,7 @@ class OpenAICompletionRequest(BaseModel):
7575
frequency_penalty: Optional[float] = Field(0.0)
7676
logit_bias: Optional[dict] = Field(None)
7777
logprobs: Optional[int] = Field(None)
78-
max_tokens: Optional[int] = Field(100)
78+
max_tokens: Optional[int] = Field(512)
7979
n: Optional[int] = Field(1)
8080
presence_penalty: Optional[float] = Field(0.0)
8181
seed: Optional[int] = Field(None)

ragondin/routers/extract.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
from typing import List, Optional
2-
31
from fastapi import APIRouter, Depends, HTTPException, Query, Request, status
42
from fastapi.responses import JSONResponse
53
from utils.dependencies import Indexer, get_indexer, vectordb
4+
from loguru import logger
65

76
# Create an APIRouter instance
87
router = APIRouter()
98

9+
1010
@router.get("/{extract_id}")
1111
async def get_extract(extract_id: str, indexer: Indexer = Depends(get_indexer)):
1212
try:
1313
doc = vectordb.get_chunk_by_id(extract_id)
1414
if doc is None:
1515
raise HTTPException(
1616
status_code=status.HTTP_404_NOT_FOUND,
17-
detail=f"Extract '{extract_id}' not found."
17+
detail=f"Extract '{extract_id}' not found.",
1818
)
1919
except Exception as e:
20+
err_str = f"Failed to retrieve extract: {str(e)}"
21+
logger.debug(err_str)
2022
raise HTTPException(
21-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
22-
detail=f"Failed to retrieve extract: {str(e)}"
23+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=err_str
2324
)
2425

2526
return JSONResponse(
2627
status_code=status.HTTP_200_OK,
27-
content={
28-
"page_content": doc.page_content,
29-
"metadata": doc.metadata
30-
}
31-
)
28+
content={"page_content": doc.page_content, "metadata": doc.metadata},
29+
)

ragondin/routers/indexer.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from loguru import logger
2121
from ray.util.state import get_task
2222
from utils.dependencies import Indexer, get_indexer, vectordb
23+
from loguru import logger
2324

2425
# load config
2526
config = load_config()
@@ -106,9 +107,11 @@ async def add_file(
106107
with open(file_path, "wb") as buffer:
107108
buffer.write(await file.read())
108109
except Exception as e:
110+
err_str = f"Failed to save file: {str(e)}"
111+
logger.debug(err_str)
109112
raise HTTPException(
110113
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
111-
detail=f"Failed to save file: {str(e)}",
114+
detail=err_str,
112115
)
113116

114117
# Queue the file for indexing
@@ -118,9 +121,11 @@ async def add_file(
118121
)
119122
# TODO: More specific errors with details and appropriate error codes
120123
except Exception as e:
124+
err_str = f"Indexing error: {str(e)}"
125+
logger.debug(err_str)
121126
raise HTTPException(
122127
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
123-
detail=f"Indexing error: {str(e)}",
128+
detail=err_str,
124129
)
125130

126131
return JSONResponse(
@@ -143,9 +148,11 @@ async def delete_file(
143148
try:
144149
deleted = ray.get(indexer.delete_file.remote(file_id, partition))
145150
except Exception as e:
151+
err_str = f"Error while deleting file '{file_id}': {str(e)}"
152+
logger.debug(err_str)
146153
raise HTTPException(
147154
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
148-
detail=f"Error while deleting file '{file_id}': {str(e)}",
155+
detail=err_str,
149156
)
150157

151158
if not deleted:
@@ -178,9 +185,11 @@ async def put_file(
178185
ray.get(indexer.delete_file.remote(file_id, partition))
179186
logger.info(f"File {file_id} deleted.")
180187
except Exception as e:
188+
err_str = f"Failed to delete existing file: {str(e)}"
189+
logger.debug(err_str)
181190
raise HTTPException(
182191
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
183-
detail=f"Failed to delete existing file: {str(e)}",
192+
detail=err_str,
184193
)
185194

186195
metadata["file_id"] = file_id
@@ -195,9 +204,11 @@ async def put_file(
195204
with open(file_path, "wb") as buffer:
196205
buffer.write(await file.read())
197206
except Exception as e:
207+
err_str = f"Failed to save file: {str(e)}"
208+
logger.debug(err_str)
198209
raise HTTPException(
199210
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
200-
detail=f"Failed to save file: {str(e)}",
211+
detail=err_str,
201212
)
202213

203214
# Queue indexing task
@@ -206,9 +217,11 @@ async def put_file(
206217
path=file_path, metadata=metadata, partition=partition
207218
)
208219
except Exception as e:
220+
err_str = f"Indexing error: {str(e)}"
221+
logger.debug(err_str)
209222
raise HTTPException(
210223
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
211-
detail=f"Indexing error: {str(e)}",
224+
detail=err_str,
212225
)
213226

214227
return JSONResponse(
@@ -241,9 +254,11 @@ async def patch_file(
241254
try:
242255
ray.get(indexer.update_file_metadata.remote(file_id, metadata, partition))
243256
except Exception as e:
257+
err_str = f"Failed to update metadata: {str(e)}"
258+
logger.debug(err_str)
244259
raise HTTPException(
245260
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
246-
detail=f"Failed to update metadata: {str(e)}",
261+
detail=err_str,
247262
)
248263

249264
return JSONResponse(

0 commit comments

Comments
 (0)