Skip to main content
Glama

create_index

Create a named local vector index for retrieval-augmented generation. Documents added are embedded via Ollama for local RAG without cloud dependencies.

Instructions

Create a named local vector index for RAG (Retrieval-Augmented Generation). Documents added to this index are embedded via Ollama.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
index_nameYes
embed_modelNonomic-embed-text

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The MCP tool 'create_index' is registered via @mcp.tool decorator. The handler function takes index_name and embed_model, then delegates to kn.create_index().
    @mcp.tool(
        name="create_index",
        description=(
            "Create a named local vector index for RAG (Retrieval-Augmented Generation). "
            "Documents added to this index are embedded via Ollama."
        ),
    )
    def create_index(
        index_name: str,
        embed_model: str = "nomic-embed-text",
    ) -> dict[str, Any]:
        """
        Args:
            index_name: Unique name for the index.
            embed_model: Ollama embedding model to use (must support /api/embeddings).
        """
        return kn.create_index(name=index_name, embed_model=embed_model)
  • Core implementation of create_index. Creates a new Index dataclass instance in the _indexes dict (or returns 'already_exists'), then persists to JSON store.
    def create_index(name: str, embed_model: str = DEFAULT_EMBED_MODEL) -> dict[str, Any]:
        if name in _indexes:
            return {"status": "already_exists", "name": name}
        _indexes[name] = Index(name=name, embed_model=embed_model)
        _save()
        return {"status": "created", "name": name, "embed_model": embed_model}
  • Dataclass schemas for Index (name, embed_model, documents) and Document (id, text, metadata, embedding) used by create_index and related knowledge operations.
    @dataclass
    class Document:
        id: str
        text: str
        metadata: dict[str, Any]
        embedding: list[float]
    
    
    @dataclass
    class Index:
        name: str
        embed_model: str
        documents: list[Document] = field(default_factory=list)
  • _save() helper: persists the in-memory _indexes dict to a JSON file, called by create_index after creating a new index.
    def _save() -> None:
        data = {}
        for idx_name, idx in _indexes.items():
            data[idx_name] = {
                "embed_model": idx.embed_model,
                "documents": [
                    {
                        "id": d.id,
                        "text": d.text,
                        "metadata": d.metadata,
                        "embedding": d.embedding,
                    }
                    for d in idx.documents
                ],
            }
        STORE_PATH.write_text(json.dumps(data))
  • _load() helper: loads persisted indexes from JSON file into _indexes dict on module import, ensuring create_index sees existing indexes.
    def _load() -> None:
        if not STORE_PATH.exists():
            return
        data = json.loads(STORE_PATH.read_text())
        for idx_name, idx_data in data.items():
            docs = [
                Document(
                    id=d["id"],
                    text=d["text"],
                    metadata=d["metadata"],
                    embedding=d["embedding"],
                )
                for d in idx_data["documents"]
            ]
            _indexes[idx_name] = Index(
                name=idx_name,
                embed_model=idx_data["embed_model"],
                documents=docs,
            )
    
    
    _load()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions embedding via Ollama but omits details like idempotency, whether it overwrites existing indices, or storage requirements. Key behavioral traits are missing.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two succinct sentences with front-loaded purpose. Every sentence adds value; no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple creation tool with an output schema, the description covers core functionality. However, it could mention prerequisites like requiring Ollama to be running.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description must compensate. It only hints at 'named' and 'embedded via Ollama' without explicitly mapping to parameters. The default embed_model value is not mentioned.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: creating a named local vector index for RAG, with documents embedded via Ollama. It uses a specific verb (create) and resource (vector index), and distinguishes from sibling tools like delete_index and list_indexes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for RAG setup but does not explicitly state when to use this tool versus alternatives like query_knowledge or add_document. No 'when not to use' guidance is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/deadSwank001/Nexus-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server