Skip to content
Snippets Groups Projects
Unverified Commit df96159e authored by Huu Le's avatar Huu Le Committed by GitHub
Browse files

feat: Use Qdrant FastEmbed as local embedding provider (#162)

parent 32fb32ab
No related branches found
No related tags found
No related merge requests found
---
"create-llama": patch
---
Use Qdrant FastEmbed as local embedding provider
...@@ -46,5 +46,8 @@ e2e/cache ...@@ -46,5 +46,8 @@ e2e/cache
# intellij # intellij
**/.idea **/.idea
# Python
.mypy_cache/
# build artifacts # build artifacts
create-llama-*.tgz create-llama-*.tgz
...@@ -153,14 +153,24 @@ const getAdditionalDependencies = ( ...@@ -153,14 +153,24 @@ const getAdditionalDependencies = (
version: "0.2.6", version: "0.2.6",
}); });
break; break;
case "groq":
dependencies.push({
name: "llama-index-llms-groq",
version: "0.1.4",
});
dependencies.push({
name: "llama-index-embeddings-fastembed",
version: "^0.1.4",
});
break;
case "anthropic": case "anthropic":
dependencies.push({ dependencies.push({
name: "llama-index-llms-anthropic", name: "llama-index-llms-anthropic",
version: "0.1.10", version: "0.1.10",
}); });
dependencies.push({ dependencies.push({
name: "llama-index-embeddings-huggingface", name: "llama-index-embeddings-fastembed",
version: "0.2.0", version: "^0.1.4",
}); });
break; break;
case "gemini": case "gemini":
......
...@@ -98,8 +98,25 @@ def init_azure_openai(): ...@@ -98,8 +98,25 @@ def init_azure_openai():
Settings.embed_model = AzureOpenAIEmbedding(**embedding_config) Settings.embed_model = AzureOpenAIEmbedding(**embedding_config)
def init_fastembed():
"""
Use Qdrant Fastembed as the local embedding provider.
"""
from llama_index.embeddings.fastembed import FastEmbedEmbedding
embed_model_map: Dict[str, str] = {
# Small and multilingual
"all-MiniLM-L6-v2": "sentence-transformers/all-MiniLM-L6-v2",
# Large and multilingual
"paraphrase-multilingual-mpnet-base-v2": "sentence-transformers/paraphrase-multilingual-mpnet-base-v2", # noqa: E501
}
# This will download the model automatically if it is not already downloaded
Settings.embed_model = FastEmbedEmbedding(
model_name=embed_model_map[os.getenv("EMBEDDING_MODEL")]
)
def init_groq(): def init_groq():
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.llms.groq import Groq from llama_index.llms.groq import Groq
model_map: Dict[str, str] = { model_map: Dict[str, str] = {
...@@ -108,19 +125,13 @@ def init_groq(): ...@@ -108,19 +125,13 @@ def init_groq():
"mixtral-8x7b": "mixtral-8x7b-32768", "mixtral-8x7b": "mixtral-8x7b-32768",
} }
embed_model_map: Dict[str, str] = {
"all-MiniLM-L6-v2": "sentence-transformers/all-MiniLM-L6-v2",
"all-mpnet-base-v2": "sentence-transformers/all-mpnet-base-v2",
}
Settings.llm = Groq(model=model_map[os.getenv("MODEL")]) Settings.llm = Groq(model=model_map[os.getenv("MODEL")])
Settings.embed_model = HuggingFaceEmbedding( # Groq does not provide embeddings, so we use FastEmbed instead
model_name=embed_model_map[os.getenv("EMBEDDING_MODEL")] init_fastembed()
)
def init_anthropic(): def init_anthropic():
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.llms.anthropic import Anthropic from llama_index.llms.anthropic import Anthropic
model_map: Dict[str, str] = { model_map: Dict[str, str] = {
...@@ -131,15 +142,9 @@ def init_anthropic(): ...@@ -131,15 +142,9 @@ def init_anthropic():
"claude-instant-1.2": "claude-instant-1.2", "claude-instant-1.2": "claude-instant-1.2",
} }
embed_model_map: Dict[str, str] = {
"all-MiniLM-L6-v2": "sentence-transformers/all-MiniLM-L6-v2",
"all-mpnet-base-v2": "sentence-transformers/all-mpnet-base-v2",
}
Settings.llm = Anthropic(model=model_map[os.getenv("MODEL")]) Settings.llm = Anthropic(model=model_map[os.getenv("MODEL")])
Settings.embed_model = HuggingFaceEmbedding( # Anthropic does not provide embeddings, so we use FastEmbed instead
model_name=embed_model_map[os.getenv("EMBEDDING_MODEL")] init_fastembed()
)
def init_gemini(): def init_gemini():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment