Skip to content

Commit

Permalink
The embedding model should be consistent for microservice retriever (o…
Browse files Browse the repository at this point in the history
…pea-project#69)

* embedding model should be consistent both for ingestion and redis retriever

Signed-off-by: zhlsunshine <[email protected]>

* fix the DOC.

Signed-off-by: zhlsunshine <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add comments for changes.

Signed-off-by: zhlsunshine <[email protected]>

* add comments for changes.

Signed-off-by: zhlsunshine <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add comments for changes.

Signed-off-by: zhlsunshine <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: zhlsunshine <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
zhlsunshine and pre-commit-ci[bot] authored May 20, 2024
1 parent 0b1ae40 commit 90bdbfc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions comps/retrievers/langchain/retriever_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from langchain_community.embeddings import HuggingFaceBgeEmbeddings
from langchain_community.embeddings import HuggingFaceBgeEmbeddings, HuggingFaceHubEmbeddings
from langchain_community.vectorstores import Redis
from redis_config import INDEX_NAME, INDEX_SCHEMA, REDIS_URL
from redis_config import EMBED_MODEL, INDEX_NAME, INDEX_SCHEMA, REDIS_URL

from comps import (
EmbedDoc768,
Expand All @@ -27,6 +28,8 @@
register_microservice,
)

tei_embedding_endpoint = os.getenv("TEI_EMBEDDING_ENDPOINT")


@register_microservice(
name="opea_service@retriever_redis",
Expand All @@ -37,7 +40,14 @@
)
@opea_telemetry
def retrieve(input: EmbedDoc768) -> SearchedDoc:
embeddings = HuggingFaceBgeEmbeddings(model_name="BAAI/bge-base-en-v1.5")
# Create vectorstore
if tei_embedding_endpoint:
# create embeddings using TEI endpoint service
embeddings = HuggingFaceHubEmbeddings(model=tei_embedding_endpoint)
else:
# create embeddings using local embedding model
embeddings = HuggingFaceBgeEmbeddings(model_name=EMBED_MODEL)

vector_db = Redis.from_existing_index(
embedding=embeddings,
index_name=INDEX_NAME,
Expand Down

0 comments on commit 90bdbfc

Please sign in to comment.