Views
No views yet
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.pip install -U vectorstackai1import vectorstackai
2import numpy as np
3api_key = "{API_KEY}" # Get your API key from www.vectorstack.ai
4client = vectorstackai.Client(api_key=api_key, timeout=30)
5
6# Documents related to law domain (e.g., court cases, consumer contracts, etc.)
7documents = [
8 "The defendant was charged with violation of contract terms in the lease agreement signed on January 1, 2022.",
9 "This contract stipulates that the consumer has 30 days to return the product in case of any manufacturing defects.",
10 "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."
11]
12
13# Get embeddings for the legal documents
14doc_embeddings = client.embed(texts=documents, model='vstackai-law-1', is_query=False) # EmbeddingsObject(num_embeddings=3, embedding_dims=1536)
15doc_embeddings = doc_embeddings.embeddings # (3, 1536) numpy array
16
17# Encode the query
18query = "How many days does the consumer have to return the product?"
19query_embedding = client.embed(
20 texts=[query],
21 model='vstackai-law-1',
22 is_query=True,
23 instruction='Represent the query for searching legal documents'
24) # EmbeddingsObject(num_embeddings=1, embedding_dims=1536)
25query_embedding = query_embedding.embeddings # (1, 1536) numpy array
26
27# To check if the embeddings work, you can compute similarity between the query and documents
28similarities = np.dot(doc_embeddings, query_embedding.T)
29print(similarities)
30# array([[0.355],
31# [0.772],
32# [0.433]])