MCPcopy Create free account
hub / github.com/KnowledgeXLab/LeanRAG / embedding_init

Function embedding_init

build_graph.py:97–111  ·  view source on GitHub ↗
(entities:list[dict])

Source from the content-addressed store, hash-verified

95 final_embedding = [d.embedding for d in embedding.data]
96 return np.array(final_embedding)
97def embedding_init(entities:list[dict])-> list[dict]:
98 texts=[truncate_text(i['description']) for i in entities]
99 model_name = EMBEDDING_MODEL
100 client = OpenAI(
101 api_key=EMBEDDING_MODEL,
102 base_url=EMBEDDING_URL
103 )
104 embedding = client.embeddings.create(
105 input=texts,
106 model=model_name,
107 )
108 final_embedding = [d.embedding for d in embedding.data]
109 for i, entity in enumerate(entities):
110 entity['vector'] = np.array(final_embedding[i])
111 return entities
112tokenizer = tiktoken.get_encoding("cl100k_base")
113def truncate_text(text, max_tokens=4096):
114 tokens = tokenizer.encode(text)

Callers

nothing calls this directly

Calls 1

truncate_textFunction · 0.70

Tested by

no test coverage detected