New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v0.0.11 #116
Comments
This was referenced Aug 31, 2023
Merged
SimpleVectorIndex refactorThe internal structure should be like this: type data struct {
ID string `json:"id"`
Metadata types.Meta `json:"metadata"`
Embedding embedder.Embedding `json:"embedding"`
} |
This was referenced Sep 13, 2023
Merged
Merged
Redis integrationcreate index
insert vector with medatada
search with vector
Go string vector encodinga := []float32{0.1,0.2,0.3}
e := fmt.Sprintf("%q",a) |
import json
import time
import numpy as np
import pandas as pd
import redis
import requests
from redis.commands.search.field import (
NumericField,
TagField,
TextField,
VectorField,
)
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
from redis.commands.search.query import Query
# from sentence_transformers import SentenceTransformer
url = "https://raw.githubusercontent.com/bsbodden/redis_vss_getting_started/main/data/bikes.json"
response = requests.get(url)
bikes = response.json()
client = redis.Redis(host="localhost", port=6379, decode_responses=True)
res = client.ping()
# >>> True
client.flushall()
pipeline = client.pipeline()
for i, bike in enumerate(bikes, start=1):
redis_key = f"bikes:{i:03}"
pipeline.json().set(redis_key, "$", bike)
res = pipeline.execute()
# >>> [True, True, True, True, True, True, True, True, True, True, True]
res = client.json().get("bikes:001", "$.model")
# >>> ['Summit']
keys = sorted(client.keys("bikes:*"))
# >>> ['bikes:001', 'bikes:002', ..., 'bikes:011']
descriptions = client.json().mget(keys, "$.description")
descriptions = [item for sublist in descriptions for item in sublist]
# embedder = SentenceTransformer("msmarco-distilbert-base-v4")
# embeddings = embedder.encode(descriptions).astype(np.float32).tolist()
embeddings = np.random.rand(len(bikes), 4).astype(np.float32).tolist()
VECTOR_DIMENSION = len(embeddings[0])
# >>> 768
pipeline = client.pipeline()
for key, embedding in zip(keys, embeddings):
pipeline.json().set(key, "$.description_embeddings", embedding)
pipeline.execute()
# >>> [True, True, True, True, True, True, True, True, True, True, True]
res = client.json().get("bikes:0")
# >>>
# {
# "model": "Summit",
# "brand": "nHill",
# "price": 1200,
# "type": "Mountain Bike",
# "specs": {
# "material": "alloy",
# "weight": "11.3"
# },
# "description": "This budget mountain bike from nHill performs well..."
# "description_embeddings": [
# -0.538114607334137,
# -0.49465855956077576,
# -0.025176964700222015,
# ...
# ]
# }
schema = (
TextField("$.model", no_stem=True, as_name="model"),
TextField("$.brand", no_stem=True, as_name="brand"),
NumericField("$.price", as_name="price"),
TagField("$.type", as_name="type"),
TextField("$.description", as_name="description"),
VectorField(
"$.description_embeddings",
"FLAT",
{
"TYPE": "FLOAT32",
"DIM": VECTOR_DIMENSION,
"DISTANCE_METRIC": "COSINE",
},
as_name="vector",
),
)
definition = IndexDefinition(prefix=["bikes:"], index_type=IndexType.JSON)
res = client.ft("idx:bikes_vss").create_index(
fields=schema, definition=definition
)
# >>> 'OK'
query = (
Query('(*)=>[KNN 3 @vector $query_vector AS vector_score]')
.sort_by('vector_score')
.return_fields('vector_score', 'id', 'brand', 'model', 'description')
.dialect(2)
)
encoded_query = [0.1, 0.2, 0.3, 0.4]
docs = client.ft("idx:bikes_vss").search(query, {'query_vector': np.array(
encoded_query, dtype=np.float32).tobytes()}).docs
print(docs) |
MetricsHere are the typical ranges for the following mathematical functions:
Keep in mind that these are the general ranges for these mathematical functions, but their specific application and interpretation can vary depending on the context in which they are used. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
load()
insimpleVectorIndex
Chore Fix load() in SimpleVectorIndex #123The text was updated successfully, but these errors were encountered: