MCPcopy Create free account
hub / github.com/NanGePlus/LightRAGTest / hf_embedding

Function hf_embedding

LightRAG/lightrag/llm.py:698–709  ·  view source on GitHub ↗
(texts: list[str], tokenizer, embed_model)

Source from the content-addressed store, hash-verified

696
697
698async def hf_embedding(texts: list[str], tokenizer, embed_model) -> np.ndarray:
699 device = next(embed_model.parameters()).device
700 input_ids = tokenizer(
701 texts, return_tensors="pt", padding=True, truncation=True
702 ).input_ids.to(device)
703 with torch.no_grad():
704 outputs = embed_model(input_ids)
705 embeddings = outputs.last_hidden_state.mean(dim=1)
706 if embeddings.dtype == torch.bfloat16:
707 return embeddings.detach().to(torch.float32).cpu().numpy()
708 else:
709 return embeddings.detach().cpu().numpy()
710
711
712async def ollama_embedding(texts: list[str], embed_model, **kwargs) -> np.ndarray:

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected