1 line
2.3 KiB
JSON
1 line
2.3 KiB
JSON
{"repo": "abhinav30219/synapticrag", "files": {"light_and_memorag/LightRAG-main/examples/lightrag_siliconcloud_demo.py": {"790992866784e67ef4453e8b2292f691b605ed16": {"t": 1785674137.8496287, "n": 1957, "h": "150a93c890032ebe", "c": "import os\nimport asyncio\nfrom lightrag import LightRAG, QueryParam\nfrom lightrag.llm import openai_complete_if_cache, siliconcloud_embedding\nfrom lightrag.utils import EmbeddingFunc\nimport numpy as np\n\nWORKING_DIR = \"./dickens\"\n\nif not os.path.exists(WORKING_DIR):\n os.mkdir(WORKING_DIR)\n\n\nasync def llm_model_func(\n prompt, system_prompt=None, history_messages=[], keyword_extraction=False, **kwargs\n) -> str:\n return await openai_complete_if_cache(\n \"Qwen/Qwen2.5-7B-Instruct\",\n prompt,\n system_prompt=system_prompt,\n history_messages=history_messages,\n api_key=os.getenv(\"SILICONFLOW_API_KEY\"),\n base_url=\"https://api.siliconflow.cn/v1/\",\n **kwargs,\n )\n\n\nasync def embedding_func(texts: list[str]) -> np.ndarray:\n return await siliconcloud_embedding(\n texts,\n model=\"netease-youdao/bce-embedding-base_v1\",\n api_key=os.getenv(\"SILICONFLOW_API_KEY\"),\n max_token_size=512,\n )\n\n\n# function test\nasync def test_funcs():\n result = await llm_model_func(\"How are you?\")\n print(\"llm_model_func: \", result)\n\n result = await embedding_func([\"How are you?\"])\n print(\"embedding_func: \", result)\n\n\nasyncio.run(test_funcs())\n\n\nrag = LightRAG(\n working_dir=WORKING_DIR,\n llm_model_func=llm_model_func,\n embedding_func=EmbeddingFunc(\n embedding_dim=768, max_token_size=512, func=embedding_func\n ),\n)\n\n\nwith open(\"./book.txt\") as f:\n rag.insert(f.read())\n\n# Perform naive search\nprint(\n rag.query(\"What are the top themes in this story?\", param=QueryParam(mode=\"naive\"))\n)\n\n# Perform local search\nprint(\n rag.query(\"What are the top themes in this story?\", param=QueryParam(mode=\"local\"))\n)\n\n# Perform global search\nprint(\n rag.query(\"What are the top themes in this story?\", param=QueryParam(mode=\"global\"))\n)\n\n# Perform hybrid search\nprint(\n rag.query(\"What are the top themes in this story?\", param=QueryParam(mode=\"hybrid\"))\n)\n"}}}} |