VectorStack AI | vstackai-law-1
This repository describes the steps of using the VectorStack AI's vstackai-law-1
model.
You can use the embedding model via our API or via private deployments in your private cloud.
Learn more about the model's features and performance in our blog post.
Usage via private deployment
If you are interested in running this model in your own private cloud/ own hardware, contact us to learn more.
Usage via API
The following code snippet shows the steps required to generate embeddings via the API. Install the SDK via:
pip install -U vectorstackai
Get your free API key on www.vectorstack.ai
import vectorstackai
import numpy as np
api_key = "{API_KEY}" # Get your API key from www.vectorstack.ai
client = vectorstackai.Client(api_key=api_key, timeout=30)
# Documents related to law domain (e.g., court cases, consumer contracts, etc.)
documents = [
"The defendant was charged with violation of contract terms in the lease agreement signed on January 1, 2022.",
"This contract stipulates that the consumer has 30 days to return the product in case of any manufacturing defects.",
"In the case of Smith v. Johnson, the court ruled that the plaintiff had the right to claim damages under section 12 of the Consumer Protection Act."
]
# Get embeddings for the legal documents
doc_embeddings = client.embed(texts=documents, model='vstackai-law-1', is_query=False) # EmbeddingsObject(num_embeddings=3, embedding_dims=1536)
doc_embeddings = doc_embeddings.embeddings # (3, 1536) numpy array
# Encode the query
query = "How many days does the consumer have to return the product?"
query_embedding = client.embed(
texts=[query],
model='vstackai-law-1',
is_query=True,
instruction='Represent the query for searching legal documents'
) # EmbeddingsObject(num_embeddings=1, embedding_dims=1536)
query_embedding = query_embedding.embeddings # (1, 1536) numpy array
# To check if the embeddings work, you can compute similarity between the query and documents
similarities = np.dot(doc_embeddings, query_embedding.T)
print(similarities)
# array([[0.355],
# [0.772],
# [0.433]])
- Downloads last month
- 99
Evaluation results
- main_score on MTEB AILACasedocs (default)test set self-reported45.881
- map_at_1 on MTEB AILACasedocs (default)test set self-reported15.626
- map_at_10 on MTEB AILACasedocs (default)test set self-reported35.655
- map_at_100 on MTEB AILACasedocs (default)test set self-reported39.715
- map_at_1000 on MTEB AILACasedocs (default)test set self-reported39.889
- map_at_20 on MTEB AILACasedocs (default)test set self-reported37.102
- map_at_3 on MTEB AILACasedocs (default)test set self-reported27.090
- map_at_5 on MTEB AILACasedocs (default)test set self-reported31.026
- mrr_at_1 on MTEB AILACasedocs (default)test set self-reported46.000
- mrr_at_10 on MTEB AILACasedocs (default)test set self-reported54.605