# LlamaIndex

Source: https://staging-docs.aiand.com/integrations/llamaindex/

LlamaIndex works against ai& through its `OpenAILike` LLM — same OpenAI wire protocol, custom base URL.

## Setup

```bash
pip install llama-index llama-index-llms-openai-like
```

```python
from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    model="openai/gpt-oss-120b",
    api_base="https://api.aiand.com/v1",
    api_key="sk-your-api-key",
    is_chat_model=True,
)

print(llm.complete("Hello").text)
```

## Indexing + querying documents

```python
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings

Settings.llm = llm
# Bring your own embeddings — ai& doesn't expose an embeddings endpoint:
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")

docs = SimpleDirectoryReader("./data").load_data()
index = VectorStoreIndex.from_documents(docs)
query_engine = index.as_query_engine()

print(query_engine.query("What is this corpus about?"))
```

## With tools (function agent)

```python
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.core.tools import FunctionTool

def get_weather(city: str) -> str:
    """Get current weather for a city."""
    return f"Sunny in {city}, 22°C"

agent = FunctionAgent(
    tools=[FunctionTool.from_defaults(fn=get_weather)],
    llm=llm,
)

print(await agent.run("What's the weather in Tokyo?"))
```

<Aside type="note">
  ai& doesn't currently expose an embeddings endpoint, so pair LlamaIndex with a local embeddings model (`HuggingFaceEmbedding`) or a separate embeddings provider.
</Aside>
