> For the complete documentation index, see [llms.txt](https://docs.envector.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.envector.io/1.4.x/sdk-user-guide/encrypted-index/access.md).

# Access

This guide explains how to access existing indexes on the enVector server, list all available indexes, and create client SDK objects to examine their contents and perform operations.

## Overall Usage

The process of accessing existing indexes involves these main steps:

1. **Connect to Server** - Initialize the SDK and connect to the enVector server
2. **List Available Indexes** - Retrieve a list of all indexes currently on the server
3. **Get Index Information** - Obtain detailed information about specific indexes
4. **Create Index Objects** - Instantiate Index objects for existing indexes to perform operations
5. **Examine Index Contents** - Access index data, metadata, and perform searches

## Detailed Usage Using Arguments

### 1. Connect to the Server

First, establish a connection to the enVector server:

```python
import pyenvector as ev

# Initialize connection to the server
HOST_ADDRESS = "your.hostname:50050"
ev.init(address=HOST_ADDRESS, key_path="./keys", key_id="your-key-id")

print("Connected to enVector server successfully")
```

### 2. List All Available Indexes

Retrieve a list of all indexes currently registered on the server:

```python
# Get list of all indexes
index_list = ev.get_index_list()

if index_list:
    print(f"Found {len(index_list)} indexes on the server:")
    for i, index_name in enumerate(index_list, 1):
        print(f"  {i}. {index_name}")
else:
    print("No indexes found on the server")
```

### 3. Get Detailed Index Information

For each index, you can retrieve detailed information:

```python
def get_index_details(index_name):
    """Get detailed information about a specific index"""
    try:
        index_info = ev.get_index_info(index_name)
        print(f"\nIndex: {index_name}")
        print(f"  Dimension: {index_info['dim']}")
        print(f"  Row Count: {index_info['row_count']}")
        print(f"  Search Type: {index_info['search_type']}")
        print(f"  Key ID: {index_info['key_id']}")
        print(f"  Index Encryption: {index_info['index_encryption']}")
        print(f"  Query Encryption: {index_info['query_encryption']}")
        print(f"  Created Time: {index_info['created_time']}")
        return index_info
    except Exception as e:
        print(f"Failed to get info for index '{index_name}': {e}")
        return None

# Get details for all indexes
for index_name in index_list:
    get_index_details(index_name)
```

Alternatively, you can simply print the returned value of the `get_index_info` API:

```python
print(ev.get_index_info(index_name))
```

### 4. Create Index Objects for Existing Indexes

Create Index objects to interact with existing indexes:

```python
from pyenvector.index import Index

try:
    # Create Index object for existing index
    index = Index(index_name)    
    print(f"\nSuccessfully created Index object for '{index_name}'")
except Exception as e:
    print(f"Failed to create Index object for '{index_name}': {e}")
```

### 5. Examine Index Contents

Once you have Index objects, you can examine their contents by simply printing the object:

```python
print(index)
```

You can also access the index configuration object to examine specific settings:

```python
# Get the index configuration object
config = index.index_config

# Access configuration properties
print(f"Index name: {config.index_name}")
print(f"Dimension: {config.dim}")
print(f"Key ID: {config.key_id}")
print(f"Index encryption: {config.index_encryption}")
print(f"Query encryption: {config.query_encryption}")
print(f"Index type: {config.index_type}")
print(f"Preset: {config.preset}")
```

### 6. Complete Working Example

Here's a complete script that demonstrates all the functionality described above:

```python
import pyenvector as ev
from pyenvector.index import Index

def main():
    # 1. Connect to server
    HOST_ADDRESS = "localhost:50050"
    ev.init(address=HOST_ADDRESS, key_path="./keys", key_id="test-key")
    print("Connected to enVector server")
    
    # 2. List all indexes
    index_list = ev.get_index_list()
    if not index_list:
        print("No indexes found on the server")
        return
    
    print(f"Found {len(index_list)} indexes: {index_list}")
    
    # 3. Access each index
    for index_name in index_list:
        print(f"\n{'='*50}")
        print(f"Accessing Index: {index_name}")
        print(f"{'='*50}")
        
        try:
            # Create Index object
            index = Index(index_name)
            
            # Get index information
            index_info = ev.get_index_info(index_name)
            print(f"Index Details:")
            for key, value in index_info.items():
                print(f"  {key}: {value}")
            
            # Examine contents
            print(f"\nIndex Object Properties:")
            print(f"  Dimension: {index.dim}")
            print(f"  Entities: {index.num_entities}")
            print(f"  Connected: {index.is_connected}")            
            
        except Exception as e:
            print(f"Error accessing index '{index_name}': {e}")
    
    print(f"\n{'='*50}")
    print("Index access completed")

if __name__ == "__main__":
    main()
```

### 7. Error Handling

Here's an example of comprehensive error handling:

```python
def safe_index_access(index_name):
    """Safely access an index with comprehensive error handling"""
    try:
        # Check if index exists
        index_list = ev.get_index_list()
        if index_name not in index_list:
            print(f"Index '{index_name}' not found on server")
            return None
        
        # Get index info
        index_info = ev.get_index_info(index_name)
        
        # Create Index object
        index = Index(index_name)
        
        return index, index_info
        
    except ValueError as e:
        if "Indexer not connected" in str(e):
            print("Server connection error. Please check your connection.")
        elif "Key ID not found" in str(e):
            print(f"Key not found for index '{index_name}'. Please register the key first.")
        else:
            print(f"Configuration error: {e}")
        return None, None
        
    except Exception as e:
        print(f"Unexpected error accessing index '{index_name}': {e}")
        return None, None
```

### 8. Best Practices

1. **Connection Management**: Always check connection status before performing operations
2. **Error Handling**: Implement comprehensive error handling for network and configuration issues
3. **Resource Cleanup**: Properly manage Index objects to avoid memory leaks

### 9. Troubleshooting

**Common Issues and Solutions:**

* **"Indexer not connected"**: Reinitialize the SDK with `ev.init()`
* **"Key ID not found"**: Register the key first using `ev.register_key()`
* **"Index not found"**: Verify the index name exists using `ev.get_index_list()`
* **Connection timeouts**: Check network connectivity and server status

This guide provides comprehensive coverage of accessing existing indexes on the enVector server, allowing you to examine their contents and perform operations using the client SDK.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.envector.io/1.4.x/sdk-user-guide/encrypted-index/access.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
