1717 insert_chunk_vector_with_retry as _insert_chunk_vector_with_retry ,
1818 get_chunk_text as _get_chunk_text ,
1919)
20- from .openai import call_coding_api , EmbeddingClient
20+ from .openai import call_coding_api
21+ from .llama_embeddings import OpenAICompatibleEmbedding
22+ from .llama_chunker import chunk_with_llama_index
2123from llama_index .core import Document
2224from utils .logger import get_logger
23- from utils import compute_file_hash , chunk_text , norm , cosine
24- from .smart_chunker import smart_chunk
25+ from utils import compute_file_hash , norm , cosine
2526import logging
2627
2728# reduce noise from httpx used by external libs
6364
6465logger = get_logger (__name__ )
6566
66- # Initialize EmbeddingClient for structured logging and retry logic
67- _embedding_client = EmbeddingClient ()
67+ # Initialize llama-index embedding client
68+ _embedding_client = OpenAICompatibleEmbedding ()
6869
6970# Thread-local storage to track execution state inside futures
7071_thread_state = threading .local ()
@@ -85,7 +86,8 @@ def _get_embedding_with_semaphore(semaphore: threading.Semaphore, text: str, fil
8586 semaphore .acquire ()
8687 try :
8788 _thread_state .stage = "calling_embed_text"
88- result = _embedding_client .embed_text (text , file_path = file_path , chunk_index = chunk_index )
89+ # Use llama-index embedding client
90+ result = _embedding_client ._get_text_embedding (text )
8991 _thread_state .stage = "completed"
9092 return result
9193 except Exception as e :
@@ -170,14 +172,8 @@ def _process_file_sync(
170172 if isinstance (cfg , dict ):
171173 embedding_model = cfg .get ("embedding_model" )
172174
173- # Use smart chunking for supported code languages
174- use_smart_chunking = cfg .get ("smart_chunking" , True ) if isinstance (cfg , dict ) else True
175- supported_languages = ["python" , "javascript" , "typescript" , "java" , "go" , "rust" , "c" , "cpp" ]
176-
177- if use_smart_chunking and lang in supported_languages :
178- chunks = smart_chunk (content , language = lang , chunk_size = CHUNK_SIZE , overlap = CHUNK_OVERLAP )
179- else :
180- chunks = chunk_text (content , chunk_size = CHUNK_SIZE , overlap = CHUNK_OVERLAP )
175+ # Use llama-index chunking for all content
176+ chunks = chunk_with_llama_index (content , language = lang , chunk_size = CHUNK_SIZE , chunk_overlap = CHUNK_OVERLAP )
181177
182178 if not chunks :
183179 chunks = [content ]
@@ -439,19 +435,18 @@ def analyze_local_path_background(local_path: str, database_path: str, venv_path
439435
440436
441437
442- def search_semantic (query : str , database_path : str , top_k : int = 5 , include_content : bool = True ):
438+ def search_semantic (query : str , database_path : str , top_k : int = 5 ):
443439 """
444- Uses llama-index with sqlite-vector backend to retrieve best-matching chunks and returns
445- a list of {file_id, path, chunk_index, score, content (optional)} .
440+ Uses llama-index with sqlite-vector backend to retrieve best-matching chunks.
441+ Always includes content as it's needed for the coding model context .
446442
447443 Args:
448444 query: Search query text
449445 database_path: Path to the SQLite database
450446 top_k: Number of results to return
451- include_content: Whether to retrieve and include the actual chunk text
452447
453448 Returns:
454- List of dicts with file_id, path, chunk_index, score, and optionally content
449+ List of dicts with file_id, path, chunk_index, score, and content
455450 """
456451 try :
457452 # Use llama-index for semantic search
@@ -466,13 +461,9 @@ def search_semantic(query: str, database_path: str, top_k: int = 5, include_cont
466461 "file_id" : metadata .get ("file_id" , 0 ),
467462 "path" : metadata .get ("path" , "" ),
468463 "chunk_index" : metadata .get ("chunk_index" , 0 ),
469- "score" : metadata .get ("score" , 0.0 )
464+ "score" : metadata .get ("score" , 0.0 ),
465+ "content" : doc .text or "" # Always include content for LLM context
470466 }
471-
472- # Include content if requested
473- if include_content :
474- result ["content" ] = doc .text or ""
475-
476467 results .append (result )
477468
478469 logger .info (f"llama-index search returned { len (results )} results" )
0 commit comments