Skip to content

Commit

Permalink
Introducing Google Semantic Retriever and Attributed Question and Ans…
Browse files Browse the repository at this point in the history
…wering (AQA) (#48)
  • Loading branch information
pikalaw authored Mar 5, 2024
1 parent e1386a7 commit 3c6e23a
Show file tree
Hide file tree
Showing 10 changed files with 1,845 additions and 4 deletions.
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

0 comments on commit 3c6e23a

Please sign in to comment.