Merge pull request #116 from Dormiveglia-elf/hotfix/embedding-dim

[hotfix-#75][embedding] Fix the potential embedding problem
This commit is contained in:
zrguo
2024-10-24 11:57:17 +08:00
committed by GitHub

View File

@@ -34,6 +34,13 @@ async def embedding_func(texts: list[str]) -> np.ndarray:
)
async def get_embedding_dim():
test_text = ["This is a test sentence."]
embedding = await embedding_func(test_text)
embedding_dim = embedding.shape[1]
return embedding_dim
# function test
async def test_funcs():
result = await llm_model_func("How are you?")
@@ -43,14 +50,18 @@ async def test_funcs():
print("embedding_func: ", result)
asyncio.run(test_funcs())
# asyncio.run(test_funcs())
async def main():
try:
embedding_dimension = await get_embedding_dim()
print(f"Detected embedding dimension: {embedding_dimension}")
rag = LightRAG(
working_dir=WORKING_DIR,
llm_model_func=llm_model_func,
embedding_func=EmbeddingFunc(
embedding_dim=4096, max_token_size=8192, func=embedding_func
embedding_dim=embedding_dimension, max_token_size=8192, func=embedding_func
),
)
@@ -77,3 +88,8 @@ print(
print(
rag.query("What are the top themes in this story?", param=QueryParam(mode="hybrid"))
)
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
asyncio.run(main())