Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

weaviate-vector-db-ag-2637 #1995

Merged
merged 14 commits into from
Feb 5, 2025
10 changes: 10 additions & 0 deletions cookbook/agent_concepts/knowledge/vector_dbs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,13 @@ docker run -p 6333:6333 -p 6334:6334 -v $(pwd)/qdrant_storage:/qdrant/storage:z
```shell
python cookbook/vector_dbs/qdrant_db.py
```

### Weaviate

```shell
./cookbook/scripts/run_weviate.sh
```

```shell
python cookbook/vector_dbs/weaviate_db.py
```
52 changes: 52 additions & 0 deletions cookbook/agent_concepts/knowledge/vector_dbs/weaviate_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
This example demonstrates using Weaviate as a vector database for semantic search.

Installation:
pip install weaviate-client

You can use either Weaviate Cloud or a local instance.

Weaviate Cloud Setup:
1. Create account at https://console.weaviate.cloud/
2. Create a cluster and copy the "REST endpoint" and "Admin" API Key. Then set environment variables:
export WCD_URL="your-cluster-url"
export WCD_API_KEY="your-api-key"

Local Development Setup:
1. Install Docker from https://docs.docker.com/get-docker/
2. Run Weaviate locally:
docker run -d \
-p 8080:8080 \
-p 50051:50051 \
--name weaviate \
cr.weaviate.io/semitechnologies/weaviate:1.28.4
or use the script `cookbook/scripts/run_weviate.sh` to start a local instance.
3. Remember to set `local=True` on the Weaviate instantiation.
"""

from agno.agent import Agent
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.vectordb.search import SearchType
from agno.vectordb.weaviate import Distance, VectorIndex, Weaviate

vector_db = Weaviate(
collection="recipes",
search_type=SearchType.hybrid,
vector_index=VectorIndex.HNSW,
distance=Distance.COSINE,
local=True, # Set to False if using Weaviate Cloud and True if using local instance
)
# Create knowledge base
knowledge_base = PDFUrlKnowledgeBase(
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=vector_db,
)
knowledge_base.load(recreate=False) # Comment out after first run

# Create and use the agent
agent = Agent(
knowledge=knowledge_base,
search_knowledge=True,
show_tool_calls=True,
)
agent.print_response("How to make Thai curry?", markdown=True)
5 changes: 5 additions & 0 deletions cookbook/scripts/run_weviate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
docker run -d \
-p 8080:8080 \
-p 50051:50051 \
--name weaviate \
cr.weaviate.io/semitechnologies/weaviate:1.28.4
2 changes: 2 additions & 0 deletions libs/agno/agno/vectordb/weaviate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from agno.vectordb.weaviate.index import Distance, VectorIndex
from agno.vectordb.weaviate.weaviate import Weaviate
15 changes: 15 additions & 0 deletions libs/agno/agno/vectordb/weaviate/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from enum import Enum


class VectorIndex(Enum):
HNSW = "hnsw"
FLAT = "flat"
DYNAMIC = "dynamic"


class Distance(Enum):
COSINE = "cosine"
DOT = "dot"
L2_SQUARED = "l2-squared"
HAMMING = "hamming"
MANHATTAN = "manhattan"
Loading