from langchain_community.vectorstores.tencentvectordb import (
ConnectionParams,
MetaField,
TencentVectorDB,
)
from langchain_core.documents import Document
from tcvectordb.model.enum import FieldType
meta_fields = [
MetaField(name="year", data_type="uint64", index=True),
MetaField(name="rating", data_type="string", index=False),
MetaField(name="genre", data_type=FieldType.String, index=True),
MetaField(name="director", data_type=FieldType.String, index=True),
]
docs = [
Document(
page_content="The Shawshank Redemption is a 1994 American drama film written and directed by Frank Darabont.",
metadata={
"year": 1994,
"rating": "9.3",
"genre": "drama",
"director": "Frank Darabont",
},
),
Document(
page_content="The Godfather is a 1972 American crime film directed by Francis Ford Coppola.",
metadata={
"year": 1972,
"rating": "9.2",
"genre": "crime",
"director": "Francis Ford Coppola",
},
),
Document(
page_content="The Dark Knight is a 2008 superhero film directed by Christopher Nolan.",
metadata={
"year": 2008,
"rating": "9.0",
"genre": "science fiction",
"director": "Christopher Nolan",
},
),
Document(
page_content="Inception is a 2010 science fiction action film written and directed by Christopher Nolan.",
metadata={
"year": 2010,
"rating": "8.8",
"genre": "science fiction",
"director": "Christopher Nolan",
},
),
Document(
page_content="The Avengers is a 2012 American superhero film based on the Marvel Comics superhero team of the same name.",
metadata={
"year": 2012,
"rating": "8.0",
"genre": "science fiction",
"director": "Joss Whedon",
},
),
Document(
page_content="Black Panther is a 2018 American superhero film based on the Marvel Comics character of the same name.",
metadata={
"year": 2018,
"rating": "7.3",
"genre": "science fiction",
"director": "Ryan Coogler",
},
),
]
vector_db = TencentVectorDB.from_documents(
docs,
None,
connection_params=ConnectionParams(
url="http://10.0.X.X",
key="eC4bLRy2va******************************",
username="root",
timeout=20,
),
collection_name="self_query_movies",
meta_fields=meta_fields,
drop_old=True,
)