> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Ollama 嵌入器

## 代码

```python theme={null}
from agno.agent import AgentKnowledge
from agno.embedder.ollama import OllamaEmbedder
from agno.vectordb.pgvector import PgVector

embeddings = OllamaEmbedder().get_embedding(
    "这只敏捷的棕色狐狸越过了一只懒惰的狗。"
)

# Print the embeddings and their dimensions
print(f"Embeddings: {embeddings[:5]}")
print(f"Dimensions: {len(embeddings)}")

# Example usage:
knowledge_base = AgentKnowledge(
    vector_db=PgVector(
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
        table_name="ollama_embeddings",
        embedder=OllamaEmbedder(),
    ),
    num_documents=2,
)
```

## 用法

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="安装 Ollama">
    请遵循 [Ollama 官网](https://ollama.ai) 上的安装说明进行操作
  </Step>

  <Step title="安装库">
    ```bash theme={null}
    pip install -U sqlalchemy 'psycopg[binary]' pgvector agno
    ```
  </Step>

  <Step title="运行 PgVector">
    ```bash theme={null}
    docker run -d \
      -e POSTGRES_DB=ai \
      -e POSTGRES_USER=ai \
      -e POSTGRES_PASSWORD=ai \
      -e PGDATA=/var/lib/postgresql/data/pgdata \
      -v pgvolume:/var/lib/postgresql/data \
      -p 5532:5432 \
      --name pgvector \
      agnohq/pgvector:16
    ```
  </Step>

  <Step title="运行 Agent">
    <CodeGroup>
      ```bash Mac theme={null}
      python cookbook/agent_concepts/knowledge/embedders/ollama_embedder.py
      ```

      ```bash Windows theme={null}
      python cookbook/agent_concepts/knowledge/embedders/ollama_embedder.py
      ```
    </CodeGroup>
  </Step>
</Steps>
