|
|
@ -12,9 +12,11 @@ This example demonstrates how to integrate Qdrant vector database with Swarms ag
|
|
|
|
## Installation
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
```bash
|
|
|
|
pip install qdrant-client fastembed swarms-memory
|
|
|
|
pip install qdrant-client fastembed swarms-memory litellm
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
> **Note**: The `litellm` package is required for using LiteLLM provider models like OpenAI, Azure, Cohere, etc.
|
|
|
|
|
|
|
|
|
|
|
|
## Tutorial Steps
|
|
|
|
## Tutorial Steps
|
|
|
|
|
|
|
|
|
|
|
|
1. First, install the latest version of Swarms:
|
|
|
|
1. First, install the latest version of Swarms:
|
|
|
@ -102,8 +104,12 @@ agent = Agent(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Query with RAG
|
|
|
|
# Query with RAG
|
|
|
|
response = agent.run("What is Qdrant and how does it relate to RAG?")
|
|
|
|
try:
|
|
|
|
print(response)
|
|
|
|
response = agent.run("What is Qdrant and how does it relate to RAG?")
|
|
|
|
|
|
|
|
print(response)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
print(f"Error during query: {e}")
|
|
|
|
|
|
|
|
# Handle error appropriately
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Advanced Setup with Batch Processing and Metadata
|
|
|
|
### Advanced Setup with Batch Processing and Metadata
|
|
|
@ -214,22 +220,37 @@ services:
|
|
|
|
```python
|
|
|
|
```python
|
|
|
|
from qdrant_client import QdrantClient, models
|
|
|
|
from qdrant_client import QdrantClient, models
|
|
|
|
from swarms_memory import QdrantDB
|
|
|
|
from swarms_memory import QdrantDB
|
|
|
|
|
|
|
|
import os
|
|
|
|
# Connect to Qdrant server
|
|
|
|
import logging
|
|
|
|
client = QdrantClient(
|
|
|
|
|
|
|
|
host="localhost",
|
|
|
|
# Setup logging for production monitoring
|
|
|
|
port=6333,
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
api_key="your-api-key" # Optional
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
# Production RAG configuration
|
|
|
|
# Connect to Qdrant server with proper error handling
|
|
|
|
rag_db = QdrantDB(
|
|
|
|
client = QdrantClient(
|
|
|
|
client=client,
|
|
|
|
host=os.getenv("QDRANT_HOST", "localhost"),
|
|
|
|
embedding_model="text-embedding-3-large", # Higher quality embeddings
|
|
|
|
port=int(os.getenv("QDRANT_PORT", "6333")),
|
|
|
|
collection_name="production_knowledge",
|
|
|
|
api_key=os.getenv("QDRANT_API_KEY"), # Use environment variable
|
|
|
|
distance=models.Distance.COSINE,
|
|
|
|
timeout=30 # 30 second timeout
|
|
|
|
n_results=10
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Production RAG configuration with enhanced settings
|
|
|
|
|
|
|
|
rag_db = QdrantDB(
|
|
|
|
|
|
|
|
client=client,
|
|
|
|
|
|
|
|
embedding_model="text-embedding-3-large", # Higher quality embeddings
|
|
|
|
|
|
|
|
collection_name="production_knowledge",
|
|
|
|
|
|
|
|
distance=models.Distance.COSINE,
|
|
|
|
|
|
|
|
n_results=10,
|
|
|
|
|
|
|
|
api_key=os.getenv("OPENAI_API_KEY") # Secure API key handling
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("Successfully initialized production RAG database")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
logger.error(f"Failed to initialize RAG database: {e}")
|
|
|
|
|
|
|
|
raise
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Configuration Options
|
|
|
|
## Configuration Options
|
|
|
|