Hi,
I keep getting this error when im trying to query a collection i have that was build with MUVERA.
The collection was created through a custom embedder, specifically "Metric-AI/ColQwen2.5-7b-multilingual-v1.0”
The error:
ERROR:main.vector_dabases.weaviate_manager:Error performing search: Query call with protocol GRPC search failed with message explorer: get class: concurrentTargetVectorSearch): explorer: get class: vector search: object vector search at index multimodalmultivqaonbd: shard multimodalmultivqaonbd_alRcqENs64jA: panic occurred: runtime error: index out of range [0] with length 0.
Processing query queries: 100%|██████████████████████████████| 10/10
Code itself:
import stamina
import logging
import json
from typing import List, Set, Optional, Any, Dict, Union
import weaviate
from weaviate.classes.config import Configure
from weaviate.classes.query import MetadataQuery
from weaviate.classes.config import Property, DataType
from .base_database import BaseVectorDatabase, DatabaseConfig, Document, SearchResult, SearchResults, VectorDatabaseFactory
class WeaviateManager(BaseVectorDatabase):
def _init_(self, config: DatabaseConfig):
super()._init_(config)
self.client = None
self.collection = None
self._connected = False
self.logger = logging.getLogger(_name_)
def _sanitize_collection_name(self, name: str) → str:
parts = name.replace('-', '\_').replace('.', '\_').split('\_')
sanitized = ''.join(part.capitalize() *for* part *in* parts *if* part.isalnum())
if sanitized and not sanitized[0].isupper():
sanitized = sanitized.capitalize()
return sanitized
async def connect(self) → bool:
try:
auth_config = weaviate.auth.AuthApiKey(*api_key*=config.api_key)
additional_config = weaviate.config.AdditionalConfig(
timeout=weaviate.config.Timeout(
init=120,
query=120,
insert=120
)
)
self.client = weaviate.connect_to_weaviate_cloud(
cluster_url=self.config.url if self.config.url.startswith(“http”) else f"https://{self.config.url}",
auth_credentials=auth_config,
additional_config=additional_config
)
if self.client.is_ready():
self._connected = True
self.logger.info(f"Successfully connected to Weaviate at {self.config.url}")
meta = self.client.get_meta()
version = meta.get('version', 'unknown')
self.logger.info(f"Weaviate server version: {version}")
return True
else:
self.logger.error(“Failed to connect to Weaviate”)
return False
except Exception as e:
self.logger.error(f"Error connecting to Weaviate: {str(e)}")
return False
async def disconnect(self) → bool:
try:
if self.client:
self.client.close()
self._connected = False
self.logger.info(“Disconnected from Weaviate”)
return True
except Exception as e:
self.logger.error(f"Error disconnecting from Weaviate: {str(e)}")
return False
async def initialize_collection(self) → bool:
try:
if not self._connected:
await self.connect()
collection_name = self.config.collection_name
sanitized_name = self.\_sanitize_collection_name(collection_name)
self.logger.info(f"Using sanitized collection name: ‘{sanitized_name}’ (from ‘{collection_name}’)")
if self.client.collections.exists(sanitized_name):
self.logger.warning(f"Collection ‘{sanitized_name}’ already exists")
self.collection = self.client.collections.get(sanitized_name)
return True
vector_config=\[
Configure.MultiVectors.self_provided(
name=“custom_multi_vector”,
encoding=Configure.VectorIndex.MultiVector.Encoding.muvera(),
),
\]
properties = \[
Property(name=“filename”, data_type=DataType.TEXT),
\]
self.collection = self.client.collections.create(
name=sanitized_name,
vector_config=vector_config,
properties=properties
)
self.logger.info(f"Successfully created collection ‘{sanitized_name}’")
return True
except Exception as e:
collection_name = getattr(self.config, 'collection_name', 'unknown')
sanitized_name = self.\_sanitize_collection_name(collection_name) *if* hasattr(self, '\_sanitize_collection_name') *else* 'unknown'
self.logger.error(f"Error creating collection ‘{sanitized_name}’ (from ‘{collection_name}’): {str(e)}")
return False
async def get_indexed_files(self) → Set[str]:
try:
if not self._connected:
await self.connect()
indexed_files = set()
sanitized_name = self.\_sanitize_collection_name(self.config.collection_name)
collection = self.client.collections.get(sanitized_name)
for obj in collection.iterator(include_vector=False):
filename = obj.properties.get("filename", "")
if filename:
indexed_files.add(filename)
return indexed_files
except Exception as e:
self.logger.error(f"Error retrieving indexed files: {str(e)}")
return set()
@stamina.retry(*on*=Exception, *attempts*=3)
async def index_document(
self,
embedding: Union[List[float], List[List[float]]],
metadata: Dict[str, Any]
) -> bool:
try:
if not self._connected:
await self.connect()
sanitized_name = self.\_sanitize_collection_name(self.config.collection_name)
collection = self.client.collections.get(sanitized_name)
properties = {
“filename”: metadata.get(“filename”, “”),
}
uuid_obj = collection.data.insert(
properties=properties,
vector={“custom_multi_vector”: embedding}
)
self.logger.debug(f"Successfully indexed document with UUID: {uuid_obj}")
return True
except Exception as e:
self.logger.error(f"Error indexing document: {str(e)}")
return False
async def search(
self,
query_embedding: Union[List[float], List[List[float]]],
limit: int = 5,
filter_conditions: Optional[Dict[str, Any]] = None
) -> SearchResults:
try:
if not self._connected:
await self.connect()
sanitized_name = self.\_sanitize_collection_name(self.config.collection_name)
collection = self.client.collections.get(sanitized_name)
response = collection.query.near_vector(
near_vector=query_embedding,
target_vector=“custom_multi_vector”,
limit=limit,
return_metadata=MetadataQuery(distance=True )
)
results = \[\]
for obj in response.objects:
full_metadata = obj.properties.copy()
result = SearchResult(
document_id=obj.properties.get(“filename”, “”),
score= 1 - obj.metadata.distance if obj.metadata else -1.0,
metadata=full_metadata
)
results.append(result)
return SearchResults(results=results)
except Exception as e:
self.logger.error(f"Error performing search: {str(e)}")
return SearchResults(results=)
def _del_(self):
if self.client:
try:
self.client.close()
except:
pass
VectorDatabaseFactory.register_database(“weaviate”, WeaviateManager)