Skip to content
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

feat: add MySQLVectorStore initialization methods #52

Merged
merged 8 commits into from
Mar 26, 2024

Conversation

jackwotherspoon
Copy link
Contributor

@jackwotherspoon jackwotherspoon commented Mar 25, 2024

Adding MySQLVectorStore and all the different class methods to initialize it.

Example usage:

from langchain_google_cloud_sql_mysql import  MySQLEngine, MySQLVectorStore

# create connection pool engine
engine = MySQLEngine.from_instance("my-project-id", "us-central1", "my-instance", "my-database")

# initialize vector store table
engine.init_vectorstore_table(table_name="vector_store", vector_size=768)

# base constructor
vector_store = MySQLVectorStore(
    engine,
    embedding_service=embeddings_service,
    table_name="vector_store",
)

# create VectorStore from LangChain Documents
vector_store = MySQLVectorStore.from_documents(
    docs,
    embedding=embeddings_service,
    engine=engine,
    table_name="vector_store",
    ids=ids,
)

# create VectorStore from texts
vector_store = MySQLVectorStore.from_texts(
    texts,
    embedding=embeddings_service,
    engine=engine,
    table_name="vector_store",
    metadatas=metadatas,
    ids=ids,
)

@jackwotherspoon jackwotherspoon self-assigned this Mar 25, 2024
@product-auto-label product-auto-label bot added the api: cloudsql-mysql Issues related to the googleapis/langchain-google-cloud-sql-mysql-python API. label Mar 25, 2024
@jackwotherspoon
Copy link
Contributor Author

Need to swap test instance over to instance that has MySQL vector support enabled.

@jackwotherspoon jackwotherspoon marked this pull request as ready for review March 25, 2024 20:42
@jackwotherspoon jackwotherspoon requested a review from a team as a code owner March 25, 2024 20:42
ignore_metadata_columns: Optional[List[str]] = None,
id_column: str = "langchain_id",
metadata_json_column: Optional[str] = "langchain_metadata",
index_query_options: Optional[QueryOptions] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to name it "query_options" instead of index_query_options. In PG QueryOptions is a sub attribute of index, though in Mysql it will be separate. There will be something more than than the index itself such as whether to use KNN query or ANN query, which we call "search_type"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want to update to query_options?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is updated to query_options, this comment is pinned on out of date code

tests/integration/test_mysql_vectorstore.py Outdated Show resolved Hide resolved
tests/integration/test_mysql_vectorstore_from_methods.py Outdated Show resolved Hide resolved
tests/integration/test_mysql_vectorstore.py Outdated Show resolved Hide resolved
tests/integration/test_mysql_vectorstore.py Outdated Show resolved Hide resolved
ignore_metadata_columns: Optional[List[str]] = None,
id_column: str = "langchain_id",
metadata_json_column: Optional[str] = "langchain_metadata",
index_query_options: Optional[QueryOptions] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want to update to query_options?

@jackwotherspoon jackwotherspoon merged commit a1c9411 into main Mar 26, 2024
11 checks passed
@jackwotherspoon jackwotherspoon deleted the vectorstore-init branch March 26, 2024 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: cloudsql-mysql Issues related to the googleapis/langchain-google-cloud-sql-mysql-python API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants