llama_index_manager.cpython-310.pyc•8.37 kB
o
�|�g�* � @ s� d Z ddlZddlZddlZddlmZmZmZmZm Z m
Z
mZmZ ddl
Z
ddlmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZ ejejd � e�e�ZG d
d� d�ZdS )z�
LlamaIndex Manager Module
Manages the LlamaIndex integration for the persistent-code knowledge graph.
Provides utilities for semantic search, embedding generation, and knowledge graph operations.
� N)�Dict�List�Optional�Any�Tuple�Set�Union�Callable)�Document�KnowledgeGraphIndex�StorageContext)�SimpleDocumentStore)�SimpleIndexStore)�
BaseEmbedding)�HuggingFaceEmbedding)�levelc @ s� e Zd ZdZ d"dededefdd�Zdefd d
�Zdefdd�Z d
e
defdd�Zd
e
defdd�Zdedededefdd�Z
d#dededeeeeeef f fdd�Zdefdd�Zdefdd�Zdeeef fd d!�ZdS )$�LlamaIndexManagerz#Manager for LlamaIndex integration.N�project_name�project_dir�triple_extract_fnc C s0 || _ || _|| _|| _d| _d| _| �� dS )a% Initialize the LlamaIndex manager.
Args:
project_name: Name of the project
project_dir: Directory for project storage
config_instance: Configuration instance
triple_extract_fn: Function to extract triples from documents
N)r r �configr �kg_index�embed_model�_initialize_llama_index)�selfr r �config_instancer � r �^/Users/sparshdrolia/Sparsh personal/persistent-code-mcp/persistent_code/llama_index_manager.py�__init__ s
zLlamaIndexManager.__init__�returnc
C s� | j �� st�d� dS z4| j �� }t�d|� �� t|d�| _tjt � t
� d�}tg || j| jdd�| _
t�d| j� �� W dS tyc } zt�d t|�� �� d
| _
d
| _W Y d
}~dS d
}~ww )zInitialize LlamaIndex components.
Returns:
success: Whether initialization was successful
�3LlamaIndex integration is disabled in configurationF�Initializing embedding model: ��
model_name)�docstoreZindex_storeT��storage_contextr �kg_triple_extract_fn�include_embeddingsz3LlamaIndex Knowledge Graph initialized for project z!Failed to initialize LlamaIndex: N)r �is_llama_index_enabled�logger�info�get_embedding_modelr r r �
from_defaultsr
r r r r r � Exception�warning�str)r r# r&