fix file path bug still compatiable bug in hnsw search

This commit is contained in:
yichuan520030910320
2025-07-03 02:02:42 +00:00
parent 44815ee7fd
commit a627abe794
4 changed files with 5 additions and 5 deletions

View File

@@ -7,7 +7,7 @@ import asyncio
import os import os
import dotenv import dotenv
from leann.api import LeannBuilder, LeannSearcher, LeannChat from leann.api import LeannBuilder, LeannSearcher, LeannChat
import leann_backend_diskann # Import to ensure backend registration import leann_backend_hnsw # Import to ensure backend registration
import shutil import shutil
from pathlib import Path from pathlib import Path
@@ -50,7 +50,7 @@ if INDEX_DIR.exists():
print(f"\n[PHASE 1] Building Leann index...") print(f"\n[PHASE 1] Building Leann index...")
builder = LeannBuilder( builder = LeannBuilder(
backend_name="diskann", backend_name="hnsw",
embedding_model="facebook/contriever", # Using a common sentence transformer model embedding_model="facebook/contriever", # Using a common sentence transformer model
graph_degree=32, graph_degree=32,
complexity=64 complexity=64

View File

@@ -151,7 +151,7 @@ class HNSWBackend(LeannBackendFactoryInterface):
@staticmethod @staticmethod
def searcher(index_path: str, **kwargs) -> LeannBackendSearcherInterface: def searcher(index_path: str, **kwargs) -> LeannBackendSearcherInterface:
path = Path(index_path) path = Path(index_path)
meta_path = path.parent / f"{path.stem}.hnsw.meta.json" meta_path = path.parent / f"{path.name}.meta.json"
if not meta_path.exists(): if not meta_path.exists():
raise FileNotFoundError(f"Leann metadata file not found at {meta_path}. Cannot infer vector dimension for searcher.") raise FileNotFoundError(f"Leann metadata file not found at {meta_path}. Cannot infer vector dimension for searcher.")

View File

@@ -1,6 +1,6 @@
{ {
"version": "0.1.0", "version": "0.1.0",
"backend_name": "diskann", "backend_name": "hnsw",
"embedding_model": "facebook/contriever", "embedding_model": "facebook/contriever",
"num_chunks": 826, "num_chunks": 826,
"chunks": [ "chunks": [