File size: 630 Bytes
39b20cc
 
 
7dbc5ab
bce723f
7dbc5ab
 
1e0a666
39b20cc
bd5a873
bce723f
b45a383
39b20cc
f277cd1
39b20cc
b45a383
f277cd1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from llama_index.core import VectorStoreIndex, Document
from llama_index.core.settings import Settings
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
import os

CACHE_DIR = os.getenv("LLAMA_INDEX_CACHE_DIR", "/app/model_cache")
embed_model = HuggingFaceEmbedding(model_name="all-MiniLM-L6-v2", cache_folder=CACHE_DIR)

Settings.embed_model = embed_model
Settings.llm = None 

def get_index_from_text(document_text: str):
    """
    Builds an in-memory index from user input using local embeddings only. No LLM.
    """
    doc = Document(text=document_text)
    return VectorStoreIndex.from_documents([doc])