Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
cebf733b
Commit
cebf733b
authored
Apr 26, 2024
by
Timothy J. Baek
Browse files
refac: naming convention
parent
69822e4c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
16 deletions
+28
-16
backend/apps/rag/main.py
backend/apps/rag/main.py
+16
-7
backend/apps/rag/utils.py
backend/apps/rag/utils.py
+7
-7
backend/config.py
backend/config.py
+4
-1
backend/main.py
backend/main.py
+1
-1
No files found.
backend/apps/rag/main.py
View file @
cebf733b
...
@@ -70,7 +70,7 @@ from config import (
...
@@ -70,7 +70,7 @@ from config import (
RAG_EMBEDDING_MODEL
,
RAG_EMBEDDING_MODEL
,
RAG_EMBEDDING_MODEL_AUTO_UPDATE
,
RAG_EMBEDDING_MODEL_AUTO_UPDATE
,
RAG_EMBEDDING_MODEL_TRUST_REMOTE_CODE
,
RAG_EMBEDDING_MODEL_TRUST_REMOTE_CODE
,
RAG_HYBRID
,
ENABLE_
RAG_HYBRID
_SEARCH
,
RAG_RERANKING_MODEL
,
RAG_RERANKING_MODEL
,
RAG_RERANKING_MODEL_AUTO_UPDATE
,
RAG_RERANKING_MODEL_AUTO_UPDATE
,
RAG_RERANKING_MODEL_TRUST_REMOTE_CODE
,
RAG_RERANKING_MODEL_TRUST_REMOTE_CODE
,
...
@@ -92,7 +92,8 @@ app = FastAPI()
...
@@ -92,7 +92,8 @@ app = FastAPI()
app
.
state
.
TOP_K
=
RAG_TOP_K
app
.
state
.
TOP_K
=
RAG_TOP_K
app
.
state
.
RELEVANCE_THRESHOLD
=
RAG_RELEVANCE_THRESHOLD
app
.
state
.
RELEVANCE_THRESHOLD
=
RAG_RELEVANCE_THRESHOLD
app
.
state
.
HYBRID
=
RAG_HYBRID
app
.
state
.
ENABLE_RAG_HYBRID_SEARCH
=
ENABLE_RAG_HYBRID_SEARCH
app
.
state
.
CHUNK_SIZE
=
CHUNK_SIZE
app
.
state
.
CHUNK_SIZE
=
CHUNK_SIZE
app
.
state
.
CHUNK_OVERLAP
=
CHUNK_OVERLAP
app
.
state
.
CHUNK_OVERLAP
=
CHUNK_OVERLAP
...
@@ -324,7 +325,7 @@ async def get_query_settings(user=Depends(get_admin_user)):
...
@@ -324,7 +325,7 @@ async def get_query_settings(user=Depends(get_admin_user)):
"template"
:
app
.
state
.
RAG_TEMPLATE
,
"template"
:
app
.
state
.
RAG_TEMPLATE
,
"k"
:
app
.
state
.
TOP_K
,
"k"
:
app
.
state
.
TOP_K
,
"r"
:
app
.
state
.
RELEVANCE_THRESHOLD
,
"r"
:
app
.
state
.
RELEVANCE_THRESHOLD
,
"hybrid"
:
app
.
state
.
HYBRID
,
"hybrid"
:
app
.
state
.
ENABLE_RAG_HYBRID_SEARCH
,
}
}
...
@@ -342,13 +343,13 @@ async def update_query_settings(
...
@@ -342,13 +343,13 @@ async def update_query_settings(
app
.
state
.
RAG_TEMPLATE
=
form_data
.
template
if
form_data
.
template
else
RAG_TEMPLATE
app
.
state
.
RAG_TEMPLATE
=
form_data
.
template
if
form_data
.
template
else
RAG_TEMPLATE
app
.
state
.
TOP_K
=
form_data
.
k
if
form_data
.
k
else
4
app
.
state
.
TOP_K
=
form_data
.
k
if
form_data
.
k
else
4
app
.
state
.
RELEVANCE_THRESHOLD
=
form_data
.
r
if
form_data
.
r
else
0.0
app
.
state
.
RELEVANCE_THRESHOLD
=
form_data
.
r
if
form_data
.
r
else
0.0
app
.
state
.
HYBRID
=
form_data
.
hybrid
if
form_data
.
hybrid
else
False
app
.
state
.
ENABLE_RAG_HYBRID_SEARCH
=
form_data
.
hybrid
if
form_data
.
hybrid
else
False
return
{
return
{
"status"
:
True
,
"status"
:
True
,
"template"
:
app
.
state
.
RAG_TEMPLATE
,
"template"
:
app
.
state
.
RAG_TEMPLATE
,
"k"
:
app
.
state
.
TOP_K
,
"k"
:
app
.
state
.
TOP_K
,
"r"
:
app
.
state
.
RELEVANCE_THRESHOLD
,
"r"
:
app
.
state
.
RELEVANCE_THRESHOLD
,
"hybrid"
:
app
.
state
.
HYBRID
,
"hybrid"
:
app
.
state
.
ENABLE_RAG_HYBRID_SEARCH
,
}
}
...
@@ -381,7 +382,11 @@ def query_doc_handler(
...
@@ -381,7 +382,11 @@ def query_doc_handler(
r
=
form_data
.
r
if
form_data
.
r
else
app
.
state
.
RELEVANCE_THRESHOLD
,
r
=
form_data
.
r
if
form_data
.
r
else
app
.
state
.
RELEVANCE_THRESHOLD
,
embeddings_function
=
embeddings_function
,
embeddings_function
=
embeddings_function
,
reranking_function
=
app
.
state
.
sentence_transformer_rf
,
reranking_function
=
app
.
state
.
sentence_transformer_rf
,
hybrid
=
form_data
.
hybrid
if
form_data
.
hybrid
else
app
.
state
.
HYBRID
,
hybrid_search
=
(
form_data
.
hybrid
if
form_data
.
hybrid
else
app
.
state
.
ENABLE_RAG_HYBRID_SEARCH
),
)
)
except
Exception
as
e
:
except
Exception
as
e
:
log
.
exception
(
e
)
log
.
exception
(
e
)
...
@@ -420,7 +425,11 @@ def query_collection_handler(
...
@@ -420,7 +425,11 @@ def query_collection_handler(
r
=
form_data
.
r
if
form_data
.
r
else
app
.
state
.
RELEVANCE_THRESHOLD
,
r
=
form_data
.
r
if
form_data
.
r
else
app
.
state
.
RELEVANCE_THRESHOLD
,
embeddings_function
=
embeddings_function
,
embeddings_function
=
embeddings_function
,
reranking_function
=
app
.
state
.
sentence_transformer_rf
,
reranking_function
=
app
.
state
.
sentence_transformer_rf
,
hybrid
=
form_data
.
hybrid
if
form_data
.
hybrid
else
app
.
state
.
HYBRID
,
hybrid_search
=
(
form_data
.
hybrid
if
form_data
.
hybrid
else
app
.
state
.
ENABLE_RAG_HYBRID_SEARCH
),
)
)
except
Exception
as
e
:
except
Exception
as
e
:
log
.
exception
(
e
)
log
.
exception
(
e
)
...
...
backend/apps/rag/utils.py
View file @
cebf733b
...
@@ -33,12 +33,12 @@ def query_embeddings_doc(
...
@@ -33,12 +33,12 @@ def query_embeddings_doc(
reranking_function
,
reranking_function
,
k
:
int
,
k
:
int
,
r
:
int
,
r
:
int
,
hybrid
:
bool
,
hybrid
_search
:
bool
,
):
):
try
:
try
:
collection
=
CHROMA_CLIENT
.
get_collection
(
name
=
collection_name
)
collection
=
CHROMA_CLIENT
.
get_collection
(
name
=
collection_name
)
if
hybrid
:
if
hybrid
_search
:
documents
=
collection
.
get
()
# get all documents
documents
=
collection
.
get
()
# get all documents
bm25_retriever
=
BM25Retriever
.
from_texts
(
bm25_retriever
=
BM25Retriever
.
from_texts
(
texts
=
documents
.
get
(
"documents"
),
texts
=
documents
.
get
(
"documents"
),
...
@@ -134,7 +134,7 @@ def query_embeddings_collection(
...
@@ -134,7 +134,7 @@ def query_embeddings_collection(
r
:
float
,
r
:
float
,
embeddings_function
,
embeddings_function
,
reranking_function
,
reranking_function
,
hybrid
:
bool
,
hybrid
_search
:
bool
,
):
):
results
=
[]
results
=
[]
...
@@ -148,7 +148,7 @@ def query_embeddings_collection(
...
@@ -148,7 +148,7 @@ def query_embeddings_collection(
r
=
r
,
r
=
r
,
embeddings_function
=
embeddings_function
,
embeddings_function
=
embeddings_function
,
reranking_function
=
reranking_function
,
reranking_function
=
reranking_function
,
hybrid
=
hybrid
,
hybrid
_search
=
hybrid_search
,
)
)
results
.
append
(
result
)
results
.
append
(
result
)
except
:
except
:
...
@@ -206,7 +206,7 @@ def rag_messages(
...
@@ -206,7 +206,7 @@ def rag_messages(
template
,
template
,
k
,
k
,
r
,
r
,
hybrid
,
hybrid
_search
,
embedding_engine
,
embedding_engine
,
embedding_model
,
embedding_model
,
embedding_function
,
embedding_function
,
...
@@ -279,7 +279,7 @@ def rag_messages(
...
@@ -279,7 +279,7 @@ def rag_messages(
r
=
r
,
r
=
r
,
embeddings_function
=
embeddings_function
,
embeddings_function
=
embeddings_function
,
reranking_function
=
reranking_function
,
reranking_function
=
reranking_function
,
hybrid
=
hybrid
,
hybrid
_search
=
hybrid_search
,
)
)
else
:
else
:
context
=
query_embeddings_doc
(
context
=
query_embeddings_doc
(
...
@@ -289,7 +289,7 @@ def rag_messages(
...
@@ -289,7 +289,7 @@ def rag_messages(
r
=
r
,
r
=
r
,
embeddings_function
=
embeddings_function
,
embeddings_function
=
embeddings_function
,
reranking_function
=
reranking_function
,
reranking_function
=
reranking_function
,
hybrid
=
hybrid
,
hybrid
_search
=
hybrid_search
,
)
)
except
Exception
as
e
:
except
Exception
as
e
:
log
.
exception
(
e
)
log
.
exception
(
e
)
...
...
backend/config.py
View file @
cebf733b
...
@@ -422,7 +422,10 @@ CHROMA_DATA_PATH = f"{DATA_DIR}/vector_db"
...
@@ -422,7 +422,10 @@ CHROMA_DATA_PATH = f"{DATA_DIR}/vector_db"
RAG_TOP_K
=
int
(
os
.
environ
.
get
(
"RAG_TOP_K"
,
"5"
))
RAG_TOP_K
=
int
(
os
.
environ
.
get
(
"RAG_TOP_K"
,
"5"
))
RAG_RELEVANCE_THRESHOLD
=
float
(
os
.
environ
.
get
(
"RAG_RELEVANCE_THRESHOLD"
,
"0.0"
))
RAG_RELEVANCE_THRESHOLD
=
float
(
os
.
environ
.
get
(
"RAG_RELEVANCE_THRESHOLD"
,
"0.0"
))
RAG_HYBRID
=
os
.
environ
.
get
(
"RAG_HYBRID"
,
""
).
lower
()
==
"true"
ENABLE_RAG_HYBRID_SEARCH
=
(
os
.
environ
.
get
(
"ENABLE_RAG_HYBRID_SEARCH"
,
""
).
lower
()
==
"true"
)
RAG_EMBEDDING_ENGINE
=
os
.
environ
.
get
(
"RAG_EMBEDDING_ENGINE"
,
""
)
RAG_EMBEDDING_ENGINE
=
os
.
environ
.
get
(
"RAG_EMBEDDING_ENGINE"
,
""
)
...
...
backend/main.py
View file @
cebf733b
...
@@ -121,7 +121,7 @@ class RAGMiddleware(BaseHTTPMiddleware):
...
@@ -121,7 +121,7 @@ class RAGMiddleware(BaseHTTPMiddleware):
rag_app
.
state
.
RAG_TEMPLATE
,
rag_app
.
state
.
RAG_TEMPLATE
,
rag_app
.
state
.
TOP_K
,
rag_app
.
state
.
TOP_K
,
rag_app
.
state
.
RELEVANCE_THRESHOLD
,
rag_app
.
state
.
RELEVANCE_THRESHOLD
,
rag_app
.
state
.
HYBRID
,
rag_app
.
state
.
ENABLE_RAG_HYBRID_SEARCH
,
rag_app
.
state
.
RAG_EMBEDDING_ENGINE
,
rag_app
.
state
.
RAG_EMBEDDING_ENGINE
,
rag_app
.
state
.
RAG_EMBEDDING_MODEL
,
rag_app
.
state
.
RAG_EMBEDDING_MODEL
,
rag_app
.
state
.
sentence_transformer_ef
,
rag_app
.
state
.
sentence_transformer_ef
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment