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

Introducing Google Semantic Retriever and Attributed Question and Answering (AQA) #48

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion libs/genai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,33 @@ from langchain_google_genai import GoogleGenerativeAIEmbeddings

embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
embeddings.embed_query("hello, world!")
```
```

## Semantic Retrieval

Enables retrieval augmented generation (RAG) in your application.

```
# Create a new store for housing your documents.
corpus_store = GoogleVectorStore.create_corpus(display_name="My Corpus")

# Create a new document under the above corpus.
document_store = GoogleVectorStore.create_document(
corpus_id=corpus_store.corpus_id, display_name="My Document"
)

# Upload some texts to the document.
text_splitter = CharacterTextSplitter(chunk_size=500, chunk_overlap=0)
for file in DirectoryLoader(path="data/").load():
documents = text_splitter.split_documents([file])
document_store.add_documents(documents)

# Talk to your entire corpus with possibly many documents.
aqa = corpus_store.as_aqa()
answer = aqa.invoke("What is the meaning of life?")

# Read the response along with the attributed passages and answerability.
print(response.answer)
print(response.attributed_passages)
print(response.answerable_probability)
```
15 changes: 15 additions & 0 deletions libs/genai/langchain_google_genai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,27 @@
from langchain_google_genai._enums import HarmBlockThreshold, HarmCategory
from langchain_google_genai.chat_models import ChatGoogleGenerativeAI
from langchain_google_genai.embeddings import GoogleGenerativeAIEmbeddings
from langchain_google_genai.genai_aqa import (
AqaInput,
AqaOutput,
GenAIAqa,
)
from langchain_google_genai.google_vector_store import (
DoesNotExistsException,
GoogleVectorStore,
)
from langchain_google_genai.llms import GoogleGenerativeAI

__all__ = [
"AqaInput",
"AqaOutput",
"ChatGoogleGenerativeAI",
"DoesNotExistsException",
"GenAIAqa",
"GoogleGenerativeAIEmbeddings",
"GoogleGenerativeAI",
"GoogleVectorStore",
"HarmBlockThreshold",
"HarmCategory",
"DoesNotExistsException",
]
Loading
Loading