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
984dbf13
"git@developer.sourcefind.cn:tsoc/superbenchmark.git" did not exist on "2664850abd1fae6c1f619aab63f8074a159dcae2"
Commit
984dbf13
authored
Apr 25, 2024
by
Timothy J. Baek
Browse files
revert: original rag pipeline
parent
7d88689f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
34 deletions
+51
-34
backend/apps/rag/utils.py
backend/apps/rag/utils.py
+51
-34
No files found.
backend/apps/rag/utils.py
View file @
984dbf13
...
...
@@ -18,6 +18,9 @@ from langchain.retrievers import (
EnsembleRetriever
,
)
from
sentence_transformers
import
CrossEncoder
from
typing
import
Optional
from
config
import
SRC_LOG_LEVELS
,
CHROMA_CLIENT
...
...
@@ -28,12 +31,14 @@ log.setLevel(SRC_LOG_LEVELS["RAG"])
def
query_embeddings_doc
(
collection_name
:
str
,
query
:
str
,
k
:
int
,
r
:
float
,
embeddings_function
,
reranking_function
,
k
:
int
,
reranking_function
:
Optional
[
CrossEncoder
]
=
None
,
r
:
Optional
[
float
]
=
None
,
):
try
:
if
reranking_function
:
# if you use docker use the model from the environment variable
collection
=
CHROMA_CLIENT
.
get_collection
(
name
=
collection_name
)
...
...
@@ -71,7 +76,19 @@ def query_embeddings_doc(
"documents"
:
[[
d
.
page_content
for
d
in
result
]],
"metadatas"
:
[[
d
.
metadata
for
d
in
result
]],
}
else
:
# if you use docker use the model from the environment variable
query_embeddings
=
embeddings_function
(
query
)
log
.
info
(
f
"query_embeddings_doc
{
query_embeddings
}
"
)
collection
=
CHROMA_CLIENT
.
get_collection
(
name
=
collection_name
)
result
=
collection
.
query
(
query_embeddings
=
[
query_embeddings
],
n_results
=
k
,
)
log
.
info
(
f
"query_embeddings_doc:result
{
result
}
"
)
return
result
except
Exception
as
e
:
raise
e
...
...
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