Adding vectors into records

Very frustrated, mostly at myself because I am BRAND NEW to Weaviate and just don’t know what I’m doing.-

Weaviate Server Version: 1.31.7

  • Deployment Method: No Docker–full deployment on Ubuntu
    -Single Server running Weaviate
  • Client Language and Version: Python client v4.16.4

The issue is so simple and that is why I am so frustrated. I have a postgres table and one of the fields in it is pgvector, 4096 dimensions. This table has only 40 records in it. I am creating a collection in weaviate and simply trying to create 40 records with metadata and the embedding associated with it. Below is the code I’m using. The code runs, tells me 40 records were successfully added. When I check the records–everything is there EXCEPT the 4096 dimension embedding. The vectors are empty. I’ve looed at it 100 different ways and tried so many different things. I’ve talked to others about it. I just don’t get it. I don’t see what I’m doing wrong.

import os
import requests
import json
import ast
from dotenv import load_dotenv
import psycopg2

Load .env file

load_dotenv(‘/home/mintdude/Github/sparky/TestScripts/.env’)

Read all config from .env

POSTGRES_URL = os.getenv(“POSTGRES_URL”)
WEAVIATE_URL = os.getenv(“WEAVIATE_URL”)
WEAVIATE_PRIORITY_CLASS = os.getenv(“WEAVIATE_PRIORITY_CLASS”, “PriorityPrototype”)

Connect to Postgres

conn = psycopg2.connect(POSTGRES_URL)
cur = conn.cursor()

Fetch all records (assuming ‘embedding’ is a pgvector field)

cur.execute(“SELECT id, text, embedding FROM priority_prototypes”)
rows = cur.fetchall()

count = 0
for row in rows:
proto_id, text, embedding = row
# Convert pgvector to Python list if needed
if isinstance(embedding, memoryview):
embedding = list(embedding.tobytes()) # handle memoryview case (may need adjustment)
elif hasattr(embedding, ‘tolist’):
embedding = embedding.tolist()
elif isinstance(embedding, str):
try:
embedding = ast.literal_eval(embedding)
except Exception as e:
print(f"Failed to parse embedding for proto_id {proto_id}: {e}“)
continue
if not isinstance(embedding, list):
print(f"Skipping proto_id {proto_id}: embedding not a list!”)
continue

# Compose Weaviate REST API payload
payload = {
    "class": WEAVIATE_PRIORITY_CLASS,
    "properties": {
        "proto_id": str(proto_id),
        "text": text
    },
    "vector": embedding
}
resp = requests.post(WEAVIATE_URL, json=payload)
if resp.status_code not in (200, 201):
    print(f"Error uploading proto_id={proto_id}: {resp.status_code}, {resp.text}")
else:
    count += 1
    print(f"Uploaded proto_id={proto_id} OK")

cur.close()
conn.close()
print(f"\nUpload complete. {count} objects sent to Weaviate.")

Hey @mscottgithub

Welcome to the community — it’s really great to have you here! Wishing you a good start and an awesome learning journey ahead.

Let’s figure this out together, no stress at all.

I haven’t tested your code myself since I don’t have a Postgres DB handy, but here are the most common reasons I’ve seen when vectors don’t get stored properly in Weaviate:

1. Vectorizer Setting

When you create your collection, make sure the vectorizer is set to “self_provided”.

If you’re using the Python client v4, that would look like:

Configure.Vectors.self_provided()

If you use something like OpenAI or Cohere as the vectorizer, Weaviate will ignore your provided vectors and create its own.

2. Vector Format

Your vector should be a list of floats (like [0.1, 0.2, …]). It shouldn’t be a string, bytes, or a list of strings. Make sure your embedding ends up as a list of 4096 float values

3. API Endpoint

Double-check the URL you’re posting to. It should be:

http(s)://<host>:8080/v1/objects

If you’re just posting to the base WEAVIATE_URL, it won’t work.

Example:

object_url = f"{WEAVIATE_URL}/v1/objects"
resp = requests.post(object_url, json=payload)

Please use the client itself for ingest objects or batching as below:

Best,

Mohamed Shahin
Weaviate Support Engineer
(Ireland, UTC±00:00/+01:00)